Commit a713a0d8 authored by Li-Ta Lo's avatar Li-Ta Lo

Generalize and documentation for DeviceAdapterAlgorithm::Transform

Generalize DeviceAdapterAlgorithm::Transform to accept input array of different value and storage type.
Add doxygen documentation in DeviceAdapterAlgorithm.h
parent 29232c49
......@@ -439,6 +439,26 @@ struct DeviceAdapterAlgorithm
///
VTKM_CONT static void Synchronize();
/// \brief Apply a given binary operation function element-wise to input arrays.
///
/// Apply the give binary operation to pairs of elements from the two input array
/// \c input1 and \c input2. The number of elements in the input arrays do not
/// have to be the same, in this case, only the smaller of the two numbers of elements
/// will be applied.
/// Outputs of the binary operation is stored in \c output.
///
template <typename T,
typename U,
typename V,
typename StorageT,
typename StorageU,
typename StorageV,
typename BinaryFunctor>
VTKM_CONT static void Transform(const vtkm::cont::ArrayHandle<T, StorageT>& input1,
const vtkm::cont::ArrayHandle<U, StorageU>& input2,
vtkm::cont::ArrayHandle<V, StorageV>& output,
BinaryFunctor binaryFunctor);
/// \brief Reduce an array to only the unique values it contains
///
/// Removes all duplicate values in \c values that are adjacent to each
......
......@@ -763,10 +763,16 @@ public:
DerivedAlgorithm::Sort(zipHandle, internal::KeyCompare<T, U, BinaryCompare>(binary_compare));
}
template <typename T, typename U, class StorageT, class StorageU, class BinaryFunctor>
VTKM_CONT static void Transform(vtkm::cont::ArrayHandle<T, StorageT>& input1,
vtkm::cont::ArrayHandle<T, StorageT>& input2,
vtkm::cont::ArrayHandle<U, StorageU>& output,
template <typename T,
typename U,
typename V,
typename StorageT,
typename StorageU,
typename StorageV,
typename BinaryFunctor>
VTKM_CONT static void Transform(const vtkm::cont::ArrayHandle<T, StorageT>& input1,
const vtkm::cont::ArrayHandle<U, StorageU>& input2,
vtkm::cont::ArrayHandle<V, StorageV>& output,
BinaryFunctor binaryFunctor)
{
vtkm::Id numValues = vtkm::Min(input1.GetNumberOfValues(), input2.GetNumberOfValues());
......@@ -779,7 +785,10 @@ public:
auto input2Portal = input2.PrepareForInput(DeviceAdapterTag());
auto outputPortal = output.PrepareForOutput(numValues, DeviceAdapterTag());
BinaryTransformKernel<decltype(input1Portal), decltype(outputPortal), BinaryFunctor>
BinaryTransformKernel<decltype(input1Portal),
decltype(input2Portal),
decltype(outputPortal),
BinaryFunctor>
binaryKernel(input1Portal, input2Portal, outputPortal, binaryFunctor);
DerivedAlgorithm::Schedule(binaryKernel, numValues);
}
......
......@@ -882,19 +882,20 @@ struct ScanKernel : vtkm::exec::FunctorBase
}
};
template <typename InPortalType, typename OutPortalType, typename BinaryFunctor>
template <typename InPortalType1,
typename InPortalType2,
typename OutPortalType,
typename BinaryFunctor>
struct BinaryTransformKernel : vtkm::exec::FunctorBase
{
using ValueType = typename InPortalType::ValueType;
InPortalType InPortal1;
InPortalType InPortal2;
InPortalType1 InPortal1;
InPortalType2 InPortal2;
OutPortalType OutPortal;
BinaryFunctor BinaryOperator;
VTKM_CONT
BinaryTransformKernel(const InPortalType& inPortal1,
const InPortalType& inPortal2,
BinaryTransformKernel(const InPortalType1& inPortal1,
const InPortalType2& inPortal2,
const OutPortalType& outPortal,
BinaryFunctor binaryOperator)
: InPortal1(inPortal1)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment