mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-08 21:33:55 +00:00
Do not cast to ArrayHandleVirtual in VariantArrayHandle::CastAndCall
We are moving to deprecate `ArrayHandleVirtual`, so we are removing the feature where `VariantArrayHandle::CastAndCall` automatically casts to an `ArrayHandleVirtual` if possible. The big reason to make this change now (as opposed to later when `ArrayHandleVirtual` is deprecated) is to improve compile times. This prevents us from having to compile an extra code path using `ArrayHandleVirtual`.
This commit is contained in:
parent
f6b13df513
commit
a3f23a03b6
@ -1409,8 +1409,8 @@ VTKM_NEVER_EXPORT VTKM_CONT inline void printSummary_ArrayHandle(
|
||||
vtkm::Id sz = array.GetNumberOfValues();
|
||||
|
||||
out << "valueType=" << vtkm::cont::TypeToString<T>()
|
||||
<< " storageType=" << vtkm::cont::TypeToString<StorageT>() << sz << " values occupying "
|
||||
<< (static_cast<size_t>(sz) * sizeof(T)) << " bytes [";
|
||||
<< " storageType=" << vtkm::cont::TypeToString<StorageT>() << " " << sz
|
||||
<< " values occupying " << (static_cast<size_t>(sz) * sizeof(T)) << " bytes [";
|
||||
|
||||
PortalType portal = array.ReadPortal();
|
||||
if (full || sz <= 7)
|
||||
|
@ -69,19 +69,29 @@ public:
|
||||
const std::string& coordsNm = "coords");
|
||||
|
||||
template <typename T>
|
||||
VTKM_CONT static vtkm::cont::DataSet Create(
|
||||
const vtkm::cont::ArrayHandle<T>& xVals,
|
||||
const vtkm::cont::ArrayHandle<T>& yVals,
|
||||
const vtkm::cont::ArrayHandle<T>& zVals,
|
||||
const vtkm::cont::ArrayHandle<vtkm::UInt8>& shapes,
|
||||
const vtkm::cont::ArrayHandle<vtkm::IdComponent>& numIndices,
|
||||
const vtkm::cont::ArrayHandle<vtkm::Id>& connectivity,
|
||||
const std::string& coordsNm = "coords")
|
||||
VTKM_DEPRECATED(1.6,
|
||||
"Combine point coordinate arrays using most appropriate array (e.g. "
|
||||
"ArrayHandleCompositeVector, ArrayHandleSOA, ArrayHandleCartesianProduct")
|
||||
VTKM_CONT static vtkm::cont::DataSet
|
||||
Create(const vtkm::cont::ArrayHandle<T>& xVals,
|
||||
const vtkm::cont::ArrayHandle<T>& yVals,
|
||||
const vtkm::cont::ArrayHandle<T>& zVals,
|
||||
const vtkm::cont::ArrayHandle<vtkm::UInt8>& shapes,
|
||||
const vtkm::cont::ArrayHandle<vtkm::IdComponent>& numIndices,
|
||||
const vtkm::cont::ArrayHandle<vtkm::Id>& connectivity,
|
||||
const std::string& coordsNm = "coords")
|
||||
{
|
||||
VTKM_ASSERT(xVals.GetNumberOfValues() == yVals.GetNumberOfValues());
|
||||
VTKM_ASSERT(xVals.GetNumberOfValues() == zVals.GetNumberOfValues());
|
||||
|
||||
auto offsets = vtkm::cont::ConvertNumIndicesToOffsets(numIndices);
|
||||
|
||||
return DataSetBuilderExplicit::BuildDataSet(
|
||||
xVals, yVals, zVals, shapes, offsets, connectivity, coordsNm);
|
||||
vtkm::cont::make_ArrayHandleCompositeVector(xVals, yVals, zVals),
|
||||
shapes,
|
||||
offsets,
|
||||
connectivity,
|
||||
coordsNm);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
@ -123,15 +133,6 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
template <typename T>
|
||||
static vtkm::cont::DataSet BuildDataSet(const vtkm::cont::ArrayHandle<T>& X,
|
||||
const vtkm::cont::ArrayHandle<T>& Y,
|
||||
const vtkm::cont::ArrayHandle<T>& Z,
|
||||
const vtkm::cont::ArrayHandle<vtkm::UInt8>& shapes,
|
||||
const vtkm::cont::ArrayHandle<vtkm::Id>& offsets,
|
||||
const vtkm::cont::ArrayHandle<vtkm::Id>& connectivity,
|
||||
const std::string& coordsNm);
|
||||
|
||||
template <typename T>
|
||||
VTKM_CONT static vtkm::cont::DataSet BuildDataSet(
|
||||
const vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>>& coords,
|
||||
@ -161,9 +162,16 @@ inline VTKM_CONT vtkm::cont::DataSet DataSetBuilderExplicit::Create(
|
||||
{
|
||||
VTKM_ASSERT(xVals.size() == yVals.size() && yVals.size() == zVals.size() && xVals.size() > 0);
|
||||
|
||||
auto xArray = vtkm::cont::make_ArrayHandle(xVals, vtkm::CopyFlag::On);
|
||||
auto yArray = vtkm::cont::make_ArrayHandle(yVals, vtkm::CopyFlag::On);
|
||||
auto zArray = vtkm::cont::make_ArrayHandle(zVals, vtkm::CopyFlag::On);
|
||||
vtkm::cont::ArrayHandle<vtkm::Vec3f> coordsArray;
|
||||
coordsArray.Allocate(static_cast<vtkm::Id>(xVals.size()));
|
||||
auto coordsPortal = coordsArray.WritePortal();
|
||||
for (std::size_t index = 0; index < xVals.size(); ++index)
|
||||
{
|
||||
coordsPortal.Set(static_cast<vtkm::Id>(index),
|
||||
vtkm::make_Vec(static_cast<vtkm::FloatDefault>(xVals[index]),
|
||||
static_cast<vtkm::FloatDefault>(yVals[index]),
|
||||
static_cast<vtkm::FloatDefault>(zVals[index])));
|
||||
}
|
||||
|
||||
auto shapesArray = vtkm::cont::make_ArrayHandle(shapes, vtkm::CopyFlag::On);
|
||||
auto connArray = vtkm::cont::make_ArrayHandle(connectivity, vtkm::CopyFlag::On);
|
||||
@ -172,33 +180,7 @@ inline VTKM_CONT vtkm::cont::DataSet DataSetBuilderExplicit::Create(
|
||||
vtkm::cont::make_ArrayHandle(numIndices, vtkm::CopyFlag::Off));
|
||||
|
||||
return DataSetBuilderExplicit::BuildDataSet(
|
||||
xArray, yArray, zArray, shapesArray, offsetsArray, connArray, coordsNm);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline VTKM_CONT vtkm::cont::DataSet DataSetBuilderExplicit::BuildDataSet(
|
||||
const vtkm::cont::ArrayHandle<T>& X,
|
||||
const vtkm::cont::ArrayHandle<T>& Y,
|
||||
const vtkm::cont::ArrayHandle<T>& Z,
|
||||
const vtkm::cont::ArrayHandle<vtkm::UInt8>& shapes,
|
||||
const vtkm::cont::ArrayHandle<vtkm::Id>& offsets,
|
||||
const vtkm::cont::ArrayHandle<vtkm::Id>& connectivity,
|
||||
const std::string& coordsNm)
|
||||
{
|
||||
VTKM_ASSERT(X.GetNumberOfValues() == Y.GetNumberOfValues() &&
|
||||
Y.GetNumberOfValues() == Z.GetNumberOfValues() && X.GetNumberOfValues() > 0 &&
|
||||
shapes.GetNumberOfValues() + 1 == offsets.GetNumberOfValues());
|
||||
|
||||
vtkm::cont::DataSet dataSet;
|
||||
dataSet.AddCoordinateSystem(
|
||||
vtkm::cont::CoordinateSystem(coordsNm, make_ArrayHandleCompositeVector(X, Y, Z)));
|
||||
vtkm::Id nPts = X.GetNumberOfValues();
|
||||
vtkm::cont::CellSetExplicit<> cellSet;
|
||||
|
||||
cellSet.Fill(nPts, shapes, connectivity, offsets);
|
||||
dataSet.SetCellSet(cellSet);
|
||||
|
||||
return dataSet;
|
||||
coordsArray, shapesArray, offsetsArray, connArray, coordsNm);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
@ -202,7 +202,7 @@ public:
|
||||
|
||||
/// \brief Holds an array handle without having to specify template parameters.
|
||||
///
|
||||
/// \c VariantArrayHandle holds an \c ArrayHandle or \c ArrayHandleVirtual
|
||||
/// `VariantArrayHandle` holds an `ArrayHandle`
|
||||
/// object using runtime polymorphism to manage different value types and
|
||||
/// storage rather than compile-time templates. This adds a programming
|
||||
/// convenience that helps avoid a proliferation of templates. It also provides
|
||||
@ -210,24 +210,23 @@ public:
|
||||
/// will not be known until runtime.
|
||||
///
|
||||
/// To interface between the runtime polymorphism and the templated algorithms
|
||||
/// in VTK-m, \c VariantArrayHandle contains a method named \c CastAndCall that
|
||||
/// will determine the correct type from some known list of types. It returns
|
||||
/// an ArrayHandleVirtual which type erases the storage type by using polymorphism.
|
||||
/// in VTK-m, `VariantArrayHandle` contains a method named `CastAndCall` that
|
||||
/// will determine the correct type from some known list of types.
|
||||
/// This mechanism is used internally by VTK-m's worklet invocation
|
||||
/// mechanism to determine the type when running algorithms.
|
||||
///
|
||||
/// By default, \c VariantArrayHandle will assume that the value type in the
|
||||
/// array matches one of the types specified by \c VTKM_DEFAULT_TYPE_LIST
|
||||
/// This list can be changed by using the \c ResetTypes. It is
|
||||
/// By default, `VariantArrayHandle` will assume that the value type in the
|
||||
/// array matches one of the types specified by `VTKM_DEFAULT_TYPE_LIST`
|
||||
/// This list can be changed by using the `ResetTypes`. It is
|
||||
/// worthwhile to match these lists closely to the possible types that might be
|
||||
/// used. If a type is missing you will get a runtime error. If there are more
|
||||
/// types than necessary, then the template mechanism will create a lot of
|
||||
/// object code that is never used, and keep in mind that the number of
|
||||
/// combinations grows exponentially when using multiple \c VariantArrayHandle
|
||||
/// combinations grows exponentially when using multiple `VariantArrayHandle`
|
||||
/// objects.
|
||||
///
|
||||
/// The actual implementation of \c VariantArrayHandle is in a templated class
|
||||
/// named \c VariantArrayHandleBase, which is templated on the list of
|
||||
/// The actual implementation of `VariantArrayHandle` is in a templated class
|
||||
/// named `VariantArrayHandleBase`, which is templated on the list of
|
||||
/// component types.
|
||||
///
|
||||
template <typename TypeList>
|
||||
@ -301,16 +300,12 @@ public:
|
||||
/// `CastAndCall` attempts to cast the held array to a specific value type,
|
||||
/// then call the given functor with the cast array. The types
|
||||
/// tried in the cast are those in the lists defined by the TypeList.
|
||||
/// By default \c VariantArrayHandle set this to \c VTKM_DEFAULT_TYPE_LIST.
|
||||
/// By default `VariantArrayHandle` set this to `VTKM_DEFAULT_TYPE_LIST`.
|
||||
///
|
||||
/// In addition to the value type, an \c ArrayHandle also requires a storage tag.
|
||||
/// By default, \c CastAndCall attempts to cast the array using the storage tags
|
||||
/// listed in \c VTKM_DEFAULT_STORAGE_LIST. You can optionally give a custom
|
||||
/// list of storage tags as the second argument. If the storage of the underlying
|
||||
/// array does not match any of the storage tags given, then the array will
|
||||
/// be cast to an \c ArrayHandleVirtual, which can hold any array given the
|
||||
/// appropriate value type. To always use \c ArrayHandleVirtual, pass
|
||||
/// \c vtkm::ListEmpty as thefirst argument.
|
||||
/// In addition to the value type, an `ArrayHandle` also requires a storage tag.
|
||||
/// By default, `CastAndCall` attempts to cast the array using the storage tags
|
||||
/// listed in `VTKM_DEFAULT_STORAGE_LIST`. You can optionally give a custom
|
||||
/// list of storage tags as the second argument.
|
||||
///
|
||||
/// As previous stated, if a storage tag list is provided, it is given in the
|
||||
/// first argument. The functor to call with the cast array is given as the next
|
||||
@ -318,7 +313,7 @@ public:
|
||||
/// The remaning arguments, if any, are passed to the functor.
|
||||
///
|
||||
/// The functor will be called with the cast array as its first argument. Any
|
||||
/// remaining arguments are passed from the arguments to \c CastAndCall.
|
||||
/// remaining arguments are passed from the arguments to `CastAndCall`.
|
||||
///
|
||||
template <typename FunctorOrStorageList, typename... Args>
|
||||
VTKM_CONT void CastAndCall(FunctorOrStorageList&& functorOrStorageList, Args&&... args) const
|
||||
@ -423,35 +418,6 @@ struct VariantArrayHandleTry
|
||||
}
|
||||
};
|
||||
|
||||
struct VariantArrayHandleTryFallback
|
||||
{
|
||||
template <typename T, typename Functor, typename... Args>
|
||||
void operator()(T,
|
||||
Functor&& f,
|
||||
bool& called,
|
||||
const vtkm::cont::internal::VariantArrayHandleContainerBase& container,
|
||||
Args&&... args) const
|
||||
{
|
||||
if (!called && vtkm::cont::internal::variant::IsValueType<T>(&container))
|
||||
{
|
||||
called = true;
|
||||
const auto* derived =
|
||||
static_cast<const vtkm::cont::internal::VariantArrayHandleContainer<T>*>(&container);
|
||||
VTKM_LOG_CAST_SUCC(container, derived);
|
||||
|
||||
// If you get a compile error here, it means that you have called CastAndCall for a
|
||||
// vtkm::cont::VariantArrayHandle and the arguments of the functor do not match those
|
||||
// being passed. This is often because it is calling the functor with an ArrayHandle
|
||||
// type that was not expected. Either add overloads to the functor to accept all
|
||||
// possible array types or constrain the types tried for the CastAndCall. Note that
|
||||
// the functor will be called with an array of type vtkm::cont::ArrayHandle<T, S>.
|
||||
// Directly using a subclass of ArrayHandle (e.g. vtkm::cont::ArrayHandleConstant<T>)
|
||||
// might not work.
|
||||
f(derived->Array, std::forward<Args>(args)...);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct IsUndefinedStorage
|
||||
{
|
||||
@ -484,16 +450,6 @@ VTKM_CONT void VariantArrayHandleCommon::CastAndCall(Functor&& f, Args&&... args
|
||||
ref,
|
||||
std::forward<Args>(args)...);
|
||||
if (!called)
|
||||
{
|
||||
// try to fall back to using ArrayHandleVirtual
|
||||
vtkm::ListForEach(detail::VariantArrayHandleTryFallback{},
|
||||
TypeList{},
|
||||
std::forward<Functor>(f),
|
||||
called,
|
||||
ref,
|
||||
std::forward<Args>(args)...);
|
||||
}
|
||||
if (!called)
|
||||
{
|
||||
// throw an exception
|
||||
VTKM_LOG_CAST_FAIL(*this, TypeList);
|
||||
@ -660,14 +616,14 @@ struct VariantArrayHandleSerializeFunctor
|
||||
|
||||
struct VariantArrayHandleDeserializeFunctor
|
||||
{
|
||||
template <typename T, typename TypeList>
|
||||
void operator()(T,
|
||||
template <typename T, typename S, typename TypeList>
|
||||
void operator()(vtkm::List<T, S>,
|
||||
vtkm::cont::VariantArrayHandleBase<TypeList>& dh,
|
||||
const std::string& typeString,
|
||||
bool& success,
|
||||
BinaryBuffer& bb) const
|
||||
{
|
||||
using ArrayHandleType = vtkm::cont::ArrayHandleVirtual<T>;
|
||||
using ArrayHandleType = vtkm::cont::ArrayHandle<T, S>;
|
||||
|
||||
if (!success && (typeString == vtkm::cont::SerializableTypeString<ArrayHandleType>::Get()))
|
||||
{
|
||||
@ -690,7 +646,7 @@ private:
|
||||
public:
|
||||
static VTKM_CONT void save(BinaryBuffer& bb, const Type& obj)
|
||||
{
|
||||
obj.CastAndCall(vtkm::ListEmpty(), internal::VariantArrayHandleSerializeFunctor{}, bb);
|
||||
obj.CastAndCall(internal::VariantArrayHandleSerializeFunctor{}, bb);
|
||||
}
|
||||
|
||||
static VTKM_CONT void load(BinaryBuffer& bb, Type& obj)
|
||||
@ -699,8 +655,12 @@ public:
|
||||
vtkmdiy::load(bb, typeString);
|
||||
|
||||
bool success = false;
|
||||
vtkm::ListForEach(
|
||||
internal::VariantArrayHandleDeserializeFunctor{}, TypeList{}, obj, typeString, success, bb);
|
||||
vtkm::ListForEach(internal::VariantArrayHandleDeserializeFunctor{},
|
||||
vtkm::cont::detail::ListDynamicTypes<TypeList, VTKM_DEFAULT_STORAGE_LIST>{},
|
||||
obj,
|
||||
typeString,
|
||||
success,
|
||||
bb);
|
||||
|
||||
if (!success)
|
||||
{
|
||||
|
@ -43,7 +43,7 @@ VTKM_CONT_EXPORT void ThrowCastAndCallException(
|
||||
const std::type_info& type)
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "Could not find appropriate cast for array in CastAndCall1.\n"
|
||||
out << "Could not find appropriate cast for array in CastAndCall.\n"
|
||||
"Array: ";
|
||||
ref.PrintSummary(out);
|
||||
out << "TypeList: " << type.name() << "\n";
|
||||
|
@ -364,8 +364,10 @@ inline vtkm::cont::DataSet MakeTestDataSet::Make3DUniformDataSet3(const vtkm::Id
|
||||
dataSet.AddPointField("pointvar", pointvar);
|
||||
|
||||
vtkm::Id numCells = (dims[0] - 1) * (dims[1] - 1) * (dims[2] - 1);
|
||||
dataSet.AddCellField(
|
||||
"cellvar", vtkm::cont::make_ArrayHandleCounting(vtkm::Float64(0), vtkm::Float64(1), numCells));
|
||||
vtkm::cont::ArrayHandle<vtkm::Float64> cellvar;
|
||||
vtkm::cont::ArrayCopy(
|
||||
vtkm::cont::make_ArrayHandleCounting(vtkm::Float64(0), vtkm::Float64(1), numCells), cellvar);
|
||||
dataSet.AddCellField("cellvar", cellvar);
|
||||
|
||||
return dataSet;
|
||||
}
|
||||
|
@ -105,6 +105,9 @@ vtkm::cont::DataSet CreateDataSetArr(bool useSeparatedCoords,
|
||||
{
|
||||
std::vector<T> xvals(numPoints), yvals(numPoints), zvals(numPoints);
|
||||
std::vector<T> varP(numPoints), varC(numCells);
|
||||
std::vector<vtkm::UInt8> shapevals(numCells);
|
||||
std::vector<vtkm::IdComponent> indicesvals(numCells);
|
||||
std::vector<vtkm::Id> connvals(numConn);
|
||||
for (std::size_t i = 0; i < numPoints; i++, f++)
|
||||
{
|
||||
xvals[i] = coords[i * 3 + 0];
|
||||
@ -116,15 +119,18 @@ vtkm::cont::DataSet CreateDataSetArr(bool useSeparatedCoords,
|
||||
for (std::size_t i = 0; i < numCells; i++, f++)
|
||||
{
|
||||
varC[i] = static_cast<T>(f * 1.1f);
|
||||
shapevals[i] = shape[i];
|
||||
indicesvals[i] = indices[i];
|
||||
}
|
||||
vtkm::cont::ArrayHandle<T> X, Y, Z, P, C;
|
||||
DFA::Copy(vtkm::cont::make_ArrayHandle(xvals), X);
|
||||
DFA::Copy(vtkm::cont::make_ArrayHandle(yvals), Y);
|
||||
DFA::Copy(vtkm::cont::make_ArrayHandle(zvals), Z);
|
||||
for (std::size_t i = 0; i < numConn; i++)
|
||||
{
|
||||
connvals[i] = conn[i];
|
||||
}
|
||||
dataSet = dsb.Create(xvals, yvals, zvals, shapevals, indicesvals, connvals);
|
||||
|
||||
vtkm::cont::ArrayHandle<T> P, C;
|
||||
DFA::Copy(vtkm::cont::make_ArrayHandle(varP), P);
|
||||
DFA::Copy(vtkm::cont::make_ArrayHandle(varC), C);
|
||||
dataSet = dsb.Create(
|
||||
X, Y, Z, createAH(numCells, shape), createAH(numCells, indices), createAH(numConn, conn));
|
||||
dataSet.AddPointField("pointvar", P);
|
||||
dataSet.AddCellField("cellvar", C);
|
||||
return dataSet;
|
||||
@ -229,7 +235,6 @@ vtkm::cont::DataSet CreateDataSetVec(bool useSeparatedCoords,
|
||||
|
||||
void TestDataSetBuilderExplicit()
|
||||
{
|
||||
vtkm::cont::DataSetBuilderExplicit dsb;
|
||||
vtkm::cont::DataSet ds;
|
||||
vtkm::Bounds bounds;
|
||||
|
||||
|
@ -132,30 +132,6 @@ struct TestArrayHandleCast
|
||||
}
|
||||
};
|
||||
|
||||
struct TestArrayHandleCompositeVector
|
||||
{
|
||||
template <typename T>
|
||||
void operator()(T) const
|
||||
{
|
||||
auto array = vtkm::cont::make_ArrayHandleCompositeVector(RandomArrayHandle<T>::Make(ArraySize),
|
||||
RandomArrayHandle<T>::Make(ArraySize));
|
||||
RunTest(array);
|
||||
RunTest(MakeTestVariantArrayHandle(array));
|
||||
}
|
||||
};
|
||||
|
||||
struct TestArrayHandleConcatenate
|
||||
{
|
||||
template <typename T>
|
||||
void operator()(T) const
|
||||
{
|
||||
auto array = vtkm::cont::make_ArrayHandleConcatenate(RandomArrayHandle<T>::Make(ArraySize),
|
||||
RandomArrayHandle<T>::Make(ArraySize));
|
||||
RunTest(array);
|
||||
RunTest(MakeTestVariantArrayHandle(array));
|
||||
}
|
||||
};
|
||||
|
||||
struct TestArrayHandleConstant
|
||||
{
|
||||
template <typename T>
|
||||
@ -181,19 +157,6 @@ struct TestArrayHandleCounting
|
||||
}
|
||||
};
|
||||
|
||||
struct TestArrayHandleExtractComponent
|
||||
{
|
||||
template <typename T>
|
||||
void operator()(T) const
|
||||
{
|
||||
auto numComps = vtkm::VecTraits<T>::NUM_COMPONENTS;
|
||||
auto array = vtkm::cont::make_ArrayHandleExtractComponent(
|
||||
RandomArrayHandle<T>::Make(ArraySize), RandomValue<vtkm::IdComponent>::Make(0, numComps - 1));
|
||||
RunTest(array);
|
||||
RunTest(MakeTestVariantArrayHandle(array));
|
||||
}
|
||||
};
|
||||
|
||||
struct TestArrayHandleGroupVec
|
||||
{
|
||||
template <typename T>
|
||||
@ -253,37 +216,6 @@ struct TestArrayHandleGroupVecVariable
|
||||
}
|
||||
};
|
||||
|
||||
struct TestArrayHandleImplicit
|
||||
{
|
||||
template <typename T>
|
||||
struct ImplicitFunctor
|
||||
{
|
||||
ImplicitFunctor() = default;
|
||||
|
||||
explicit ImplicitFunctor(const T& factor)
|
||||
: Factor(factor)
|
||||
{
|
||||
}
|
||||
|
||||
VTKM_EXEC_CONT T operator()(vtkm::Id index) const
|
||||
{
|
||||
return static_cast<T>(this->Factor *
|
||||
static_cast<typename vtkm::VecTraits<T>::ComponentType>(index));
|
||||
}
|
||||
|
||||
T Factor;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
void operator()(T) const
|
||||
{
|
||||
ImplicitFunctor<T> functor(RandomValue<T>::Make(2, 9));
|
||||
auto array = vtkm::cont::make_ArrayHandleImplicit(functor, ArraySize);
|
||||
RunTest(array);
|
||||
RunTest(MakeTestVariantArrayHandle(array));
|
||||
}
|
||||
};
|
||||
|
||||
void TestArrayHandleIndex()
|
||||
{
|
||||
auto size = RandomValue<vtkm::Id>::Make(2, 10);
|
||||
@ -321,86 +253,6 @@ struct TestArrayHandleReverse
|
||||
}
|
||||
};
|
||||
|
||||
struct TestArrayHandleSwizzle
|
||||
{
|
||||
template <typename T>
|
||||
void operator()(T) const
|
||||
{
|
||||
static const vtkm::IdComponent2 map2s[6] = { { 0, 1 }, { 0, 2 }, { 1, 0 },
|
||||
{ 1, 2 }, { 2, 0 }, { 2, 1 } };
|
||||
static const vtkm::IdComponent3 map3s[6] = { { 0, 1, 2 }, { 0, 2, 1 }, { 1, 0, 2 },
|
||||
{ 1, 2, 0 }, { 2, 0, 1 }, { 2, 1, 0 } };
|
||||
|
||||
auto numOutComps = RandomValue<vtkm::IdComponent>::Make(2, 3);
|
||||
switch (numOutComps)
|
||||
{
|
||||
case 2:
|
||||
{
|
||||
auto array = make_ArrayHandleSwizzle(RandomArrayHandle<vtkm::Vec<T, 3>>::Make(ArraySize),
|
||||
map2s[RandomValue<int>::Make(0, 5)]);
|
||||
RunTest(array);
|
||||
RunTest(MakeTestVariantArrayHandle(array));
|
||||
break;
|
||||
}
|
||||
case 3:
|
||||
default:
|
||||
{
|
||||
auto array = make_ArrayHandleSwizzle(RandomArrayHandle<vtkm::Vec<T, 3>>::Make(ArraySize),
|
||||
map3s[RandomValue<int>::Make(0, 5)]);
|
||||
RunTest(array);
|
||||
RunTest(MakeTestVariantArrayHandle(array));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
struct TestArrayHandleTransform
|
||||
{
|
||||
struct TransformFunctor
|
||||
{
|
||||
template <typename T>
|
||||
VTKM_EXEC_CONT T operator()(const T& in) const
|
||||
{
|
||||
return static_cast<T>(in * T{ 2 });
|
||||
}
|
||||
};
|
||||
|
||||
struct InverseTransformFunctor
|
||||
{
|
||||
template <typename T>
|
||||
VTKM_EXEC_CONT T operator()(const T& in) const
|
||||
{
|
||||
return static_cast<T>(in / T{ 2 });
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
void TestType1() const
|
||||
{
|
||||
auto array = vtkm::cont::make_ArrayHandleTransform(RandomArrayHandle<T>::Make(ArraySize),
|
||||
TransformFunctor{});
|
||||
RunTest(array);
|
||||
RunTest(MakeTestVariantArrayHandle(array));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void TestType2() const
|
||||
{
|
||||
auto array = vtkm::cont::make_ArrayHandleTransform(
|
||||
RandomArrayHandle<T>::Make(ArraySize), TransformFunctor{}, InverseTransformFunctor{});
|
||||
RunTest(array);
|
||||
RunTest(MakeTestVariantArrayHandle(array));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void operator()(T) const
|
||||
{
|
||||
this->TestType1<T>();
|
||||
this->TestType2<T>();
|
||||
}
|
||||
};
|
||||
|
||||
vtkm::cont::ArrayHandleUniformPointCoordinates MakeRandomArrayHandleUniformPointCoordinates()
|
||||
{
|
||||
@ -417,48 +269,6 @@ void TestArrayHandleUniformPointCoordinates()
|
||||
RunTest(MakeTestVariantArrayHandle(array));
|
||||
}
|
||||
|
||||
VTKM_DEPRECATED_SUPPRESS_BEGIN
|
||||
void TestArrayHandleVirtualCoordinates()
|
||||
{
|
||||
int type = RandomValue<int>::Make(0, 2);
|
||||
|
||||
vtkm::cont::ArrayHandleVirtualCoordinates array;
|
||||
switch (type)
|
||||
{
|
||||
case 0:
|
||||
array =
|
||||
vtkm::cont::ArrayHandleVirtualCoordinates(MakeRandomArrayHandleUniformPointCoordinates());
|
||||
break;
|
||||
case 1:
|
||||
array =
|
||||
vtkm::cont::ArrayHandleVirtualCoordinates(vtkm::cont::make_ArrayHandleCartesianProduct(
|
||||
RandomArrayHandle<vtkm::FloatDefault>::Make(ArraySize),
|
||||
RandomArrayHandle<vtkm::FloatDefault>::Make(ArraySize),
|
||||
RandomArrayHandle<vtkm::FloatDefault>::Make(ArraySize)));
|
||||
break;
|
||||
default:
|
||||
array =
|
||||
vtkm::cont::ArrayHandleVirtualCoordinates(RandomArrayHandle<vtkm::Vec3f>::Make(ArraySize));
|
||||
break;
|
||||
}
|
||||
|
||||
RunTest(array);
|
||||
RunTest(MakeTestVariantArrayHandle(array));
|
||||
}
|
||||
VTKM_DEPRECATED_SUPPRESS_END
|
||||
|
||||
struct TestArrayHandleZip
|
||||
{
|
||||
template <typename T>
|
||||
void operator()(T) const
|
||||
{
|
||||
auto array = vtkm::cont::make_ArrayHandleZip(RandomArrayHandle<T>::Make(ArraySize),
|
||||
vtkm::cont::ArrayHandleIndex(ArraySize));
|
||||
RunTest(array);
|
||||
RunTest(MakeTestVariantArrayHandle(array));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void TestArrayHandleSerialization()
|
||||
@ -466,62 +276,81 @@ void TestArrayHandleSerialization()
|
||||
std::cout << "Testing ArrayHandleBasic\n";
|
||||
vtkm::testing::Testing::TryTypes(TestArrayHandleBasic(), TestTypesList());
|
||||
|
||||
std::cout << "Testing ArrayHandleSOA\n";
|
||||
vtkm::testing::Testing::TryTypes(TestArrayHandleSOA(), TestTypesList());
|
||||
if (vtkm::ListHas<VTKM_DEFAULT_STORAGE_LIST, vtkm::cont::StorageTagSOA>::value)
|
||||
{
|
||||
std::cout << "Testing ArrayHandleSOA\n";
|
||||
vtkm::testing::Testing::TryTypes(TestArrayHandleSOA(), TestTypesList());
|
||||
}
|
||||
|
||||
std::cout << "Testing ArrayHandleCartesianProduct\n";
|
||||
vtkm::testing::Testing::TryTypes(TestArrayHandleCartesianProduct(), TestTypesList());
|
||||
if (vtkm::ListHas<VTKM_DEFAULT_STORAGE_LIST,
|
||||
vtkm::cont::StorageTagCartesianProduct<vtkm::cont::StorageTagBasic,
|
||||
vtkm::cont::StorageTagBasic,
|
||||
vtkm::cont::StorageTagBasic>>::value)
|
||||
{
|
||||
std::cout << "Testing ArrayHandleCartesianProduct\n";
|
||||
vtkm::testing::Testing::TryTypes(TestArrayHandleCartesianProduct(), TestTypesList());
|
||||
}
|
||||
|
||||
std::cout << "Testing TestArrayHandleCast\n";
|
||||
vtkm::testing::Testing::TryTypes(TestArrayHandleCast(), TestTypesList());
|
||||
if (vtkm::ListHas<VTKM_DEFAULT_STORAGE_LIST,
|
||||
vtkm::cont::StorageTagCast<vtkm::Int8, vtkm::cont::StorageTagBasic>>::value)
|
||||
{
|
||||
std::cout << "Testing TestArrayHandleCast\n";
|
||||
vtkm::testing::Testing::TryTypes(TestArrayHandleCast(), TestTypesList());
|
||||
}
|
||||
|
||||
std::cout << "Testing ArrayHandleCompositeVector\n";
|
||||
vtkm::testing::Testing::TryTypes(TestArrayHandleCompositeVector(), TestTypesList());
|
||||
if (vtkm::ListHas<VTKM_DEFAULT_STORAGE_LIST, vtkm::cont::StorageTagConstant>::value)
|
||||
{
|
||||
std::cout << "Testing ArrayHandleConstant\n";
|
||||
vtkm::testing::Testing::TryTypes(TestArrayHandleConstant(), TestTypesList());
|
||||
}
|
||||
|
||||
std::cout << "Testing ArrayHandleConcatenate\n";
|
||||
vtkm::testing::Testing::TryTypes(TestArrayHandleConcatenate(), TestTypesList());
|
||||
if (vtkm::ListHas<VTKM_DEFAULT_STORAGE_LIST, vtkm::cont::StorageTagCounting>::value)
|
||||
{
|
||||
std::cout << "Testing ArrayHandleCounting\n";
|
||||
vtkm::testing::Testing::TryTypes(TestArrayHandleCounting(), TestTypesList());
|
||||
}
|
||||
|
||||
std::cout << "Testing ArrayHandleConstant\n";
|
||||
vtkm::testing::Testing::TryTypes(TestArrayHandleConstant(), TestTypesList());
|
||||
if (vtkm::ListHas<VTKM_DEFAULT_STORAGE_LIST,
|
||||
vtkm::cont::StorageTagGroupVec<vtkm::cont::StorageTagBasic, 3>>::value)
|
||||
{
|
||||
std::cout << "Testing ArrayHandleGroupVec\n";
|
||||
vtkm::testing::Testing::TryTypes(TestArrayHandleGroupVec(), TestTypesList());
|
||||
}
|
||||
|
||||
std::cout << "Testing ArrayHandleCounting\n";
|
||||
vtkm::testing::Testing::TryTypes(TestArrayHandleCounting(), TestTypesList());
|
||||
if (vtkm::ListHas<VTKM_DEFAULT_STORAGE_LIST,
|
||||
vtkm::cont::StorageTagGroupVecVariable<vtkm::cont::StorageTagBasic,
|
||||
vtkm::cont::StorageTagBasic>>::value)
|
||||
{
|
||||
std::cout << "Testing ArrayHandleGroupVecVariable\n";
|
||||
vtkm::testing::Testing::TryTypes(TestArrayHandleGroupVecVariable(), TestTypesList());
|
||||
}
|
||||
|
||||
std::cout << "Testing ArrayHandleExtractComponent\n";
|
||||
vtkm::testing::Testing::TryTypes(TestArrayHandleExtractComponent(), TestTypesList());
|
||||
if (vtkm::ListHas<VTKM_DEFAULT_STORAGE_LIST, vtkm::cont::StorageTagIndex>::value)
|
||||
{
|
||||
std::cout << "Testing ArrayHandleIndex\n";
|
||||
TestArrayHandleIndex();
|
||||
}
|
||||
|
||||
std::cout << "Testing ArrayHandleGroupVec\n";
|
||||
vtkm::testing::Testing::TryTypes(TestArrayHandleGroupVec(), TestTypesList());
|
||||
if (vtkm::ListHas<VTKM_DEFAULT_STORAGE_LIST,
|
||||
vtkm::cont::StorageTagPermutation<vtkm::cont::StorageTagBasic,
|
||||
vtkm::cont::StorageTagBasic>>::value)
|
||||
{
|
||||
std::cout << "Testing ArrayHandlePermutation\n";
|
||||
vtkm::testing::Testing::TryTypes(TestArrayHandlePermutation(), TestTypesList());
|
||||
}
|
||||
|
||||
std::cout << "Testing ArrayHandleGroupVecVariable\n";
|
||||
vtkm::testing::Testing::TryTypes(TestArrayHandleGroupVecVariable(), TestTypesList());
|
||||
if (vtkm::ListHas<VTKM_DEFAULT_STORAGE_LIST,
|
||||
vtkm::cont::StorageTagReverse<vtkm::cont::StorageTagBasic>>::value)
|
||||
{
|
||||
std::cout << "Testing ArrayHandleReverse\n";
|
||||
vtkm::testing::Testing::TryTypes(TestArrayHandleReverse(), TestTypesList());
|
||||
}
|
||||
|
||||
std::cout << "Testing ArrayHandleImplicit\n";
|
||||
vtkm::testing::Testing::TryTypes(TestArrayHandleImplicit(), TestTypesList());
|
||||
|
||||
std::cout << "Testing ArrayHandleIndex\n";
|
||||
TestArrayHandleIndex();
|
||||
|
||||
std::cout << "Testing ArrayHandlePermutation\n";
|
||||
vtkm::testing::Testing::TryTypes(TestArrayHandlePermutation(), TestTypesList());
|
||||
|
||||
std::cout << "Testing ArrayHandleReverse\n";
|
||||
vtkm::testing::Testing::TryTypes(TestArrayHandleReverse(), TestTypesList());
|
||||
|
||||
std::cout << "Testing ArrayHandleSwizzle\n";
|
||||
vtkm::testing::Testing::TryTypes(TestArrayHandleSwizzle(), TestTypesList());
|
||||
|
||||
std::cout << "Testing ArrayHandleTransform\n";
|
||||
vtkm::testing::Testing::TryTypes(TestArrayHandleTransform(), TestTypesList());
|
||||
|
||||
std::cout << "Testing ArrayHandleUniformPointCoordinates\n";
|
||||
TestArrayHandleUniformPointCoordinates();
|
||||
|
||||
std::cout << "Testing ArrayHandleVirtualCoordinates\n";
|
||||
TestArrayHandleVirtualCoordinates();
|
||||
|
||||
std::cout << "Testing ArrayHandleZip\n";
|
||||
vtkm::testing::Testing::TryTypes(TestArrayHandleZip(), TestTypesList());
|
||||
if (vtkm::ListHas<VTKM_DEFAULT_STORAGE_LIST, vtkm::cont::StorageTagUniformPoints>::value)
|
||||
{
|
||||
std::cout << "Testing ArrayHandleUniformPointCoordinates\n";
|
||||
TestArrayHandleUniformPointCoordinates();
|
||||
}
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
@ -542,37 +371,3 @@ int UnitTestSerializationArrayHandle(int argc, char* argv[])
|
||||
|
||||
return vtkm::cont::testing::Testing::Run(TestArrayHandleSerialization, argc, argv);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
namespace vtkm
|
||||
{
|
||||
namespace cont
|
||||
{
|
||||
|
||||
template <typename T>
|
||||
struct SerializableTypeString<TestArrayHandleImplicit::ImplicitFunctor<T>>
|
||||
{
|
||||
static VTKM_CONT const std::string& Get()
|
||||
{
|
||||
static std::string name =
|
||||
"TestArrayHandleImplicit::ImplicitFunctor<" + SerializableTypeString<T>::Get() + ">";
|
||||
return name;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct SerializableTypeString<TestArrayHandleTransform::TransformFunctor>
|
||||
{
|
||||
static VTKM_CONT const std::string Get() { return "TestArrayHandleTransform::TransformFunctor"; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct SerializableTypeString<TestArrayHandleTransform::InverseTransformFunctor>
|
||||
{
|
||||
static VTKM_CONT const std::string Get()
|
||||
{
|
||||
return "TestArrayHandleTransform::InverseTransformFunctor";
|
||||
}
|
||||
};
|
||||
}
|
||||
} // vtkm::cont
|
||||
|
@ -187,6 +187,9 @@ void CheckArrayVariant(const vtkm::cont::VariantArrayHandleBase<TypeList>& array
|
||||
VTKM_TEST_ASSERT(!calledUnusual, "The array somehow got cast to an unusual storage.");
|
||||
}
|
||||
|
||||
#if 0
|
||||
// Test disabled. CastAndCall no longer casts to ArrayHandleVirtual because
|
||||
// that is getting deprecated.
|
||||
std::cout << " CastAndCall with no storage" << std::endl;
|
||||
calledBasic = false;
|
||||
calledUnusual = false;
|
||||
@ -197,6 +200,7 @@ void CheckArrayVariant(const vtkm::cont::VariantArrayHandleBase<TypeList>& array
|
||||
"The functor was never called (and apparently a bad value exception not thrown).");
|
||||
VTKM_TEST_ASSERT(!calledBasic, "The array somehow got cast to a basic storage.");
|
||||
VTKM_TEST_ASSERT(!calledUnusual, "The array somehow got cast to an unusual storage.");
|
||||
#endif
|
||||
|
||||
std::cout << " CastAndCall with extra storage" << std::endl;
|
||||
calledBasic = false;
|
||||
@ -469,6 +473,9 @@ void TryUnusualType()
|
||||
std::cout << " Found type when type list was reset." << std::endl;
|
||||
}
|
||||
|
||||
#if 0
|
||||
// It is now requred to know the storage used (no longer wrapping in ArrayHandleVirtual),
|
||||
// so disable this test.
|
||||
void TryUnusualStorage()
|
||||
{
|
||||
vtkm::cont::VariantArrayHandle array = ArrayHandleWithUnusualStorage<vtkm::Id>();
|
||||
@ -506,6 +513,7 @@ void TryUnusualTypeAndStorage()
|
||||
VTKM_TEST_FAIL("CastAndCall with Variant failed to handle unusual storage.");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
template <typename ArrayHandleType>
|
||||
void TryCastToArrayHandle(const ArrayHandleType& array)
|
||||
@ -586,11 +594,15 @@ void TestVariantArrayHandle()
|
||||
std::cout << "Try unusual type." << std::endl;
|
||||
TryUnusualType();
|
||||
|
||||
#if 0
|
||||
// It is now requred to know the storage used (no longer wrapping in ArrayHandleVirtual),
|
||||
// so disable this test.
|
||||
std::cout << "Try unusual storage." << std::endl;
|
||||
TryUnusualStorage();
|
||||
|
||||
std::cout << "Try unusual type in unusual storage." << std::endl;
|
||||
TryUnusualTypeAndStorage();
|
||||
#endif
|
||||
|
||||
std::cout << "Try CastToArrayHandle" << std::endl;
|
||||
TryCastToArrayHandle();
|
||||
|
Loading…
Reference in New Issue
Block a user