//============================================================================= // // Copyright (c) Kitware, Inc. // All rights reserved. // See LICENSE.txt for details. // // This software is distributed WITHOUT ANY WARRANTY; without even // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notice for more information. // // Copyright 2015 National Technology & Engineering Solutions of Sandia, LLC (NTESS). // Copyright 2015 UT-Battelle, LLC. // Copyright 2015 Los Alamos National Security. // // Under the terms of Contract DE-NA0003525 with NTESS, // the U.S. Government retains certain rights in this software. // Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National // Laboratory (LANL), the U.S. Government retains certain rights in // this software. // //============================================================================= #include #include #include #include #include #include namespace ArrayHandleCartesianProductNamespace { using DFA = vtkm::cont::DeviceAdapterAlgorithm; template void ArrayHandleCPBasic(vtkm::cont::ArrayHandle x, vtkm::cont::ArrayHandle y, vtkm::cont::ArrayHandle z) { vtkm::cont::ArrayHandleCartesianProduct, vtkm::cont::ArrayHandle, vtkm::cont::ArrayHandle> cpArray; vtkm::Id nx = x.GetNumberOfValues(); vtkm::Id ny = y.GetNumberOfValues(); vtkm::Id nz = z.GetNumberOfValues(); vtkm::Id n = nx * ny * nz; cpArray = vtkm::cont::make_ArrayHandleCartesianProduct(x, y, z); //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"); //Make sure the values are correct. vtkm::Vec 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(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"); } } template void createArr(std::vector& arr, std::size_t n) { arr.resize(n); for (std::size_t i = 0; i < n; i++) arr[i] = static_cast(i); } template void RunTest() { 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 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 TestArrayHandleCartesianProduct() { RunTest(); RunTest(); RunTest(); } } // namespace ArrayHandleCartesianProductNamespace int UnitTestArrayHandleCartesianProduct(int, char* []) { using namespace ArrayHandleCartesianProductNamespace; return vtkm::cont::testing::Testing::Run(TestArrayHandleCartesianProduct); }