2014-04-03 19:17:14 +00:00
|
|
|
//============================================================================
|
|
|
|
// Copyright (c) Kitware, Inc.
|
|
|
|
// All rights reserved.
|
|
|
|
// See LICENSE.txt for details.
|
2019-04-15 23:24:21 +00:00
|
|
|
//
|
2014-04-03 19:17:14 +00:00
|
|
|
// 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.
|
|
|
|
//============================================================================
|
|
|
|
|
2018-12-11 13:56:08 +00:00
|
|
|
#include <vtkm/cont/VariantArrayHandle.h>
|
2014-04-03 19:17:14 +00:00
|
|
|
|
2014-10-08 21:40:20 +00:00
|
|
|
#include <vtkm/TypeTraits.h>
|
|
|
|
|
2015-09-20 06:28:11 +00:00
|
|
|
#include <vtkm/cont/ArrayHandleCast.h>
|
|
|
|
#include <vtkm/cont/ArrayHandleCompositeVector.h>
|
|
|
|
#include <vtkm/cont/ArrayHandleConstant.h>
|
|
|
|
#include <vtkm/cont/ArrayHandleCounting.h>
|
2015-09-28 23:19:38 +00:00
|
|
|
#include <vtkm/cont/ArrayHandleGroupVec.h>
|
2015-09-20 06:28:11 +00:00
|
|
|
#include <vtkm/cont/ArrayHandleImplicit.h>
|
|
|
|
#include <vtkm/cont/ArrayHandleIndex.h>
|
|
|
|
#include <vtkm/cont/ArrayHandlePermutation.h>
|
|
|
|
#include <vtkm/cont/ArrayHandleTransform.h>
|
|
|
|
#include <vtkm/cont/ArrayHandleUniformPointCoordinates.h>
|
2018-11-08 15:37:50 +00:00
|
|
|
#include <vtkm/cont/ArrayHandleVirtual.h>
|
2015-09-20 06:28:11 +00:00
|
|
|
#include <vtkm/cont/ArrayHandleZip.h>
|
2014-06-23 23:33:04 +00:00
|
|
|
|
2014-04-03 19:17:14 +00:00
|
|
|
#include <vtkm/cont/internal/IteratorFromArrayPortal.h>
|
|
|
|
|
|
|
|
#include <vtkm/cont/testing/Testing.h>
|
|
|
|
|
|
|
|
#include <sstream>
|
|
|
|
#include <string>
|
2019-03-15 19:15:47 +00:00
|
|
|
#include <type_traits>
|
2014-07-10 16:53:02 +00:00
|
|
|
#include <typeinfo>
|
2014-04-03 19:17:14 +00:00
|
|
|
|
2020-07-16 21:22:39 +00:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
|
|
|
// Make an "unusual" type to use in the test. This is simply a type that
|
|
|
|
// is sure not to be declared elsewhere.
|
|
|
|
struct UnusualType
|
|
|
|
{
|
|
|
|
using T = vtkm::Id;
|
|
|
|
T X;
|
|
|
|
UnusualType() = default;
|
|
|
|
UnusualType(T x)
|
|
|
|
: X(x)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
UnusualType& operator=(T x)
|
|
|
|
{
|
|
|
|
this->X = x;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
operator T() const { return this->X; }
|
|
|
|
};
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace vtkm
|
|
|
|
{
|
2015-07-08 20:09:36 +00:00
|
|
|
|
2018-12-11 13:56:08 +00:00
|
|
|
// VariantArrayHandle requires its value type to have a defined VecTraits
|
2020-07-16 21:22:39 +00:00
|
|
|
// class. One of the tests is to use an "unusual" array.
|
2015-07-08 20:09:36 +00:00
|
|
|
// Make an implementation here. Because I am lazy, this is only a partial
|
|
|
|
// implementation.
|
2017-05-18 14:29:41 +00:00
|
|
|
template <>
|
2020-07-16 21:22:39 +00:00
|
|
|
struct VecTraits<UnusualType> : VecTraits<UnusualType::T>
|
2015-07-08 20:09:36 +00:00
|
|
|
{
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace vtkm
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace
|
|
|
|
{
|
2014-04-03 19:17:14 +00:00
|
|
|
|
|
|
|
const vtkm::Id ARRAY_SIZE = 10;
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename T>
|
2015-09-20 06:28:11 +00:00
|
|
|
struct TestValueFunctor
|
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
T operator()(vtkm::Id index) const { return TestValue(index, T()); }
|
2015-09-20 06:28:11 +00:00
|
|
|
};
|
|
|
|
|
2014-04-03 19:17:14 +00:00
|
|
|
struct CheckFunctor
|
|
|
|
{
|
2020-07-16 21:22:39 +00:00
|
|
|
template <typename T, typename S>
|
|
|
|
static void CheckArray(const vtkm::cont::ArrayHandle<T, S>& array)
|
|
|
|
{
|
|
|
|
VTKM_TEST_ASSERT(array.GetNumberOfValues() == ARRAY_SIZE, "Unexpected array size.");
|
|
|
|
CheckPortal(array.ReadPortal());
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename S>
|
|
|
|
static void CheckArray(const vtkm::cont::ArrayHandle<UnusualType, S>& array)
|
|
|
|
{
|
|
|
|
VTKM_TEST_ASSERT(array.GetNumberOfValues() == ARRAY_SIZE, "Unexpected array size.");
|
|
|
|
auto portal = array.ReadPortal();
|
|
|
|
for (vtkm::Id index = 0; index < array.GetNumberOfValues(); ++index)
|
|
|
|
{
|
|
|
|
VTKM_TEST_ASSERT(portal.Get(index) == TestValue(index, UnusualType::T{}));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-08 15:37:50 +00:00
|
|
|
template <typename T>
|
2019-01-17 04:31:55 +00:00
|
|
|
void operator()(const vtkm::cont::ArrayHandle<T>& array,
|
|
|
|
bool& calledBasic,
|
|
|
|
bool& vtkmNotUsed(calledVirtual)) const
|
|
|
|
{
|
|
|
|
calledBasic = true;
|
|
|
|
std::cout << " Checking for basic array type: " << typeid(T).name() << std::endl;
|
|
|
|
|
2020-07-16 21:22:39 +00:00
|
|
|
CheckArray(array);
|
2019-01-17 04:31:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
void operator()(const vtkm::cont::ArrayHandleVirtual<T>& array,
|
|
|
|
bool& vtkmNotUsed(calledBasic),
|
|
|
|
bool& calledVirtual) const
|
2017-05-18 14:29:41 +00:00
|
|
|
{
|
2019-01-17 04:31:55 +00:00
|
|
|
calledVirtual = true;
|
|
|
|
std::cout << " Checking for virtual array type: " << typeid(T).name() << std::endl;
|
2014-04-03 19:17:14 +00:00
|
|
|
|
2020-07-16 21:22:39 +00:00
|
|
|
CheckArray(array);
|
2014-04-03 19:17:14 +00:00
|
|
|
}
|
2020-03-17 23:22:35 +00:00
|
|
|
|
|
|
|
template <typename T, typename S>
|
2020-07-22 00:38:32 +00:00
|
|
|
void operator()(const vtkm::cont::ArrayHandle<T, S>&, bool&, bool&) const
|
2020-03-17 23:22:35 +00:00
|
|
|
{
|
|
|
|
VTKM_TEST_FAIL("Array resolved to unexpected type.");
|
|
|
|
}
|
2014-04-03 19:17:14 +00:00
|
|
|
};
|
|
|
|
|
2018-11-08 15:37:50 +00:00
|
|
|
template <typename TypeList>
|
2018-12-11 13:56:08 +00:00
|
|
|
void BasicArrayVariantChecks(const vtkm::cont::VariantArrayHandleBase<TypeList>& array,
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::IdComponent numComponents)
|
2015-06-16 21:23:50 +00:00
|
|
|
{
|
2015-07-08 20:09:36 +00:00
|
|
|
VTKM_TEST_ASSERT(array.GetNumberOfValues() == ARRAY_SIZE,
|
|
|
|
"Dynamic array reports unexpected size.");
|
2019-03-15 20:47:32 +00:00
|
|
|
std::cout << "array.GetNumberOfComponents() = " << array.GetNumberOfComponents() << ", "
|
|
|
|
<< "numComponents = " << numComponents << "\n";
|
2015-07-08 20:09:36 +00:00
|
|
|
VTKM_TEST_ASSERT(array.GetNumberOfComponents() == numComponents,
|
|
|
|
"Dynamic array reports unexpected number of components.");
|
|
|
|
}
|
|
|
|
|
2018-11-08 15:37:50 +00:00
|
|
|
template <typename TypeList>
|
2018-12-11 13:56:08 +00:00
|
|
|
void CheckArrayVariant(const vtkm::cont::VariantArrayHandleBase<TypeList>& array,
|
2019-01-17 04:31:55 +00:00
|
|
|
vtkm::IdComponent numComponents,
|
2020-07-22 00:38:32 +00:00
|
|
|
bool isBasicArray)
|
2015-06-16 21:23:50 +00:00
|
|
|
{
|
2018-11-08 15:37:50 +00:00
|
|
|
BasicArrayVariantChecks(array, numComponents);
|
2015-07-08 20:09:36 +00:00
|
|
|
|
2019-01-17 04:31:55 +00:00
|
|
|
std::cout << " CastAndCall with default storage" << std::endl;
|
|
|
|
bool calledBasic = false;
|
|
|
|
bool calledVirtual = false;
|
2020-07-22 00:38:32 +00:00
|
|
|
CastAndCall(array, CheckFunctor(), calledBasic, calledVirtual);
|
2019-01-17 04:31:55 +00:00
|
|
|
|
|
|
|
VTKM_TEST_ASSERT(
|
2020-07-22 00:38:32 +00:00
|
|
|
calledBasic || calledVirtual,
|
2019-01-17 04:31:55 +00:00
|
|
|
"The functor was never called (and apparently a bad value exception not thrown).");
|
|
|
|
if (isBasicArray)
|
|
|
|
{
|
|
|
|
VTKM_TEST_ASSERT(calledBasic, "The functor was never called with the basic array fast path");
|
|
|
|
VTKM_TEST_ASSERT(!calledVirtual, "The functor was somehow called with the virtual path");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
VTKM_TEST_ASSERT(!calledBasic, "The array somehow got cast to a basic storage.");
|
|
|
|
}
|
2015-06-16 21:23:50 +00:00
|
|
|
|
2019-01-17 04:31:55 +00:00
|
|
|
std::cout << " CastAndCall with extra storage" << std::endl;
|
|
|
|
calledBasic = false;
|
|
|
|
calledVirtual = false;
|
2020-07-22 00:38:32 +00:00
|
|
|
array.CastAndCall(vtkm::List<vtkm::cont::StorageTagBasic, vtkm::cont::StorageTagConstant>{},
|
2019-01-17 04:31:55 +00:00
|
|
|
CheckFunctor(),
|
|
|
|
calledBasic,
|
|
|
|
calledVirtual);
|
|
|
|
VTKM_TEST_ASSERT(
|
2020-07-22 00:38:32 +00:00
|
|
|
calledBasic || calledVirtual,
|
2019-01-17 04:31:55 +00:00
|
|
|
"The functor was never called (and apparently a bad value exception not thrown).");
|
|
|
|
if (isBasicArray)
|
|
|
|
{
|
|
|
|
VTKM_TEST_ASSERT(calledBasic, "The functor was never called with the basic array fast path");
|
|
|
|
VTKM_TEST_ASSERT(!calledVirtual, "The functor was somehow called with the virtual path");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
VTKM_TEST_ASSERT(!calledBasic, "The array somehow got cast to a basic storage.");
|
|
|
|
}
|
2015-06-16 21:23:50 +00:00
|
|
|
}
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename T>
|
2018-12-11 13:56:08 +00:00
|
|
|
vtkm::cont::VariantArrayHandle CreateArrayVariant(T)
|
2014-04-03 19:17:14 +00:00
|
|
|
{
|
2020-07-16 16:32:32 +00:00
|
|
|
vtkm::cont::ArrayHandle<T> array;
|
|
|
|
array.Allocate(ARRAY_SIZE);
|
|
|
|
SetPortal(array.WritePortal());
|
|
|
|
return vtkm::cont::VariantArrayHandle(array);
|
2014-04-03 19:17:14 +00:00
|
|
|
}
|
|
|
|
|
2020-07-16 21:22:39 +00:00
|
|
|
vtkm::cont::VariantArrayHandle CreateArrayVariant(UnusualType)
|
|
|
|
{
|
|
|
|
vtkm::cont::ArrayHandle<UnusualType> array;
|
|
|
|
array.Allocate(ARRAY_SIZE);
|
|
|
|
auto portal = array.WritePortal();
|
|
|
|
for (vtkm::Id index = 0; index < ARRAY_SIZE; ++index)
|
|
|
|
{
|
|
|
|
portal.Set(index, TestValue(index, UnusualType::T{}));
|
|
|
|
}
|
|
|
|
return vtkm::cont::VariantArrayHandle(array);
|
|
|
|
}
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename ArrayHandleType>
|
|
|
|
void CheckCastToArrayHandle(const ArrayHandleType& array)
|
2015-09-18 04:31:58 +00:00
|
|
|
{
|
|
|
|
VTKM_IS_ARRAY_HANDLE(ArrayHandleType);
|
|
|
|
|
2018-12-11 13:56:08 +00:00
|
|
|
vtkm::cont::VariantArrayHandle arrayVariant = array;
|
2020-07-16 21:22:39 +00:00
|
|
|
VTKM_TEST_ASSERT(!arrayVariant.IsType<vtkm::cont::ArrayHandle<UnusualType>>(),
|
2017-05-18 14:29:41 +00:00
|
|
|
"Dynamic array reporting is wrong type.");
|
2015-09-18 04:31:58 +00:00
|
|
|
|
|
|
|
ArrayHandleType castArray1;
|
2018-11-08 15:37:50 +00:00
|
|
|
arrayVariant.CopyTo(castArray1);
|
|
|
|
VTKM_TEST_ASSERT(arrayVariant.IsType<ArrayHandleType>(), "Did not query handle correctly.");
|
2015-09-20 06:28:11 +00:00
|
|
|
VTKM_TEST_ASSERT(array == castArray1, "Did not get back same array.");
|
2015-09-18 04:31:58 +00:00
|
|
|
|
2018-11-08 15:37:50 +00:00
|
|
|
ArrayHandleType castArray2 = arrayVariant.Cast<ArrayHandleType>();
|
2015-09-20 06:28:11 +00:00
|
|
|
VTKM_TEST_ASSERT(array == castArray2, "Did not get back same array.");
|
2019-03-15 19:15:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// A vtkm::Vec if NumComps > 1, otherwise a scalar
|
|
|
|
template <typename T, vtkm::IdComponent NumComps>
|
|
|
|
using VecOrScalar = typename std::conditional<(NumComps > 1), vtkm::Vec<T, NumComps>, T>::type;
|
|
|
|
|
|
|
|
template <typename ArrayType>
|
|
|
|
void CheckCastToVirtualArrayHandle(const ArrayType& array)
|
|
|
|
{
|
|
|
|
VTKM_IS_ARRAY_HANDLE(ArrayType);
|
|
|
|
|
|
|
|
using ValueType = typename ArrayType::ValueType;
|
|
|
|
using VTraits = vtkm::VecTraits<ValueType>;
|
|
|
|
using ComponentType = typename VTraits::ComponentType;
|
|
|
|
static constexpr vtkm::IdComponent NumComps = VTraits::NUM_COMPONENTS;
|
|
|
|
|
|
|
|
using Storage = typename ArrayType::StorageTag;
|
2019-12-05 21:38:41 +00:00
|
|
|
using StorageList = vtkm::ListAppend<VTKM_DEFAULT_STORAGE_LIST, vtkm::List<Storage>>;
|
2019-03-15 19:15:47 +00:00
|
|
|
|
2019-12-05 17:55:57 +00:00
|
|
|
using TypeList = vtkm::ListAppend<VTKM_DEFAULT_TYPE_LIST, vtkm::List<ValueType>>;
|
2019-03-15 19:15:47 +00:00
|
|
|
using VariantArrayType = vtkm::cont::VariantArrayHandleBase<TypeList>;
|
|
|
|
|
|
|
|
VariantArrayType arrayVariant = array;
|
|
|
|
|
|
|
|
{
|
|
|
|
auto testArray = arrayVariant.template AsVirtual<ValueType, StorageList>();
|
|
|
|
VTKM_TEST_ASSERT(testArray.GetNumberOfValues() == array.GetNumberOfValues(),
|
|
|
|
"Did not get back virtual array handle representation.");
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
auto testArray =
|
|
|
|
arrayVariant.template AsVirtual<VecOrScalar<vtkm::Int8, NumComps>, StorageList>();
|
|
|
|
VTKM_TEST_ASSERT(testArray.GetNumberOfValues() == array.GetNumberOfValues(),
|
|
|
|
"Did not get back virtual array handle representation.");
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
auto testArray =
|
|
|
|
arrayVariant.template AsVirtual<VecOrScalar<vtkm::Int64, NumComps>, StorageList>();
|
|
|
|
VTKM_TEST_ASSERT(testArray.GetNumberOfValues() == array.GetNumberOfValues(),
|
|
|
|
"Did not get back virtual array handle representation.");
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
auto testArray =
|
|
|
|
arrayVariant.template AsVirtual<VecOrScalar<vtkm::UInt64, NumComps>, StorageList>();
|
|
|
|
VTKM_TEST_ASSERT(testArray.GetNumberOfValues() == array.GetNumberOfValues(),
|
|
|
|
"Did not get back virtual array handle representation.");
|
|
|
|
}
|
2018-11-08 15:37:50 +00:00
|
|
|
|
2019-03-15 19:15:47 +00:00
|
|
|
{
|
|
|
|
auto testArray =
|
|
|
|
arrayVariant.template AsVirtual<VecOrScalar<vtkm::Float32, NumComps>, StorageList>();
|
|
|
|
VTKM_TEST_ASSERT(testArray.GetNumberOfValues() == array.GetNumberOfValues(),
|
|
|
|
"Did not get back virtual array handle representation.");
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
auto testArray =
|
|
|
|
arrayVariant.template AsVirtual<VecOrScalar<vtkm::Float64, NumComps>, StorageList>();
|
|
|
|
VTKM_TEST_ASSERT(testArray.GetNumberOfValues() == array.GetNumberOfValues(),
|
|
|
|
"Did not get back virtual array handle representation.");
|
|
|
|
}
|
|
|
|
|
|
|
|
bool threw = false;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
arrayVariant.template AsVirtual<vtkm::Vec<ComponentType, NumComps + 1>, StorageList>();
|
|
|
|
}
|
|
|
|
catch (vtkm::cont::ErrorBadType&)
|
|
|
|
{
|
|
|
|
// caught expected exception
|
|
|
|
threw = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_TEST_ASSERT(threw,
|
|
|
|
"Casting to different vector width did not throw expected "
|
|
|
|
"ErrorBadType exception.");
|
2015-09-18 04:31:58 +00:00
|
|
|
}
|
|
|
|
|
2018-11-08 15:37:50 +00:00
|
|
|
template <typename T, typename ArrayVariantType>
|
|
|
|
void TryNewInstance(T, ArrayVariantType originalArray)
|
2015-06-16 21:23:50 +00:00
|
|
|
{
|
|
|
|
// This check should already have been performed by caller, but just in case.
|
2020-07-22 00:38:32 +00:00
|
|
|
CheckArrayVariant(originalArray, vtkm::VecTraits<T>::NUM_COMPONENTS, true);
|
2015-06-16 21:23:50 +00:00
|
|
|
|
|
|
|
std::cout << "Create new instance of array." << std::endl;
|
2018-11-08 15:37:50 +00:00
|
|
|
ArrayVariantType newArray = originalArray.NewInstance();
|
2015-06-16 21:23:50 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
std::cout << "Get a static instance of the new array (which checks the type)." << std::endl;
|
2016-01-14 19:01:05 +00:00
|
|
|
vtkm::cont::ArrayHandle<T> staticArray;
|
|
|
|
newArray.CopyTo(staticArray);
|
2015-06-16 21:23:50 +00:00
|
|
|
|
|
|
|
std::cout << "Fill the new array with invalid values and make sure the original" << std::endl
|
|
|
|
<< "is uneffected." << std::endl;
|
|
|
|
staticArray.Allocate(ARRAY_SIZE);
|
|
|
|
for (vtkm::Id index = 0; index < ARRAY_SIZE; index++)
|
|
|
|
{
|
2020-01-28 19:14:32 +00:00
|
|
|
staticArray.WritePortal().Set(index, TestValue(index + 100, T()));
|
2015-06-16 21:23:50 +00:00
|
|
|
}
|
2020-07-22 00:38:32 +00:00
|
|
|
CheckArrayVariant(originalArray, vtkm::VecTraits<T>::NUM_COMPONENTS, true);
|
2015-06-16 21:23:50 +00:00
|
|
|
|
|
|
|
std::cout << "Set the new static array to expected values and make sure the new" << std::endl
|
|
|
|
<< "dynamic array points to the same new values." << std::endl;
|
|
|
|
for (vtkm::Id index = 0; index < ARRAY_SIZE; index++)
|
|
|
|
{
|
2020-01-28 19:14:32 +00:00
|
|
|
staticArray.WritePortal().Set(index, TestValue(index, T()));
|
2015-06-16 21:23:50 +00:00
|
|
|
}
|
2020-07-22 00:38:32 +00:00
|
|
|
CheckArrayVariant(newArray, vtkm::VecTraits<T>::NUM_COMPONENTS, true);
|
2015-06-16 21:23:50 +00:00
|
|
|
}
|
|
|
|
|
2019-09-05 14:57:58 +00:00
|
|
|
template <typename T, typename ArrayVariantType>
|
|
|
|
void TryAsMultiplexer(T, ArrayVariantType sourceArray)
|
|
|
|
{
|
|
|
|
auto originalArray = sourceArray.template Cast<vtkm::cont::ArrayHandle<T>>();
|
|
|
|
|
|
|
|
{
|
|
|
|
std::cout << "Get multiplex array through direct type." << std::endl;
|
|
|
|
using MultiplexerType = vtkm::cont::ArrayHandleMultiplexer<vtkm::cont::ArrayHandle<T>,
|
|
|
|
vtkm::cont::ArrayHandleConstant<T>>;
|
|
|
|
MultiplexerType multiplexArray = sourceArray.template AsMultiplexer<MultiplexerType>();
|
|
|
|
|
|
|
|
VTKM_TEST_ASSERT(multiplexArray.IsValid());
|
2020-01-28 19:14:32 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal_portals(multiplexArray.ReadPortal(), originalArray.ReadPortal()));
|
2019-09-05 14:57:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
std::cout << "Get multiplex array through cast type." << std::endl;
|
|
|
|
using CastT = typename vtkm::VecTraits<T>::template ReplaceBaseComponentType<vtkm::Float64>;
|
|
|
|
using MultiplexerType = vtkm::cont::ArrayHandleMultiplexer<
|
|
|
|
vtkm::cont::ArrayHandle<CastT>,
|
|
|
|
vtkm::cont::ArrayHandleCast<CastT, vtkm::cont::ArrayHandle<T>>>;
|
|
|
|
MultiplexerType multiplexArray = sourceArray.template AsMultiplexer<MultiplexerType>();
|
|
|
|
|
|
|
|
VTKM_TEST_ASSERT(multiplexArray.IsValid());
|
2020-01-28 19:14:32 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal_portals(multiplexArray.ReadPortal(), originalArray.ReadPortal()));
|
2019-09-05 14:57:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
std::cout << "Make sure multiplex array prefers direct array (1st arg)" << std::endl;
|
|
|
|
using MultiplexerType = vtkm::cont::ArrayHandleMultiplexer<
|
|
|
|
vtkm::cont::ArrayHandle<T>,
|
|
|
|
vtkm::cont::ArrayHandleCast<T, vtkm::cont::ArrayHandle<T>>>;
|
|
|
|
MultiplexerType multiplexArray = sourceArray.template AsMultiplexer<MultiplexerType>();
|
|
|
|
|
|
|
|
VTKM_TEST_ASSERT(multiplexArray.IsValid());
|
|
|
|
VTKM_TEST_ASSERT(multiplexArray.GetStorage().GetArrayHandleVariant().GetIndex() == 0);
|
2020-01-28 19:14:32 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal_portals(multiplexArray.ReadPortal(), originalArray.ReadPortal()));
|
2019-09-05 14:57:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
std::cout << "Make sure multiplex array prefers direct array (2nd arg)" << std::endl;
|
|
|
|
using MultiplexerType =
|
|
|
|
vtkm::cont::ArrayHandleMultiplexer<vtkm::cont::ArrayHandleCast<T, vtkm::cont::ArrayHandle<T>>,
|
|
|
|
vtkm::cont::ArrayHandle<T>>;
|
|
|
|
MultiplexerType multiplexArray = sourceArray.template AsMultiplexer<MultiplexerType>();
|
|
|
|
|
|
|
|
VTKM_TEST_ASSERT(multiplexArray.IsValid());
|
|
|
|
VTKM_TEST_ASSERT(multiplexArray.GetStorage().GetArrayHandleVariant().GetIndex() == 1);
|
2020-01-28 19:14:32 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal_portals(multiplexArray.ReadPortal(), originalArray.ReadPortal()));
|
2019-09-05 14:57:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename T>
|
2014-04-03 19:17:14 +00:00
|
|
|
void TryDefaultType(T)
|
|
|
|
{
|
2018-12-11 13:56:08 +00:00
|
|
|
vtkm::cont::VariantArrayHandle array = CreateArrayVariant(T());
|
2014-04-03 19:17:14 +00:00
|
|
|
|
2020-07-22 00:38:32 +00:00
|
|
|
CheckArrayVariant(array, vtkm::VecTraits<T>::NUM_COMPONENTS, true);
|
2014-04-03 19:17:14 +00:00
|
|
|
|
2015-06-16 21:23:50 +00:00
|
|
|
TryNewInstance(T(), array);
|
2019-09-05 14:57:58 +00:00
|
|
|
|
|
|
|
TryAsMultiplexer(T(), array);
|
2014-04-03 19:17:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct TryBasicVTKmType
|
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename T>
|
|
|
|
void operator()(T) const
|
|
|
|
{
|
2018-12-11 13:56:08 +00:00
|
|
|
vtkm::cont::VariantArrayHandle array = CreateArrayVariant(T());
|
2014-04-03 19:17:14 +00:00
|
|
|
|
2019-01-17 04:31:55 +00:00
|
|
|
CheckArrayVariant(
|
2020-07-22 00:38:32 +00:00
|
|
|
array.ResetTypes(vtkm::TypeListAll()), vtkm::VecTraits<T>::NUM_COMPONENTS, true);
|
2014-04-03 19:17:14 +00:00
|
|
|
|
2019-12-05 17:55:57 +00:00
|
|
|
TryNewInstance(T(), array.ResetTypes(vtkm::TypeListAll()));
|
2014-04-03 19:17:14 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
void TryUnusualType()
|
|
|
|
{
|
|
|
|
// A string is an unlikely type to be declared elsewhere in VTK-m.
|
2020-07-16 21:22:39 +00:00
|
|
|
vtkm::cont::VariantArrayHandle array = CreateArrayVariant(UnusualType{});
|
2014-04-03 19:17:14 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2020-07-22 00:38:32 +00:00
|
|
|
CheckArrayVariant(array, 1, true);
|
2014-04-03 19:17:14 +00:00
|
|
|
VTKM_TEST_FAIL("CastAndCall failed to error for unrecognized type.");
|
|
|
|
}
|
2017-02-23 15:13:30 +00:00
|
|
|
catch (vtkm::cont::ErrorBadValue&)
|
2014-04-03 19:17:14 +00:00
|
|
|
{
|
|
|
|
std::cout << " Caught exception for unrecognized type." << std::endl;
|
|
|
|
}
|
2020-07-16 21:22:39 +00:00
|
|
|
CheckArrayVariant(array.ResetTypes(vtkm::List<UnusualType>()), 1, true);
|
2017-05-18 14:29:41 +00:00
|
|
|
std::cout << " Found type when type list was reset." << std::endl;
|
2014-04-03 19:17:14 +00:00
|
|
|
}
|
2019-03-15 19:15:47 +00:00
|
|
|
template <typename ArrayHandleType>
|
|
|
|
void TryCastToArrayHandle(const ArrayHandleType& array)
|
|
|
|
{
|
|
|
|
CheckCastToArrayHandle(array);
|
|
|
|
CheckCastToVirtualArrayHandle(array);
|
|
|
|
}
|
|
|
|
|
2015-09-18 04:31:58 +00:00
|
|
|
void TryCastToArrayHandle()
|
|
|
|
{
|
|
|
|
std::cout << " Normal array handle." << std::endl;
|
2015-09-20 06:28:11 +00:00
|
|
|
vtkm::Id buffer[ARRAY_SIZE];
|
2015-09-18 04:31:58 +00:00
|
|
|
for (vtkm::Id index = 0; index < ARRAY_SIZE; index++)
|
|
|
|
{
|
2015-09-20 06:28:11 +00:00
|
|
|
buffer[index] = TestValue(index, vtkm::Id());
|
2015-09-18 04:31:58 +00:00
|
|
|
}
|
2019-03-15 19:15:47 +00:00
|
|
|
|
2020-07-16 16:32:32 +00:00
|
|
|
vtkm::cont::ArrayHandle<vtkm::Id> array =
|
|
|
|
vtkm::cont::make_ArrayHandle(buffer, ARRAY_SIZE, vtkm::CopyFlag::On);
|
2019-03-15 19:15:47 +00:00
|
|
|
TryCastToArrayHandle(array);
|
2015-09-20 06:28:11 +00:00
|
|
|
|
|
|
|
std::cout << " Cast array handle." << std::endl;
|
2019-03-15 19:15:47 +00:00
|
|
|
TryCastToArrayHandle(vtkm::cont::make_ArrayHandleCast(array, vtkm::FloatDefault()));
|
2015-09-20 06:28:11 +00:00
|
|
|
|
|
|
|
std::cout << " Composite vector array handle." << std::endl;
|
2019-03-15 19:15:47 +00:00
|
|
|
TryCastToArrayHandle(vtkm::cont::make_ArrayHandleCompositeVector(array, array));
|
2015-09-20 06:28:11 +00:00
|
|
|
|
|
|
|
std::cout << " Constant array handle." << std::endl;
|
2019-03-15 19:15:47 +00:00
|
|
|
TryCastToArrayHandle(vtkm::cont::make_ArrayHandleConstant(5, ARRAY_SIZE));
|
2015-09-20 06:28:11 +00:00
|
|
|
|
|
|
|
std::cout << " Counting array handle." << std::endl;
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::cont::ArrayHandleCounting<vtkm::Id> countingArray(ARRAY_SIZE - 1, -1, ARRAY_SIZE);
|
2019-03-15 19:15:47 +00:00
|
|
|
TryCastToArrayHandle(countingArray);
|
2015-09-20 06:28:11 +00:00
|
|
|
|
2015-09-28 23:19:38 +00:00
|
|
|
std::cout << " Group vec array handle" << std::endl;
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::cont::ArrayHandleGroupVec<vtkm::cont::ArrayHandle<vtkm::Id>, 2> groupVecArray(array);
|
2019-03-15 19:15:47 +00:00
|
|
|
TryCastToArrayHandle(groupVecArray);
|
2015-09-28 23:19:38 +00:00
|
|
|
|
2015-09-20 06:28:11 +00:00
|
|
|
std::cout << " Implicit array handle." << std::endl;
|
2019-03-15 19:15:47 +00:00
|
|
|
TryCastToArrayHandle(
|
2017-05-30 15:13:18 +00:00
|
|
|
vtkm::cont::make_ArrayHandleImplicit(TestValueFunctor<vtkm::FloatDefault>(), ARRAY_SIZE));
|
2015-09-20 06:28:11 +00:00
|
|
|
|
|
|
|
std::cout << " Index array handle." << std::endl;
|
2019-03-15 19:15:47 +00:00
|
|
|
TryCastToArrayHandle(vtkm::cont::ArrayHandleIndex(ARRAY_SIZE));
|
2015-09-20 06:28:11 +00:00
|
|
|
|
|
|
|
std::cout << " Permutation array handle." << std::endl;
|
2019-03-15 19:15:47 +00:00
|
|
|
TryCastToArrayHandle(vtkm::cont::make_ArrayHandlePermutation(countingArray, array));
|
2015-09-20 06:28:11 +00:00
|
|
|
|
|
|
|
std::cout << " Transform array handle." << std::endl;
|
2019-03-15 19:15:47 +00:00
|
|
|
TryCastToArrayHandle(
|
2017-05-30 14:00:01 +00:00
|
|
|
vtkm::cont::make_ArrayHandleTransform(countingArray, TestValueFunctor<vtkm::FloatDefault>()));
|
2015-09-20 06:28:11 +00:00
|
|
|
|
|
|
|
std::cout << " Uniform point coordinates array handle." << std::endl;
|
2019-03-15 19:15:47 +00:00
|
|
|
TryCastToArrayHandle(vtkm::cont::ArrayHandleUniformPointCoordinates(vtkm::Id3(ARRAY_SIZE)));
|
2015-09-20 06:28:11 +00:00
|
|
|
|
2018-11-08 15:37:50 +00:00
|
|
|
// std::cout << " Zip array handle." << std::endl;
|
|
|
|
// CheckCastToArrayHandle(vtkm::cont::make_ArrayHandleZip(countingArray, array));
|
2015-09-18 04:31:58 +00:00
|
|
|
}
|
|
|
|
|
2018-12-11 13:56:08 +00:00
|
|
|
void TestVariantArrayHandle()
|
2014-04-03 19:17:14 +00:00
|
|
|
{
|
|
|
|
std::cout << "Try common types with default type lists." << std::endl;
|
2014-10-09 14:54:56 +00:00
|
|
|
std::cout << "*** vtkm::Id **********************" << std::endl;
|
2014-04-03 19:17:14 +00:00
|
|
|
TryDefaultType(vtkm::Id());
|
2014-10-09 14:54:56 +00:00
|
|
|
std::cout << "*** vtkm::FloatDefault ************" << std::endl;
|
|
|
|
TryDefaultType(vtkm::FloatDefault());
|
|
|
|
std::cout << "*** vtkm::Float32 *****************" << std::endl;
|
|
|
|
TryDefaultType(vtkm::Float32());
|
|
|
|
std::cout << "*** vtkm::Float64 *****************" << std::endl;
|
|
|
|
TryDefaultType(vtkm::Float64());
|
|
|
|
std::cout << "*** vtkm::Vec<Float32,3> **********" << std::endl;
|
2019-07-31 16:20:38 +00:00
|
|
|
TryDefaultType(vtkm::Vec3f_32());
|
2014-10-09 14:54:56 +00:00
|
|
|
std::cout << "*** vtkm::Vec<Float64,3> **********" << std::endl;
|
2019-07-31 16:20:38 +00:00
|
|
|
TryDefaultType(vtkm::Vec3f_64());
|
2014-04-03 19:17:14 +00:00
|
|
|
|
2016-08-24 22:02:18 +00:00
|
|
|
std::cout << "Try exemplar VTK-m types." << std::endl;
|
|
|
|
vtkm::testing::Testing::TryTypes(TryBasicVTKmType());
|
2014-04-03 19:17:14 +00:00
|
|
|
|
|
|
|
std::cout << "Try unusual type." << std::endl;
|
|
|
|
TryUnusualType();
|
|
|
|
|
2015-09-18 04:31:58 +00:00
|
|
|
std::cout << "Try CastToArrayHandle" << std::endl;
|
|
|
|
TryCastToArrayHandle();
|
2014-04-03 19:17:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
2019-01-01 22:19:02 +00:00
|
|
|
int UnitTestVariantArrayHandle(int argc, char* argv[])
|
2014-04-03 19:17:14 +00:00
|
|
|
{
|
2019-01-01 22:19:02 +00:00
|
|
|
return vtkm::cont::testing::Testing::Run(TestVariantArrayHandle, argc, argv);
|
2014-04-03 19:17:14 +00:00
|
|
|
}
|