mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-16 17:22:55 +00:00
Wrap test_equal_ArrayHandles into a precompiled library
The previous implementation of test_equal_ArrayHandles was several templates that had to be resolved by any test that used them, which could be costly for unknown array types. Simplify this a bit by moving the implementation of testing unknown arrays into a library. Another advantage of the new implementation is that is handles more cases. Thus, you should not need to `ResetTypes` on the unknown/ uncertain arrays.
This commit is contained in:
parent
5610d674d8
commit
932c8e5ec0
@ -68,7 +68,7 @@ function(vtkm_create_test_executable
|
||||
set_property(TARGET ${prog} PROPERTY LIBRARY_OUTPUT_DIRECTORY ${VTKm_LIBRARY_OUTPUT_PATH})
|
||||
set_property(TARGET ${prog} PROPERTY RUNTIME_OUTPUT_DIRECTORY ${VTKm_EXECUTABLE_OUTPUT_PATH})
|
||||
|
||||
target_link_libraries(${prog} PRIVATE vtkm_cont ${libraries})
|
||||
target_link_libraries(${prog} PRIVATE vtkm_cont_testing ${libraries})
|
||||
|
||||
if(use_job_pool)
|
||||
vtkm_setup_job_pool()
|
||||
|
@ -114,6 +114,42 @@ VTKM_CONT UnknownArrayHandle UnknownArrayHandle::NewInstanceBasic() const
|
||||
return newArray;
|
||||
}
|
||||
|
||||
VTKM_CONT std::string UnknownArrayHandle::GetValueTypeName() const
|
||||
{
|
||||
if (this->Container)
|
||||
{
|
||||
return vtkm::cont::TypeToString(this->Container->ValueType);
|
||||
}
|
||||
else
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
VTKM_CONT std::string UnknownArrayHandle::GetBaseComponentTypeName() const
|
||||
{
|
||||
if (this->Container)
|
||||
{
|
||||
return vtkm::cont::TypeToString(this->Container->BaseComponentType);
|
||||
}
|
||||
else
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
VTKM_CONT std::string UnknownArrayHandle::GetStorageTypeName() const
|
||||
{
|
||||
if (this->Container)
|
||||
{
|
||||
return vtkm::cont::TypeToString(this->Container->StorageType);
|
||||
}
|
||||
else
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
VTKM_CONT vtkm::Id UnknownArrayHandle::GetNumberOfValues() const
|
||||
{
|
||||
if (this->Container)
|
||||
|
@ -343,6 +343,21 @@ public:
|
||||
///
|
||||
VTKM_CONT UnknownArrayHandle NewInstanceBasic() const;
|
||||
|
||||
/// \brief Returns the name of the value type stored in the array.
|
||||
///
|
||||
/// Returns an empty string if no array is stored.
|
||||
VTKM_CONT std::string GetValueTypeName() const;
|
||||
|
||||
/// \brief Returns the name of the base component of the value type stored in the array.
|
||||
///
|
||||
/// Returns an empty string if no array is stored.
|
||||
VTKM_CONT std::string GetBaseComponentTypeName() const;
|
||||
|
||||
/// \brief Returns the name of the storage tag for the array.
|
||||
///
|
||||
/// Returns an empty string if no array is stored.
|
||||
VTKM_CONT std::string GetStorageTypeName() const;
|
||||
|
||||
/// Returns true if this array matches the ValueType template argument.
|
||||
///
|
||||
template <typename ValueType>
|
||||
|
@ -29,8 +29,6 @@ set(headers
|
||||
TestingVirtualObjectHandle.h
|
||||
)
|
||||
|
||||
vtkm_declare_headers(${headers})
|
||||
|
||||
set(unit_tests
|
||||
UnitTestAlgorithm.cxx
|
||||
UnitTestArrayCopy.cxx
|
||||
@ -91,6 +89,22 @@ set(unit_tests
|
||||
UnitTestVariantArrayHandle.cxx
|
||||
)
|
||||
|
||||
set(library_sources
|
||||
TestEqualArrayHandles.cxx
|
||||
)
|
||||
|
||||
set(library_sources_device
|
||||
TestEqualArrayHandles.cxx # Really doesn't need device, but currently includes device headers
|
||||
)
|
||||
|
||||
vtkm_library(
|
||||
NAME vtkm_cont_testing
|
||||
SOURCES ${library_sources}
|
||||
DEVICE_SOURCES ${library_sources_device}
|
||||
HEADERS ${headers}
|
||||
)
|
||||
target_link_libraries(vtkm_cont_testing PUBLIC vtkm_cont)
|
||||
|
||||
vtkm_unit_tests(SOURCES ${unit_tests} DEFINES VTKM_NO_ERROR_ON_MIXED_CUDA_CXX_TAG)
|
||||
|
||||
# add distributed tests i.e. test to run with MPI
|
||||
|
92
vtkm/cont/testing/TestEqualArrayHandles.cxx
Normal file
92
vtkm/cont/testing/TestEqualArrayHandles.cxx
Normal file
@ -0,0 +1,92 @@
|
||||
//============================================================================
|
||||
// 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.
|
||||
//============================================================================
|
||||
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
struct TestEqualArrayHandleType2
|
||||
{
|
||||
template <typename T, typename FirstArrayType>
|
||||
void operator()(T,
|
||||
const FirstArrayType& array1,
|
||||
const vtkm::cont::UnknownArrayHandle& array2,
|
||||
vtkm::IdComponent cIndex,
|
||||
TestEqualResult& result,
|
||||
bool& called) const
|
||||
{
|
||||
if (!array2.IsBaseComponentType<T>())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
result = test_equal_ArrayHandles(array1, array2.ExtractComponent<T>(cIndex));
|
||||
|
||||
called = true;
|
||||
}
|
||||
};
|
||||
|
||||
struct TestEqualArrayHandleType1
|
||||
{
|
||||
template <typename T>
|
||||
void operator()(T,
|
||||
const vtkm::cont::UnknownArrayHandle& array1,
|
||||
const vtkm::cont::UnknownArrayHandle& array2,
|
||||
TestEqualResult& result,
|
||||
bool& called) const
|
||||
{
|
||||
if (!array1.IsBaseComponentType<T>())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (vtkm::IdComponent cIndex = 0; cIndex < array1.GetNumberOfComponentsFlat(); ++cIndex)
|
||||
{
|
||||
vtkm::ListForEach(TestEqualArrayHandleType2{},
|
||||
vtkm::TypeListScalarAll{},
|
||||
array1.ExtractComponent<T>(cIndex),
|
||||
array2,
|
||||
cIndex,
|
||||
result,
|
||||
called);
|
||||
if (!result)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
TestEqualResult test_equal_ArrayHandles(const vtkm::cont::UnknownArrayHandle& array1,
|
||||
const vtkm::cont::UnknownArrayHandle& array2)
|
||||
{
|
||||
TestEqualResult result;
|
||||
|
||||
if (array1.GetNumberOfComponentsFlat() != array2.GetNumberOfComponentsFlat())
|
||||
{
|
||||
result.PushMessage("Arrays have different numbers of components.");
|
||||
return result;
|
||||
}
|
||||
|
||||
bool called = false;
|
||||
|
||||
vtkm::ListForEach(
|
||||
TestEqualArrayHandleType1{}, vtkm::TypeListScalarAll{}, array1, array2, result, called);
|
||||
|
||||
if (!called)
|
||||
{
|
||||
result.PushMessage("Could not base component type for " + array1.GetBaseComponentTypeName() +
|
||||
" or " + array2.GetBaseComponentTypeName());
|
||||
}
|
||||
return result;
|
||||
}
|
@ -25,6 +25,8 @@
|
||||
#include <vtkm/cont/UnknownArrayHandle.h>
|
||||
#include <vtkm/cont/VariantArrayHandle.h>
|
||||
|
||||
#include <vtkm/cont/testing/vtkm_cont_testing_export.h>
|
||||
|
||||
#include <vtkm/thirdparty/diy/diy.h>
|
||||
|
||||
namespace opt = vtkm::cont::internal::option;
|
||||
@ -341,110 +343,37 @@ private:
|
||||
} // namespace vtkm::cont::testing
|
||||
|
||||
//============================================================================
|
||||
namespace detail
|
||||
{
|
||||
|
||||
struct TestEqualArrayHandle
|
||||
{
|
||||
template <typename T1, typename T2, typename StorageTag1, typename StorageTag2>
|
||||
VTKM_CONT void operator()(const vtkm::cont::ArrayHandle<T1, StorageTag1>&,
|
||||
const vtkm::cont::ArrayHandle<T2, StorageTag2>&,
|
||||
TestEqualResult& result) const
|
||||
VTKM_CONT TestEqualResult
|
||||
test_equal_ArrayHandles(const vtkm::cont::ArrayHandle<T1, StorageTag1>& array1,
|
||||
const vtkm::cont::ArrayHandle<T2, StorageTag2>& array2)
|
||||
{
|
||||
result.PushMessage("types don't match");
|
||||
return;
|
||||
}
|
||||
TestEqualResult result;
|
||||
|
||||
template <typename T, typename StorageTag1, typename StorageTag2>
|
||||
VTKM_CONT void operator()(const vtkm::cont::ArrayHandle<T, StorageTag1>& array1,
|
||||
const vtkm::cont::ArrayHandle<T, StorageTag2>& array2,
|
||||
TestEqualResult& result) const
|
||||
{
|
||||
if (array1.GetNumberOfValues() != array2.GetNumberOfValues())
|
||||
{
|
||||
result.PushMessage("sizes don't match");
|
||||
return;
|
||||
result.PushMessage("Arrays have different sizes.");
|
||||
return result;
|
||||
}
|
||||
|
||||
auto portal1 = array1.ReadPortal();
|
||||
auto portal2 = array2.ReadPortal();
|
||||
for (vtkm::Id i = 0; i < portal1.GetNumberOfValues(); ++i)
|
||||
{
|
||||
if (!test_equal(portal1.Get(i), portal2.Get(i)))
|
||||
{
|
||||
result.PushMessage(std::string("values don't match at index ") + std::to_string(i));
|
||||
return;
|
||||
}
|
||||
result.PushMessage("Values don't match at index " + std::to_string(i));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T, typename StorageTag, typename TypeList>
|
||||
VTKM_CONT void operator()(const vtkm::cont::ArrayHandle<T, StorageTag>& array1,
|
||||
const vtkm::cont::VariantArrayHandleBase<TypeList>& array2,
|
||||
TestEqualResult& result) const
|
||||
{
|
||||
array2.CastAndCall(*this, array1, result);
|
||||
}
|
||||
|
||||
template <typename T, typename StorageTag, typename TypeList>
|
||||
VTKM_CONT void operator()(const vtkm::cont::VariantArrayHandleBase<TypeList>& array1,
|
||||
const vtkm::cont::ArrayHandle<T, StorageTag>& array2,
|
||||
TestEqualResult& result) const
|
||||
{
|
||||
array1.CastAndCall(*this, array2, result);
|
||||
}
|
||||
|
||||
template <typename TypeList1, typename TypeList2>
|
||||
VTKM_CONT void operator()(const vtkm::cont::VariantArrayHandleBase<TypeList1>& array1,
|
||||
const vtkm::cont::VariantArrayHandleBase<TypeList2>& array2,
|
||||
TestEqualResult& result) const
|
||||
{
|
||||
array2.CastAndCall(*this, array1, result);
|
||||
}
|
||||
|
||||
template <typename T, typename StorageTag>
|
||||
VTKM_CONT void operator()(const vtkm::cont::ArrayHandle<T, StorageTag>& array1,
|
||||
const vtkm::cont::UnknownArrayHandle& array2,
|
||||
TestEqualResult& result) const
|
||||
{
|
||||
array2.CastAndCallForTypes<vtkm::List<T>, vtkm::List<VTKM_DEFAULT_STORAGE_TAG, StorageTag>>(
|
||||
*this, array1, result);
|
||||
}
|
||||
|
||||
template <typename T, typename StorageTag>
|
||||
VTKM_CONT void operator()(const vtkm::cont::UnknownArrayHandle& array1,
|
||||
const vtkm::cont::ArrayHandle<T, StorageTag>& array2,
|
||||
TestEqualResult& result) const
|
||||
{
|
||||
array1.CastAndCallForTypes<vtkm::List<T>, vtkm::List<VTKM_DEFAULT_STORAGE_TAG, StorageTag>>(
|
||||
*this, array2, result);
|
||||
}
|
||||
|
||||
VTKM_CONT void operator()(const vtkm::cont::UnknownArrayHandle& array1,
|
||||
const vtkm::cont::UnknownArrayHandle& array2,
|
||||
TestEqualResult& result) const
|
||||
{
|
||||
array2.CastAndCallForTypes<vtkm::TypeListAll, VTKM_DEFAULT_STORAGE_LIST>(*this, array1, result);
|
||||
}
|
||||
|
||||
template <typename TypeList, typename StorageList>
|
||||
VTKM_CONT void operator()(const vtkm::cont::UncertainArrayHandle<TypeList, StorageList>& array1,
|
||||
const vtkm::cont::UncertainArrayHandle<TypeList, StorageList>& array2,
|
||||
TestEqualResult& result) const
|
||||
{
|
||||
array2.CastAndCall(*this, array1, result);
|
||||
}
|
||||
};
|
||||
} // detail
|
||||
|
||||
template <typename ArrayHandle1, typename ArrayHandle2>
|
||||
inline VTKM_CONT TestEqualResult test_equal_ArrayHandles(const ArrayHandle1& array1,
|
||||
const ArrayHandle2& array2)
|
||||
{
|
||||
TestEqualResult result;
|
||||
detail::TestEqualArrayHandle{}(array1, array2, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
VTKM_CONT_TESTING_EXPORT TestEqualResult
|
||||
test_equal_ArrayHandles(const vtkm::cont::UnknownArrayHandle& array1,
|
||||
const vtkm::cont::UnknownArrayHandle& array2);
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user