mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-16 17:22:55 +00:00
Simplify ArrayHandleImplicit template
This commit is contained in:
parent
6ce2a43d41
commit
c4e3102084
@ -59,12 +59,12 @@ private:
|
||||
/// takes (almost) no memory.
|
||||
///
|
||||
template <typename T>
|
||||
class ArrayHandleConstant : public vtkm::cont::ArrayHandleImplicit<T, detail::ConstantFunctor<T>>
|
||||
class ArrayHandleConstant : public vtkm::cont::ArrayHandleImplicit<detail::ConstantFunctor<T>>
|
||||
{
|
||||
public:
|
||||
VTKM_ARRAY_HANDLE_SUBCLASS(ArrayHandleConstant,
|
||||
(ArrayHandleConstant<T>),
|
||||
(vtkm::cont::ArrayHandleImplicit<T, detail::ConstantFunctor<T>>));
|
||||
(vtkm::cont::ArrayHandleImplicit<detail::ConstantFunctor<T>>));
|
||||
|
||||
VTKM_CONT
|
||||
ArrayHandleConstant(T value, vtkm::Id numberOfValues = 0)
|
||||
|
@ -32,6 +32,20 @@ namespace cont
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template <class FunctorType_>
|
||||
class VTKM_ALWAYS_EXPORT ArrayPortalImplicit;
|
||||
|
||||
/// A convenience class that provides a typedef to the appropriate tag for
|
||||
/// a implicit array container.
|
||||
template <typename FunctorType>
|
||||
struct ArrayHandleImplicitTraits
|
||||
{
|
||||
using ValueType = decltype(FunctorType{}(vtkm::Id{}));
|
||||
using StorageTag = vtkm::cont::StorageTagImplicit<ArrayPortalImplicit<FunctorType>>;
|
||||
using Superclass = vtkm::cont::ArrayHandle<ValueType, StorageTag>;
|
||||
};
|
||||
|
||||
/// \brief An array portal that returns the result of a functor
|
||||
///
|
||||
/// This array portal is similar to an implicit array i.e an array that is
|
||||
@ -41,12 +55,12 @@ namespace detail
|
||||
/// The \c ArrayPortalImplicit is used in an ArrayHandle with an
|
||||
/// \c StorageImplicit container.
|
||||
///
|
||||
template <class ValueType_, class FunctorType_>
|
||||
template <class FunctorType_>
|
||||
class VTKM_ALWAYS_EXPORT ArrayPortalImplicit
|
||||
{
|
||||
public:
|
||||
typedef ValueType_ ValueType;
|
||||
typedef FunctorType_ FunctorType;
|
||||
using ValueType = typename ArrayHandleImplicitTraits<FunctorType_>::ValueType;
|
||||
using FunctorType = FunctorType_;
|
||||
|
||||
VTKM_EXEC_CONT
|
||||
ArrayPortalImplicit()
|
||||
@ -77,7 +91,7 @@ public:
|
||||
#endif
|
||||
}
|
||||
|
||||
typedef vtkm::cont::internal::IteratorFromArrayPortal<ArrayPortalImplicit<ValueType, FunctorType>>
|
||||
typedef vtkm::cont::internal::IteratorFromArrayPortal<ArrayPortalImplicit<FunctorType>>
|
||||
IteratorType;
|
||||
|
||||
VTKM_CONT
|
||||
@ -88,17 +102,6 @@ private:
|
||||
vtkm::Id NumberOfValues;
|
||||
};
|
||||
|
||||
/// A convenience class that provides a typedef to the appropriate tag for
|
||||
/// a implicit array container.
|
||||
template <typename ValueType, typename FunctorType>
|
||||
struct ArrayHandleImplicitTraits
|
||||
{
|
||||
typedef vtkm::cont::StorageTagImplicit<
|
||||
vtkm::cont::detail::ArrayPortalImplicit<ValueType, FunctorType>>
|
||||
StorageTag;
|
||||
typedef vtkm::cont::ArrayHandle<ValueType, StorageTag> Superclass;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
/// \brief An \c ArrayHandle that computes values on the fly.
|
||||
@ -108,15 +111,15 @@ struct ArrayHandleImplicitTraits
|
||||
/// The functor returns the result of the functor as the value of this
|
||||
/// array at that position.
|
||||
///
|
||||
template <typename T, class FunctorType>
|
||||
class ArrayHandleImplicit : public detail::ArrayHandleImplicitTraits<T, FunctorType>::Superclass
|
||||
template <class FunctorType>
|
||||
class ArrayHandleImplicit : public detail::ArrayHandleImplicitTraits<FunctorType>::Superclass
|
||||
{
|
||||
private:
|
||||
typedef typename detail::ArrayHandleImplicitTraits<T, FunctorType> ArrayTraits;
|
||||
typedef typename detail::ArrayHandleImplicitTraits<FunctorType> ArrayTraits;
|
||||
|
||||
public:
|
||||
VTKM_ARRAY_HANDLE_SUBCLASS(ArrayHandleImplicit,
|
||||
(ArrayHandleImplicit<T, FunctorType>),
|
||||
(ArrayHandleImplicit<FunctorType>),
|
||||
(typename ArrayTraits::Superclass));
|
||||
|
||||
VTKM_CONT
|
||||
@ -130,12 +133,11 @@ public:
|
||||
/// ArrayHandleImplicit. It takes a functor and the virtual length of the
|
||||
/// arry.
|
||||
|
||||
template <typename T, typename FunctorType>
|
||||
VTKM_CONT vtkm::cont::ArrayHandleImplicit<T, FunctorType> make_ArrayHandleImplicit(
|
||||
FunctorType functor,
|
||||
vtkm::Id length)
|
||||
template <typename FunctorType>
|
||||
VTKM_CONT vtkm::cont::ArrayHandleImplicit<FunctorType> make_ArrayHandleImplicit(FunctorType functor,
|
||||
vtkm::Id length)
|
||||
{
|
||||
return ArrayHandleImplicit<T, FunctorType>(functor, length);
|
||||
return ArrayHandleImplicit<FunctorType>(functor, length);
|
||||
}
|
||||
}
|
||||
} // namespace vtkm::cont
|
||||
|
@ -46,11 +46,11 @@ struct VTKM_ALWAYS_EXPORT IndexFunctor
|
||||
/// 0, 1, 2, 3,... to a specified size. Every value in the array is the same
|
||||
/// as the index to that value.
|
||||
///
|
||||
class ArrayHandleIndex : public vtkm::cont::ArrayHandleImplicit<vtkm::Id, detail::IndexFunctor>
|
||||
class ArrayHandleIndex : public vtkm::cont::ArrayHandleImplicit<detail::IndexFunctor>
|
||||
{
|
||||
public:
|
||||
VTKM_ARRAY_HANDLE_SUBCLASS_NT(ArrayHandleIndex,
|
||||
(vtkm::cont::ArrayHandleImplicit<vtkm::Id, detail::IndexFunctor>));
|
||||
(vtkm::cont::ArrayHandleImplicit<detail::IndexFunctor>));
|
||||
|
||||
VTKM_CONT
|
||||
ArrayHandleIndex(vtkm::Id length)
|
||||
|
@ -328,7 +328,7 @@ public:
|
||||
|
||||
typedef ReduceKernel<InputPortalType, U, BinaryFunctor> ReduceKernelType;
|
||||
|
||||
typedef vtkm::cont::ArrayHandleImplicit<U, ReduceKernelType> ReduceHandleType;
|
||||
typedef vtkm::cont::ArrayHandleImplicit<ReduceKernelType> ReduceHandleType;
|
||||
typedef vtkm::cont::ArrayHandle<U, vtkm::cont::StorageTagBasic> TempArrayType;
|
||||
|
||||
ReduceKernelType kernel(
|
||||
@ -336,7 +336,7 @@ public:
|
||||
|
||||
vtkm::Id length = (input.GetNumberOfValues() / 16);
|
||||
length += (input.GetNumberOfValues() % 16 == 0) ? 0 : 1;
|
||||
ReduceHandleType reduced = vtkm::cont::make_ArrayHandleImplicit<U>(kernel, length);
|
||||
ReduceHandleType reduced = vtkm::cont::make_ArrayHandleImplicit(kernel, length);
|
||||
|
||||
TempArrayType inclusiveScanStorage;
|
||||
const U scanResult =
|
||||
|
@ -265,8 +265,8 @@ private:
|
||||
typedef ::fancy_array_detail::IndexSquared<ValueType> FunctorType;
|
||||
FunctorType functor;
|
||||
|
||||
vtkm::cont::ArrayHandleImplicit<ValueType, FunctorType> implicit =
|
||||
vtkm::cont::make_ArrayHandleImplicit<ValueType>(functor, length);
|
||||
vtkm::cont::ArrayHandleImplicit<FunctorType> implicit =
|
||||
vtkm::cont::make_ArrayHandleImplicit(functor, length);
|
||||
|
||||
vtkm::cont::printSummary_ArrayHandle(implicit, std::cout);
|
||||
std::cout << std::endl;
|
||||
@ -298,7 +298,7 @@ private:
|
||||
typedef ::fancy_array_detail::IndexSquared<ValueType> FunctorType;
|
||||
typedef typename vtkm::VecTraits<ValueType>::ComponentType ComponentType;
|
||||
|
||||
typedef vtkm::cont::ArrayHandleImplicit<ValueType, FunctorType> ValueHandleType;
|
||||
typedef vtkm::cont::ArrayHandleImplicit<FunctorType> ValueHandleType;
|
||||
typedef vtkm::cont::ArrayHandle<ValueType> BasicArrayType;
|
||||
typedef vtkm::cont::ArrayHandleConcatenate<ValueHandleType, BasicArrayType> ConcatenateType;
|
||||
|
||||
@ -309,8 +309,7 @@ private:
|
||||
vtkm::Id basicLen = start_pos;
|
||||
|
||||
// make an implicit array
|
||||
ValueHandleType implicit =
|
||||
vtkm::cont::make_ArrayHandleImplicit<ValueType>(functor, implicitLen);
|
||||
ValueHandleType implicit = vtkm::cont::make_ArrayHandleImplicit(functor, implicitLen);
|
||||
// make a basic array
|
||||
std::vector<ValueType> basicVec;
|
||||
for (vtkm::Id i = 0; i < basicLen; i++)
|
||||
@ -359,7 +358,7 @@ private:
|
||||
typedef ::fancy_array_detail::IndexSquared<ValueType> FunctorType;
|
||||
|
||||
typedef vtkm::cont::ArrayHandleCounting<vtkm::Id> KeyHandleType;
|
||||
typedef vtkm::cont::ArrayHandleImplicit<ValueType, FunctorType> ValueHandleType;
|
||||
typedef vtkm::cont::ArrayHandleImplicit<FunctorType> ValueHandleType;
|
||||
typedef vtkm::cont::ArrayHandlePermutation<KeyHandleType, ValueHandleType>
|
||||
PermutationHandleType;
|
||||
|
||||
@ -371,7 +370,7 @@ private:
|
||||
KeyHandleType counting =
|
||||
vtkm::cont::make_ArrayHandleCounting<vtkm::Id>(start_pos, 1, counting_length);
|
||||
|
||||
ValueHandleType implicit = vtkm::cont::make_ArrayHandleImplicit<ValueType>(functor, length);
|
||||
ValueHandleType implicit = vtkm::cont::make_ArrayHandleImplicit(functor, length);
|
||||
|
||||
PermutationHandleType permutation =
|
||||
vtkm::cont::make_ArrayHandlePermutation(counting, implicit);
|
||||
|
@ -52,9 +52,9 @@ struct ImplicitTests
|
||||
typedef IndexSquared<ValueType> FunctorType;
|
||||
FunctorType functor;
|
||||
|
||||
typedef vtkm::cont::ArrayHandleImplicit<ValueType, FunctorType> ImplicitHandle;
|
||||
typedef vtkm::cont::ArrayHandleImplicit<FunctorType> ImplicitHandle;
|
||||
|
||||
ImplicitHandle implict = vtkm::cont::make_ArrayHandleImplicit<ValueType>(functor, ARRAY_SIZE);
|
||||
ImplicitHandle implict = vtkm::cont::make_ArrayHandleImplicit(functor, ARRAY_SIZE);
|
||||
|
||||
//verify that the control portal works
|
||||
for (int i = 0; i < ARRAY_SIZE; ++i)
|
||||
|
@ -44,7 +44,7 @@ struct DoubleIndexFunctor
|
||||
vtkm::Id operator()(vtkm::Id index) const { return 2 * index; }
|
||||
};
|
||||
|
||||
typedef vtkm::cont::ArrayHandleImplicit<vtkm::Id, DoubleIndexFunctor> DoubleIndexArrayType;
|
||||
typedef vtkm::cont::ArrayHandleImplicit<DoubleIndexFunctor> DoubleIndexArrayType;
|
||||
|
||||
template <typename PermutedPortalType>
|
||||
struct CheckPermutationFunctor : vtkm::exec::FunctorBase
|
||||
@ -185,7 +185,7 @@ VTKM_CONT void CheckOutputResult(PortalType portal)
|
||||
template <typename ValueType>
|
||||
struct PermutationTests
|
||||
{
|
||||
typedef vtkm::cont::ArrayHandleImplicit<vtkm::Id, DoubleIndexFunctor> IndexArrayType;
|
||||
typedef vtkm::cont::ArrayHandleImplicit<DoubleIndexFunctor> IndexArrayType;
|
||||
typedef vtkm::cont::ArrayHandle<ValueType, vtkm::cont::StorageTagBasic> ValueArrayType;
|
||||
typedef vtkm::cont::ArrayHandlePermutation<IndexArrayType, ValueArrayType> PermutationArrayType;
|
||||
|
||||
|
@ -379,8 +379,8 @@ void TryCastToArrayHandle()
|
||||
CheckCastToArrayHandle(groupVecArray);
|
||||
|
||||
std::cout << " Implicit array handle." << std::endl;
|
||||
CheckCastToArrayHandle(vtkm::cont::make_ArrayHandleImplicit<vtkm::FloatDefault>(
|
||||
TestValueFunctor<vtkm::FloatDefault>(), ARRAY_SIZE));
|
||||
CheckCastToArrayHandle(
|
||||
vtkm::cont::make_ArrayHandleImplicit(TestValueFunctor<vtkm::FloatDefault>(), ARRAY_SIZE));
|
||||
|
||||
std::cout << " Index array handle." << std::endl;
|
||||
CheckCastToArrayHandle(vtkm::cont::ArrayHandleIndex(ARRAY_SIZE));
|
||||
|
@ -140,7 +140,7 @@ public:
|
||||
|
||||
private:
|
||||
using AxisIndexArrayPoints =
|
||||
vtkm::cont::ArrayHandleImplicit<vtkm::Id, extractstructured::internal::SubArrayPermutePoints>;
|
||||
vtkm::cont::ArrayHandleImplicit<extractstructured::internal::SubArrayPermutePoints>;
|
||||
using PointIndexArray = vtkm::cont::ArrayHandleCartesianProduct<AxisIndexArrayPoints,
|
||||
AxisIndexArrayPoints,
|
||||
AxisIndexArrayPoints>;
|
||||
@ -158,7 +158,7 @@ private:
|
||||
{
|
||||
auto fnctr = extractstructured::internal::SubArrayPermutePoints(
|
||||
count, first, last, stride, includeBoundary);
|
||||
return vtkm::cont::make_ArrayHandleImplicit<vtkm::Id>(fnctr, count);
|
||||
return vtkm::cont::make_ArrayHandleImplicit(fnctr, count);
|
||||
}
|
||||
|
||||
static AxisIndexArrayCells MakeAxisIndexArrayCells(vtkm::Id count,
|
||||
|
@ -93,7 +93,7 @@ struct ScatterUniform
|
||||
return this->GetOutputRange(inputRange[0] * inputRange[1] * inputRange[2]);
|
||||
}
|
||||
|
||||
typedef vtkm::cont::ArrayHandleImplicit<vtkm::Id, detail::FunctorDiv> OutputToInputMapType;
|
||||
typedef vtkm::cont::ArrayHandleImplicit<detail::FunctorDiv> OutputToInputMapType;
|
||||
template <typename RangeType>
|
||||
VTKM_CONT OutputToInputMapType GetOutputToInputMap(RangeType inputRange) const
|
||||
{
|
||||
@ -101,7 +101,7 @@ struct ScatterUniform
|
||||
this->GetOutputRange(inputRange));
|
||||
}
|
||||
|
||||
typedef vtkm::cont::ArrayHandleImplicit<vtkm::IdComponent, detail::FunctorModulus> VisitArrayType;
|
||||
typedef vtkm::cont::ArrayHandleImplicit<detail::FunctorModulus> VisitArrayType;
|
||||
template <typename RangeType>
|
||||
VTKM_CONT VisitArrayType GetVisitArray(RangeType inputRange) const
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user