Commit 0b2823ba authored by Kenneth Moreland's avatar Kenneth Moreland
Browse files

Make UnitTestArrayHandleCartesianProduct faster

Reduce the number of conditions UnitTestArrayHandleCartesianProduct
tries so that it is faster. All the conditions are pretty similar, so it
should be OK to reduce some.
parent 427f3cf5
......@@ -35,15 +35,15 @@ typedef vtkm::cont::DeviceAdapterAlgorithm<VTKM_DEFAULT_DEVICE_ADAPTER_TAG> DFA;
template <typename T>
void ArrayHandleCPBasic(vtkm::cont::ArrayHandle<T> x,
vtkm::cont::ArrayHandle<T> y,
vtkm::cont::ArrayHandle<T> z)
vtkm::cont::ArrayHandle<T> y,
vtkm::cont::ArrayHandle<T> z)
{
vtkm::cont::ArrayHandleCartesianProduct<
vtkm::cont::ArrayHandle<T>,
vtkm::cont::ArrayHandle<T>,
vtkm::cont::ArrayHandle<T> > cpArray;
vtkm::cont::ArrayHandle<T>,
vtkm::cont::ArrayHandle<T>,
vtkm::cont::ArrayHandle<T> > cpArray;
vtkm::Id nx = x.GetNumberOfValues();
vtkm::Id ny = y.GetNumberOfValues();
vtkm::Id nz = z.GetNumberOfValues();
......@@ -53,21 +53,21 @@ void ArrayHandleCPBasic(vtkm::cont::ArrayHandle<T> x,
//Make sure we have the right number of values.
VTKM_TEST_ASSERT(cpArray.GetNumberOfValues() == (nx*ny*nz),
"Cartesian array constructor has wrong number of values");
"Cartesian array constructor has wrong number of values");
//Make sure the values are correct.
vtkm::Vec<T,3> val;
for (vtkm::Id i = 0; i < n; i++)
{
vtkm::Id idx0 = (i % (nx*ny)) % nx;
vtkm::Id idx1 = (i % (nx*ny)) / nx;
vtkm::Id idx2 = i / (nx*ny);
val = vtkm::Vec<T,3>(x.GetPortalConstControl().Get(idx0),
y.GetPortalConstControl().Get(idx1),
z.GetPortalConstControl().Get(idx2));
VTKM_TEST_ASSERT(test_equal(cpArray.GetPortalConstControl().Get(i), val),
"Wrong value in array");
vtkm::Id idx0 = (i % (nx*ny)) % nx;
vtkm::Id idx1 = (i % (nx*ny)) / nx;
vtkm::Id idx2 = i / (nx*ny);
val = vtkm::Vec<T,3>(x.GetPortalConstControl().Get(idx0),
y.GetPortalConstControl().Get(idx1),
z.GetPortalConstControl().Get(idx2));
VTKM_TEST_ASSERT(test_equal(cpArray.GetPortalConstControl().Get(i), val),
"Wrong value in array");
}
}
......@@ -76,28 +76,32 @@ void createArr(std::vector<T> &arr, std::size_t n)
{
arr.resize(n);
for (std::size_t i = 0; i < n; i++)
arr[i] = static_cast<T>(i);
arr[i] = static_cast<T>(i);
}
template <typename T>
void
RunTest()
{
std::size_t nX = 10, nY = 10, nZ = 10;
for (std::size_t i = 1; i < nX; i++)
for (std::size_t j = 1; j < nY; j++)
for (std::size_t k = 1; k < nZ; k++)
{
std::vector<T> X,Y,Z;
createArr(X, nX);
createArr(Y, nY);
createArr(Z, nZ);
ArrayHandleCPBasic(vtkm::cont::make_ArrayHandle(X),
vtkm::cont::make_ArrayHandle(Y),
vtkm::cont::make_ArrayHandle(Z));
}
std::size_t nX = 11, nY = 13, nZ = 11;
for (std::size_t i = 1; i < nX; i += 2)
{
for (std::size_t j = 1; j < nY; j += 4)
{
for (std::size_t k = 1; k < nZ; k += 5)
{
std::vector<T> X,Y,Z;
createArr(X, nX);
createArr(Y, nY);
createArr(Z, nZ);
ArrayHandleCPBasic(vtkm::cont::make_ArrayHandle(X),
vtkm::cont::make_ArrayHandle(Y),
vtkm::cont::make_ArrayHandle(Z));
}
}
}
}
void
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment