Merge topic 'arrayhandle-getcomponents'

9b992dcdd Add `GetNumberOfComponentsFlat` method to `ArrayHandle`

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: Li-Ta Lo <ollie@lanl.gov>
Merge-request: !3137
This commit is contained in:
Kenneth Moreland 2023-10-10 12:58:16 +00:00 committed by Kitware Robot
commit cdff776a16
42 changed files with 311 additions and 60 deletions

@ -0,0 +1,20 @@
# Add `GetNumberOfComponentsFlat` method to `ArrayHandle`
Getting the number of components (or the number of flattened components)
from an `ArrayHandle` is usually trivial. However, if the `ArrayHandle` is
special in that the number of components is specified at runtime, then it
becomes much more difficult to determine.
Getting the number of components is most important when extracting
component arrays (or reconstructions using component arrays) with
`UnknownArrayHandle`. Previously, `UnknownArrayHandle` used a hack to get
the number of components, which mostly worked but broke down when wrapping
a runtime array inside another array such as `ArrayHandleView`.
To prevent this issue, the ability to get the number of components has been
added to `ArrayHandle` proper. All `Storage` objects for `ArrayHandle`s now
need a method named `GetNumberOfComponentsFlat`. The implementation of this
method is usually trivial. The `ArrayHandle` template now also provides a
`GetNumberOfComponentsFlat` method that gets this information from the
`Storage`. This provides an easy access point for the `UnknownArrayHandle`
to pull this information.

@ -465,6 +465,12 @@ public:
return StorageType::GetNumberOfValues(this->GetBuffers());
}
/// @copydoc vtkm::cont::UnknownArrayHandle::GetNumberOfComponentsFlat
VTKM_CONT vtkm::IdComponent GetNumberOfComponentsFlat() const
{
return StorageType::GetNumberOfComponentsFlat(this->GetBuffers());
}
///@{
/// \brief Allocates an array large enough to hold the given number of values.
///

@ -18,6 +18,8 @@
#include <vtkm/internal/ArrayPortalBasic.h>
#include <vtkm/VecFlat.h>
#include <limits>
namespace vtkm
@ -49,6 +51,12 @@ public:
vtkm::internal::NumberOfValuesToNumberOfBytes<T>(numValues), preserve, token);
}
VTKM_CONT static vtkm::IdComponent GetNumberOfComponentsFlat(
const std::vector<vtkm::cont::internal::Buffer>&)
{
return vtkm::VecFlat<T>::NUM_COMPONENTS;
}
VTKM_CONT static vtkm::Id GetNumberOfValues(
const std::vector<vtkm::cont::internal::Buffer>& buffers)
{

@ -105,6 +105,12 @@ public:
buffers[0].GetMetaData<vtkm::cont::internal::BitFieldMetaData>().NumberOfBits = numberOfBits;
}
VTKM_CONT static vtkm::IdComponent GetNumberOfComponentsFlat(
const std::vector<vtkm::cont::internal::Buffer>&)
{
return 1;
}
VTKM_CONT static vtkm::Id GetNumberOfValues(
const std::vector<vtkm::cont::internal::Buffer>& buffers)
{

@ -240,6 +240,12 @@ public:
typename Storage2::WritePortalType,
typename Storage3::WritePortalType>;
VTKM_CONT static vtkm::IdComponent GetNumberOfComponentsFlat(
const std::vector<vtkm::cont::internal::Buffer>&)
{
return vtkm::VecFlat<T>::NUM_COMPONENTS * 3;
}
VTKM_CONT static vtkm::Id GetNumberOfValues(
const std::vector<vtkm::cont::internal::Buffer>& buffers)
{

@ -289,6 +289,15 @@ private:
}
public:
VTKM_CONT static vtkm::IdComponent GetNumberOfComponentsFlat(
const std::vector<vtkm::cont::internal::Buffer>& buffers)
{
// Assume that all subcomponents are the same size. Things are not well defined otherwise.
return vtkm::tuple_element_t<0, StorageTuple>::GetNumberOfComponentsFlat(
GetBuffers(buffers, 0)) *
ValueType::NUM_COMPONENTS;
}
VTKM_CONT static vtkm::Id GetNumberOfValues(
const std::vector<vtkm::cont::internal::Buffer>& buffers)
{

@ -157,6 +157,22 @@ public:
vtkm::internal::ArrayPortalConcatenate<typename SourceStorage1::WritePortalType,
typename SourceStorage2::WritePortalType>;
VTKM_CONT static vtkm::IdComponent GetNumberOfComponentsFlat(
const std::vector<vtkm::cont::internal::Buffer>& buffers)
{
vtkm::IdComponent components1 = SourceStorage1::GetNumberOfComponentsFlat(Buffers1(buffers));
vtkm::IdComponent components2 = SourceStorage2::GetNumberOfComponentsFlat(Buffers2(buffers));
if (components1 == components2)
{
return components1;
}
else
{
// Inconsistent component size.
return 0;
}
}
VTKM_CONT static vtkm::Id GetNumberOfValues(
const std::vector<vtkm::cont::internal::Buffer>& buffers)
{

@ -506,6 +506,25 @@ public:
using ReadPortalType = typename Traits::ReadPortalType;
using WritePortalType = typename Traits::WritePortalType;
private:
VTKM_CONT static vtkm::IdComponent GetNumberOfComponentsFlatImpl(vtkm::VecTraitsTagSizeStatic)
{
return vtkm::VecFlat<DecoratorImplT>::NUM_COMPONENTS;
}
VTKM_CONT static vtkm::IdComponent GetNumberOfComponentsFlatImpl(vtkm::VecTraitsTagSizeVariable)
{
// Currently only support getting the number of components for statically sized types.
return 0;
}
public:
VTKM_CONT static vtkm::IdComponent GetNumberOfComponentsFlat(
const std::vector<vtkm::cont::internal::Buffer>&)
{
return GetNumberOfComponentsFlatImpl(typename vtkm::VecTraits<DecoratorImplT>::IsSizeStatic{});
}
VTKM_CONT static vtkm::Id GetNumberOfValues(
const std::vector<vtkm::cont::internal::Buffer>& buffers)
{

@ -119,6 +119,12 @@ public:
buffers[0].GetMetaData<DiscardMetaData>().NumberOfValues = numValues;
}
VTKM_CONT static vtkm::IdComponent GetNumberOfComponentsFlat(
const std::vector<vtkm::cont::internal::Buffer>&)
{
return vtkm::VecFlat<ValueType>::NUM_COMPONENTS;
}
VTKM_CONT static vtkm::Id GetNumberOfValues(
const std::vector<vtkm::cont::internal::Buffer>& buffers)
{

@ -114,6 +114,12 @@ public:
using WritePortalType =
vtkm::internal::ArrayPortalExtractComponent<typename SourceStorage::WritePortalType>;
VTKM_CONT static vtkm::IdComponent GetNumberOfComponentsFlat(
const std::vector<vtkm::cont::internal::Buffer>&)
{
return vtkm::VecFlat<ValueType>::NUM_COMPONENTS;
}
VTKM_CONT static vtkm::Id GetNumberOfValues(
const std::vector<vtkm::cont::internal::Buffer>& buffers)
{

@ -141,6 +141,12 @@ public:
ComponentsStorage::ResizeBuffers(NUM_COMPONENTS * numValues, buffers, preserve, token);
}
VTKM_CONT static vtkm::IdComponent GetNumberOfComponentsFlat(
const std::vector<vtkm::cont::internal::Buffer>& buffers)
{
return ComponentsStorage::GetNumberOfComponentsFlat(buffers) * NUM_COMPONENTS;
}
VTKM_CONT static vtkm::Id GetNumberOfValues(
const std::vector<vtkm::cont::internal::Buffer>& buffers)
{

@ -167,6 +167,13 @@ public:
vtkm::internal::ArrayPortalGroupVecVariable<typename ComponentsStorage::WritePortalType,
typename OffsetsStorage::ReadPortalType>;
VTKM_CONT static vtkm::IdComponent GetNumberOfComponentsFlat(
const std::vector<vtkm::cont::internal::Buffer>&)
{
// Number of components can be variable.
return 0;
}
VTKM_CONT static vtkm::Id GetNumberOfValues(
const std::vector<vtkm::cont::internal::Buffer>& buffers)
{

@ -129,6 +129,12 @@ struct VTKM_ALWAYS_EXPORT
return vtkm::cont::internal::PortalToArrayHandleImplicitBuffers(ArrayPortalType{});
}
VTKM_CONT static vtkm::IdComponent GetNumberOfComponentsFlat(
const std::vector<vtkm::cont::internal::Buffer>&)
{
return vtkm::VecFlat<typename ArrayPortalType::ValueType>::NUM_COMPONENTS;
}
VTKM_CONT static vtkm::Id GetNumberOfValues(
const std::vector<vtkm::cont::internal::Buffer>& buffers)
{

@ -148,6 +148,17 @@ namespace internal
namespace detail
{
struct MultiplexerGetNumberOfComponentsFlatFunctor
{
template <typename StorageType>
VTKM_CONT vtkm::IdComponent operator()(
StorageType,
const std::vector<vtkm::cont::internal::Buffer>& buffers) const
{
return StorageType::GetNumberOfComponentsFlat(buffers);
}
};
struct MultiplexerGetNumberOfValuesFunctor
{
template <typename StorageType>
@ -251,6 +262,13 @@ public:
using WritePortalType =
vtkm::internal::ArrayPortalMultiplexer<typename StorageFor<StorageTags>::WritePortalType...>;
VTKM_CONT static vtkm::IdComponent GetNumberOfComponentsFlat(
const std::vector<vtkm::cont::internal::Buffer>& buffers)
{
return Variant(buffers).CastAndCall(detail::MultiplexerGetNumberOfComponentsFlatFunctor{},
ArrayBuffers(buffers));
}
VTKM_CONT static vtkm::Id GetNumberOfValues(
const std::vector<vtkm::cont::internal::Buffer>& buffers)
{

@ -76,6 +76,12 @@ public:
return OffsetsStorage::CreateBuffers();
}
VTKM_CONT static vtkm::IdComponent GetNumberOfComponentsFlat(
const std::vector<vtkm::cont::internal::Buffer>&)
{
return 1;
}
VTKM_CONT static vtkm::Id GetNumberOfValues(
const std::vector<vtkm::cont::internal::Buffer>& buffers)
{

@ -142,6 +142,12 @@ public:
vtkm::internal::ArrayPortalPermutation<typename IndexStorage::ReadPortalType,
typename ValueStorage::WritePortalType>;
VTKM_CONT static vtkm::IdComponent GetNumberOfComponentsFlat(
const std::vector<vtkm::cont::internal::Buffer>& buffers)
{
return ValueStorage::GetNumberOfComponentsFlat(ValueBuffers(buffers));
}
VTKM_CONT static vtkm::Id GetNumberOfValues(
const std::vector<vtkm::cont::internal::Buffer>& buffers)
{

@ -445,6 +445,15 @@ public:
buffers[0].GetMetaData<detail::RecombineVecMetaData>().ArrayBufferOffsets.size() - 1);
}
VTKM_CONT static vtkm::IdComponent GetNumberOfComponentsFlat(
const std::vector<vtkm::cont::internal::Buffer>& buffers)
{
vtkm::IdComponent numComponents = GetNumberOfComponents(buffers);
vtkm::IdComponent numSubComponents =
SourceStorage::GetNumberOfComponentsFlat(BuffersForComponent(buffers, 0));
return numComponents * numSubComponents;
}
VTKM_CONT static vtkm::Id GetNumberOfValues(
const std::vector<vtkm::cont::internal::Buffer>& buffers)
{

@ -102,6 +102,12 @@ public:
SourceStorage::ResizeBuffers(numValues, buffers, preserve, token);
}
VTKM_CONT static vtkm::IdComponent GetNumberOfComponentsFlat(
const std::vector<vtkm::cont::internal::Buffer>& buffers)
{
return SourceStorage::GetNumberOfComponentsFlat(buffers);
}
VTKM_CONT static vtkm::Id GetNumberOfValues(
const std::vector<vtkm::cont::internal::Buffer>& buffers)
{

@ -177,6 +177,15 @@ public:
return buffers[0].GetMetaData<Info>().NumberOfComponents;
}
VTKM_CONT static vtkm::IdComponent GetNumberOfComponentsFlat(
const std::vector<vtkm::cont::internal::Buffer>& buffers)
{
vtkm::IdComponent numComponents = GetNumberOfComponents(buffers);
vtkm::IdComponent numSubComponents =
ComponentsStorage::GetNumberOfComponentsFlat(ComponentsBuffers(buffers));
return numComponents * numSubComponents;
}
VTKM_CONT static vtkm::Id GetNumberOfValues(
const std::vector<vtkm::cont::internal::Buffer>& buffers)
{

@ -144,6 +144,12 @@ public:
return std::vector<vtkm::cont::internal::Buffer>(static_cast<std::size_t>(NUM_COMPONENTS));
}
VTKM_CONT static vtkm::IdComponent GetNumberOfComponentsFlat(
const std::vector<vtkm::cont::internal::Buffer>&)
{
return vtkm::VecFlat<ComponentType>::NUM_COMPONENTS * NUM_COMPONENTS;
}
VTKM_CONT static void ResizeBuffers(vtkm::Id numValues,
const std::vector<vtkm::cont::internal::Buffer>& buffers,
vtkm::CopyFlag preserve,

@ -166,6 +166,12 @@ public:
return buffers[0].GetMetaData<StrideInfo>();
}
VTKM_CONT static vtkm::IdComponent GetNumberOfComponentsFlat(
const std::vector<vtkm::cont::internal::Buffer>&)
{
return vtkm::VecFlat<T>::NUM_COMPONENTS;
}
VTKM_CONT static vtkm::Id GetNumberOfValues(
const std::vector<vtkm::cont::internal::Buffer>& buffers)
{

@ -263,6 +263,12 @@ public:
typename ArrayHandleType::ReadPortalType,
typename FunctorManager::FunctorType>;
VTKM_CONT static vtkm::IdComponent GetNumberOfComponentsFlat(
const std::vector<vtkm::cont::internal::Buffer>&)
{
return vtkm::VecFlat<ValueType>::NUM_COMPONENTS;
}
VTKM_CONT static vtkm::Id GetNumberOfValues(
const std::vector<vtkm::cont::internal::Buffer>& buffers)
{
@ -342,6 +348,12 @@ public:
typename FunctorManager::FunctorType,
typename InverseFunctorManager::FunctorType>;
VTKM_CONT static vtkm::IdComponent GetNumberOfComponentsFlat(
const std::vector<vtkm::cont::internal::Buffer>&)
{
return vtkm::VecFlat<ValueType>::NUM_COMPONENTS;
}
VTKM_CONT static vtkm::Id GetNumberOfValues(
const std::vector<vtkm::cont::internal::Buffer>& buffers)
{

@ -119,6 +119,12 @@ public:
using WritePortalType =
vtkm::internal::ArrayPortalView<typename ArrayHandleType::WritePortalType>;
VTKM_CONT static vtkm::IdComponent GetNumberOfComponentsFlat(
const std::vector<vtkm::cont::internal::Buffer>& buffers)
{
return SourceStorage::GetNumberOfComponentsFlat(SourceBuffers(buffers));
}
VTKM_CONT static vtkm::Id GetNumberOfValues(
const std::vector<vtkm::cont::internal::Buffer>& buffers)
{

@ -186,6 +186,12 @@ public:
using ReadPortalType =
vtkm::internal::ArrayPortalXGCCoordinates<typename SourceStorage::ReadPortalType>;
VTKM_CONT static vtkm::IdComponent GetNumberOfComponentsFlat(
const std::vector<vtkm::cont::internal::Buffer>&)
{
return 3;
}
VTKM_CONT static vtkm::Id GetNumberOfValues(
const std::vector<vtkm::cont::internal::Buffer>& buffers)
{

@ -181,6 +181,12 @@ public:
return vtkm::cont::internal::CreateBuffers(info, firstArray, secondArray);
}
VTKM_CONT static vtkm::IdComponent GetNumberOfComponentsFlat(
const std::vector<vtkm::cont::internal::Buffer>&)
{
return 1;
}
VTKM_CONT static void ResizeBuffers(vtkm::Id numValues,
const std::vector<vtkm::cont::internal::Buffer>& buffers,
vtkm::CopyFlag preserve,

@ -23,6 +23,7 @@
#include <vtkm/Deprecated.h>
#include <vtkm/TypeList.h>
#include <vtkm/VecTraits.h>
#include <memory>
#include <typeindex>
@ -65,6 +66,14 @@ vtkm::Id UnknownAHNumberOfValues(void* mem)
return arrayHandle->GetNumberOfValues();
}
template <typename T, typename S>
vtkm::IdComponent UnknownAHNumberOfComponentsFlat(void* mem)
{
using AH = vtkm::cont::ArrayHandle<T, S>;
AH* arrayHandle = reinterpret_cast<AH*>(mem);
return arrayHandle->GetNumberOfComponentsFlat();
}
// Uses SFINAE to use Storage<>::GetNumberOfComponents if it exists, or the VecTraits otherwise
template <typename T, typename S>
inline auto UnknownAHNumberOfComponentsImpl(void* mem)
@ -76,75 +85,25 @@ inline auto UnknownAHNumberOfComponentsImpl(void* mem)
return vtkm::cont::internal::Storage<T, S>::GetNumberOfComponents(arrayHandle->GetBuffers());
}
// Uses SFINAE to use the number of compnents in VecTraits.
// Note that this will conflict with the above overloaded function if the storage has a
// GetNumberOfComponents method and VecTraits has a static size. However, I cannot think
// of a use case for the storage to report the number of components for a static data type.
// If that happens, this implementation will need to be modified.
// Uses static vec size.
template <typename T, typename S>
inline auto UnknownAHNumberOfComponentsImpl(void*) -> decltype(vtkm::VecTraits<T>::NUM_COMPONENTS)
inline vtkm::IdComponent UnknownAHNumberOfComponentsImpl(void*, vtkm::VecTraitsTagSizeStatic)
{
static constexpr vtkm::IdComponent numComponents = vtkm::VecTraits<T>::NUM_COMPONENTS;
return numComponents;
return vtkm::VecTraits<T>::NUM_COMPONENTS;
}
// Fallback for when there is no way to determine the number of components. (This could be
// because each value could have a different number of components.
// The size of the vecs are not defined at compile time. Assume that the components are not
// nested and use the flat components query.
template <typename T, typename S>
inline vtkm::IdComponent UnknownAHNumberOfComponentsImpl(...)
inline vtkm::IdComponent UnknownAHNumberOfComponentsImpl(void* mem, vtkm::VecTraitsTagSizeVariable)
{
return 0;
return UnknownAHNumberOfComponentsFlat<T, S>(mem);
}
template <typename T, typename S>
vtkm::IdComponent UnknownAHNumberOfComponents(void* mem)
{
return UnknownAHNumberOfComponentsImpl<T, S>(mem);
}
// Uses SFINAE to use Storage<>::GetNumberOfComponents if it exists, or the VecTraits otherwise
template <typename T, typename S>
inline auto UnknownAHNumberOfComponentsFlatImpl(void* mem)
-> decltype(vtkm::cont::internal::Storage<T, S>::GetNumberOfComponents(
std::vector<vtkm::cont::internal::Buffer>()))
{
using AH = vtkm::cont::ArrayHandle<T, S>;
AH* arrayHandle = reinterpret_cast<AH*>(mem);
// Making an assumption here that `T` is a `Vec`-like object that `GetNumberOfComponents`
// will report on how many each has. Further assuming that the components of `T` are
// static. If a future `ArrayHandle` type violates this, this code will have to become
// more complex.
return (vtkm::cont::internal::Storage<T, S>::GetNumberOfComponents(arrayHandle->GetBuffers()) *
vtkm::VecFlat<typename vtkm::VecTraits<T>::ComponentType>::NUM_COMPONENTS);
}
// Uses SFINAE to use the number of compnents in VecTraits.
// Note that this will conflict with the above overloaded function if the storage has a
// GetNumberOfComponents method and VecTraits has a static size. However, I cannot think
// of a use case for the storage to report the number of components for a static data type.
// If that happens, this implementation will need to be modified.
template <typename T, typename S>
inline auto UnknownAHNumberOfComponentsFlatImpl(void*)
-> decltype(vtkm::VecTraits<T>::NUM_COMPONENTS)
{
// static constexpr vtkm::IdComponent numComponents = vtkm::VecFlat<T>::NUM_COMPONENTS;
// return numComponents;
return vtkm::VecFlat<T>::NUM_COMPONENTS;
}
// Fallback for when there is no way to determine the number of components. (This could be
// because each value could have a different number of components or just that VecTraits
// are not defined.) Since it cannot be flattened, just return the same as num components.
template <typename T, typename S>
inline vtkm::IdComponent UnknownAHNumberOfComponentsFlatImpl(...)
{
return UnknownAHNumberOfComponentsImpl<T, S>(static_cast<void*>(nullptr));
}
template <typename T, typename S>
vtkm::IdComponent UnknownAHNumberOfComponentsFlat(void* mem)
{
return UnknownAHNumberOfComponentsFlatImpl<T, S>(mem);
return UnknownAHNumberOfComponentsImpl<T, S>(mem, typename vtkm::VecTraits<T>::IsSizeStatic{});
}
template <typename T, typename S>
@ -621,8 +580,12 @@ public:
/// of components (in this case 3).
/// If the array holds a hierarchy of `Vec`s (such as `vtkm::Vec<vtkm::Vec3f, 2>`), this will
/// return the total number of vecs (in this case 6).
/// If the array holds `Vec`-like objects that have the number of components that can vary
/// at runtime, this method will return 0 (because there is no consistent answer).
///
/// If this object is holding an array where the number of components can be selected at
/// runtime (for example, `vtkm::cont::ArrayHandleRuntimeVec`), this method will still return
/// the correct number of components. However, if each value in the array can be a `Vec` of
/// a different size (such as `vtkm::cont::ArrayHandleGroupVecVariable`),
/// this method will return 0 (because there is no consistent answer).
///
VTKM_CONT vtkm::IdComponent GetNumberOfComponentsFlat() const;

@ -15,6 +15,8 @@
#include <vtkm/cont/ArrayHandleCounting.h>
#include <vtkm/cont/ArrayHandleIndex.h>
#include <vtkm/cont/ArrayHandlePermutation.h>
#include <vtkm/cont/ArrayHandleReverse.h>
#include <vtkm/cont/ArrayHandleRuntimeVec.h>
#include <vtkm/cont/ArrayHandleView.h>
#include <vtkm/cont/UncertainArrayHandle.h>
#include <vtkm/cont/UnknownArrayHandle.h>
@ -217,6 +219,41 @@ void TryCopy()
TestValues(input, output);
}
{
std::cout << "runtime vec size -> runtime vec size" << std::endl;
using ComponentType = typename VTraits::BaseComponentType;
vtkm::cont::ArrayHandle<ValueType> staticVecArray = MakeInputArray<ValueType>();
vtkm::cont::ArrayHandleRuntimeVec<ComponentType> input =
vtkm::cont::make_ArrayHandleRuntimeVec(staticVecArray);
vtkm::cont::ArrayHandleRuntimeVec<ComponentType> output(input.GetNumberOfComponents());
vtkm::cont::ArrayCopy(input, output);
// Convert the arrays back to static vec sizes for comparison, because TestValues
// uses a device array copy that may not work on runtime vec sizes.
TestValues(staticVecArray,
output.template AsArrayHandleBasic<vtkm::cont::ArrayHandle<ValueType>>());
}
{
std::cout << "runtime vec size reverse -> runtime vec size view" << std::endl;
using ComponentType = typename VTraits::BaseComponentType;
vtkm::cont::ArrayHandle<ValueType> staticVecArray = MakeInputArray<ValueType>();
vtkm::cont::ArrayHandleRuntimeVec<ComponentType> inputRuntimeVec =
vtkm::cont::make_ArrayHandleRuntimeVec(staticVecArray);
auto input = vtkm::cont::make_ArrayHandleReverse(inputRuntimeVec);
vtkm::cont::ArrayHandleRuntimeVec<ComponentType> outputBase(
inputRuntimeVec.GetNumberOfComponents());
outputBase.Allocate(ARRAY_SIZE * 2);
auto output = vtkm::cont::make_ArrayHandleView(outputBase, 2, ARRAY_SIZE);
vtkm::cont::ArrayCopy(input, output);
// Convert the arrays back to static vec sizes for comparison, because TestValues
// uses a device array copy that may not work on runtime vec sizes.
TestValues(vtkm::cont::make_ArrayHandleReverse(staticVecArray),
vtkm::cont::make_ArrayHandleView(
outputBase.template AsArrayHandleBasic<vtkm::cont::ArrayHandle<ValueType>>(),
2,
ARRAY_SIZE));
}
// Test the copy methods in UnknownArrayHandle. Although this would be appropriate in
// UnitTestUnknownArrayHandle, it is easier to test copies here.
{

@ -219,6 +219,7 @@ struct VerifyUserTransferredMemory
VTKM_TEST_ASSERT(arrayHandle.GetNumberOfValues() == ARRAY_SIZE,
"ArrayHandle has wrong number of entries.");
VTKM_TEST_ASSERT(arrayHandle.GetNumberOfComponentsFlat() == vtkm::VecFlat<T>::NUM_COMPONENTS);
std::cout << "Check array with user transferred memory." << std::endl;
CheckArray(arrayHandle);

@ -39,6 +39,7 @@ 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");
VTKM_TEST_ASSERT(cpArray.GetNumberOfComponentsFlat() == 3);
//Make sure the values are correct.
vtkm::Vec<T, 3> val;

@ -124,6 +124,7 @@ void TestConcatOfConcat()
vtkm::cont::printSummary_ArrayHandle(array5, std::cout, true);
VTKM_TEST_ASSERT(array5.GetNumberOfValues() == 4 * ARRAY_SIZE);
VTKM_TEST_ASSERT(array5.GetNumberOfComponentsFlat() == 1);
// Check the values in array5. If array5 is correct, all the `ArrayHandleConcatinate`s
// (such as in array3) must be working.
@ -163,6 +164,7 @@ void TestConcatenateEmptyArray()
vtkm::cont::printSummary_ArrayHandle(arrConc2, std::cout, true);
VTKM_TEST_ASSERT(arrConc2.GetNumberOfValues() == ARRAY_SIZE);
VTKM_TEST_ASSERT(arrConc2.GetNumberOfComponentsFlat() == 1);
}
void TestConcatenateFill()

@ -46,6 +46,9 @@ struct TestConstantAsInput
vtkm::cont::make_ArrayHandleConstant(value, ARRAY_SIZE);
VTKM_TEST_ASSERT(constant.GetValue() == value);
VTKM_TEST_ASSERT(constant.GetNumberOfValues() == ARRAY_SIZE);
VTKM_TEST_ASSERT(constant.GetNumberOfComponentsFlat() ==
vtkm::VecFlat<ValueType>::NUM_COMPONENTS);
vtkm::cont::ArrayHandle<ValueType> result;

@ -320,6 +320,8 @@ struct DecoratorTests
{
auto portalDecor = ahDecor.ReadPortal();
VTKM_TEST_ASSERT(ahDecor.GetNumberOfValues() == ARRAY_SIZE);
VTKM_TEST_ASSERT(ahDecor.GetNumberOfComponentsFlat() ==
vtkm::VecFlat<ValueType>::NUM_COMPONENTS);
VTKM_TEST_ASSERT(portalDecor.GetNumberOfValues() == ARRAY_SIZE);
VTKM_TEST_ASSERT(portalDecor.Get(0) == ValueType{ 23 });
VTKM_TEST_ASSERT(portalDecor.Get(1) == ValueType{ 21 });
@ -340,6 +342,8 @@ struct DecoratorTests
{ // Accessing portal should give all 25s:
auto portalDecor = ahDecor.ReadPortal();
VTKM_TEST_ASSERT(ahDecor.GetNumberOfValues() == ARRAY_SIZE);
VTKM_TEST_ASSERT(ahDecor.GetNumberOfComponentsFlat() ==
vtkm::VecFlat<ValueType>::NUM_COMPONENTS);
VTKM_TEST_ASSERT(portalDecor.GetNumberOfValues() == ARRAY_SIZE);
VTKM_TEST_ASSERT(portalDecor.Get(0) == ValueType{ 25 });
VTKM_TEST_ASSERT(portalDecor.Get(1) == ValueType{ 25 });
@ -356,6 +360,8 @@ struct DecoratorTests
{ // ah3Copy should have updated values:
auto portalAH3Copy = ah3Copy.ReadPortal();
VTKM_TEST_ASSERT(ahDecor.GetNumberOfValues() == ARRAY_SIZE);
VTKM_TEST_ASSERT(ahDecor.GetNumberOfComponentsFlat() ==
vtkm::VecFlat<ValueType>::NUM_COMPONENTS);
VTKM_TEST_ASSERT(portalAH3Copy.GetNumberOfValues() == ARRAY_SIZE);
VTKM_TEST_ASSERT(portalAH3Copy.Get(0) == ValueType{ 15 });
VTKM_TEST_ASSERT(portalAH3Copy.Get(1) == ValueType{ 15 });

@ -49,6 +49,8 @@ struct TestGroupVecAsInput
groupArray(baseArray);
VTKM_TEST_ASSERT(groupArray.GetNumberOfValues() == ARRAY_SIZE,
"Group array reporting wrong array size.");
VTKM_TEST_ASSERT(groupArray.GetNumberOfComponentsFlat() ==
vtkm::VecFlat<ComponentType>::NUM_COMPONENTS * NUM_COMPONENTS);
vtkm::cont::ArrayHandle<ValueType> resultArray;

@ -76,6 +76,10 @@ struct TestGroupVecVariableAsInput
auto groupVecArray = vtkm::cont::make_ArrayHandleGroupVecVariable(sourceArray, offsetsArray);
VTKM_TEST_ASSERT(groupVecArray.GetNumberOfValues() == ARRAY_SIZE);
// Num components is inconsistent, so you should just get 0.
VTKM_TEST_ASSERT(groupVecArray.GetNumberOfComponentsFlat() == 0);
invoke(GroupVariableInputWorklet{}, groupVecArray, dummyArray);
dummyArray.ReadPortal();

@ -21,6 +21,7 @@ void TestArrayHandleIndex()
{
vtkm::cont::ArrayHandleIndex array(ARRAY_SIZE);
VTKM_TEST_ASSERT(array.GetNumberOfValues() == ARRAY_SIZE, "Bad size.");
VTKM_TEST_ASSERT(array.GetNumberOfComponentsFlat() == 1);
auto portal = array.ReadPortal();
for (vtkm::Id index = 0; index < ARRAY_SIZE; index++)
{

@ -135,6 +135,8 @@ void Fill()
MultiplexerType multiplexer = vtkm::cont::ArrayHandle<ValueType>{};
multiplexer.AllocateAndFill(ARRAY_SIZE, testValue1);
VTKM_TEST_ASSERT(multiplexer.GetNumberOfComponentsFlat() ==
vtkm::VecFlat<ValueType>::NUM_COMPONENTS);
{
auto portal = multiplexer.ReadPortal();
VTKM_TEST_ASSERT(portal.GetNumberOfValues() == ARRAY_SIZE);

@ -161,6 +161,8 @@ struct PermutationTests
"Permutation portal wrong size.");
VTKM_TEST_ASSERT(permutationArray.ReadPortal().GetNumberOfValues() == ARRAY_SIZE,
"Permutation portal wrong size.");
VTKM_TEST_ASSERT(permutationArray.GetNumberOfComponentsFlat() ==
vtkm::VecFlat<ValueType>::NUM_COMPONENTS);
vtkm::cont::Invoker invoke;

@ -50,6 +50,8 @@ struct TestRecombineVecAsInput
recombinedArray.AppendComponentArray(vtkm::cont::ArrayExtractComponent(baseArray, cIndex));
}
VTKM_TEST_ASSERT(recombinedArray.GetNumberOfComponents() == VTraits::NUM_COMPONENTS);
VTKM_TEST_ASSERT(recombinedArray.GetNumberOfComponentsFlat() ==
vtkm::VecFlat<T>::NUM_COMPONENTS);
VTKM_TEST_ASSERT(recombinedArray.GetNumberOfValues() == ARRAY_SIZE);
vtkm::cont::ArrayHandle<T> outputArray;

@ -23,6 +23,7 @@ void TestArrayHandleReverseRead()
{
vtkm::cont::ArrayHandleIndex array(ARRAY_SIZE);
VTKM_TEST_ASSERT(array.GetNumberOfValues() == ARRAY_SIZE, "Bad size.");
VTKM_TEST_ASSERT(array.GetNumberOfComponentsFlat() == 1);
auto portal = array.ReadPortal();
for (vtkm::Id index = 0; index < ARRAY_SIZE; index++)

@ -129,6 +129,8 @@ struct TestRuntimeVecAsInput
auto runtimeVecArray = vtkm::cont::make_ArrayHandleRuntimeVec(NUM_COMPONENTS, baseArray);
VTKM_TEST_ASSERT(runtimeVecArray.GetNumberOfValues() == ARRAY_SIZE,
"Group array reporting wrong array size.");
VTKM_TEST_ASSERT(runtimeVecArray.GetNumberOfComponentsFlat() ==
NUM_COMPONENTS * vtkm::VecFlat<ComponentType>::NUM_COMPONENTS);
vtkm::cont::ArrayHandle<ValueType> resultArray;

@ -122,6 +122,8 @@ struct TestSOAAsInput
soaArray.SetArray(componentIndex, componentArray);
}
VTKM_TEST_ASSERT(soaArray.GetNumberOfComponentsFlat() ==
vtkm::VecFlat<ValueType>::NUM_COMPONENTS);
VTKM_TEST_ASSERT(soaArray.GetNumberOfValues() == ARRAY_SIZE);
VTKM_TEST_ASSERT(soaArray.ReadPortal().GetNumberOfValues() == ARRAY_SIZE);
CheckPortal(soaArray.ReadPortal());

@ -63,6 +63,9 @@ struct TestViewAsInput
ViewHandleType view =
vtkm::cont::make_ArrayHandleView(implicit, start_pos, counting_ARRAY_SIZE);
VTKM_TEST_ASSERT(view.GetNumberOfComponentsFlat() ==
vtkm::VecFlat<ValueType>::NUM_COMPONENTS);
VTKM_TEST_ASSERT(view.GetNumberOfValues() == counting_ARRAY_SIZE);
vtkm::cont::ArrayHandle<ValueType> result;