10 #ifndef vtk_m_cont_internal_FunctorsGeneral_h
11 #define vtk_m_cont_internal_FunctorsGeneral_h
38 template <
typename ResultType,
typename Function>
39 struct WrappedBinaryOperator
44 WrappedBinaryOperator(
const Function& f)
50 template <
typename Argument1,
typename Argument2>
51 VTKM_EXEC_CONT ResultType operator()(
const Argument1& x,
const Argument2& y)
const
53 return static_cast<ResultType
>(m_f(x, y));
57 template <
typename Argument1,
typename Argument2>
59 operator()(
const vtkm::internal::ArrayPortalValueReference<Argument1>& x,
60 const vtkm::internal::ArrayPortalValueReference<Argument2>& y)
const
62 using ValueTypeX =
typename vtkm::internal::ArrayPortalValueReference<Argument1>::ValueType;
63 using ValueTypeY =
typename vtkm::internal::ArrayPortalValueReference<Argument2>::ValueType;
64 return static_cast<ResultType
>(m_f((ValueTypeX)x, (ValueTypeY)y));
68 template <
typename Argument1,
typename Argument2>
70 operator()(
const Argument1& x,
71 const vtkm::internal::ArrayPortalValueReference<Argument2>& y)
const
73 using ValueTypeY =
typename vtkm::internal::ArrayPortalValueReference<Argument2>::ValueType;
74 return static_cast<ResultType
>(m_f(x, (ValueTypeY)y));
78 template <
typename Argument1,
typename Argument2>
80 operator()(
const vtkm::internal::ArrayPortalValueReference<Argument1>& x,
81 const Argument2& y)
const
83 using ValueTypeX =
typename vtkm::internal::ArrayPortalValueReference<Argument1>::ValueType;
84 return static_cast<ResultType
>(m_f((ValueTypeX)x, y));
91 template <
typename T,
typename U,
class BinaryCompare = DefaultCompareFunctor>
98 explicit KeyCompare(BinaryCompare c)
111 BinaryCompare CompareFunctor;
114 template <
typename PortalConstType,
typename T,
typename BinaryFunctor>
117 PortalConstType Portal;
119 BinaryFunctor BinaryOperator;
132 ReduceKernel(
const PortalConstType& portal, T initialValue, BinaryFunctor binary_functor)
134 , InitialValue(initialValue)
135 , BinaryOperator(binary_functor)
136 , PortalLength(portal.GetNumberOfValues())
145 const vtkm::Id offset = index * reduceWidth;
147 if (offset + reduceWidth >= this->PortalLength)
151 T partialSum =
static_cast<T
>(BinaryOperator(this->InitialValue, this->Portal.Get(offset)));
153 while (currentIndex < this->PortalLength)
155 partialSum =
static_cast<T
>(BinaryOperator(partialSum, this->Portal.Get(currentIndex)));
165 static_cast<T
>(BinaryOperator(this->Portal.Get(offset), this->Portal.Get(offset + 1)));
166 for (
int i = 2; i < reduceWidth; ++i)
168 partialSum =
static_cast<T
>(BinaryOperator(partialSum, this->Portal.Get(offset + i)));
175 struct ReduceKeySeriesStates
182 ReduceKeySeriesStates(
bool start =
false,
bool end =
false)
189 template <
typename InputPortalType,
typename KeyStatePortalType>
192 InputPortalType Input;
193 KeyStatePortalType KeyState;
196 ReduceStencilGeneration(
const InputPortalType& input,
const KeyStatePortalType& kstate)
204 void operator()(
vtkm::Id centerIndex)
const
206 using ValueType =
typename InputPortalType::ValueType;
207 using KeyStateType =
typename KeyStatePortalType::ValueType;
209 const vtkm::Id leftIndex = centerIndex - 1;
210 const vtkm::Id rightIndex = centerIndex + 1;
222 if (centerIndex == 0)
227 const ValueType centerValue = this->Input.Get(centerIndex);
228 const ValueType rightValue = this->Input.Get(rightIndex);
229 const KeyStateType state = ReduceKeySeriesStates(
true, rightValue != centerValue);
230 this->KeyState.Set(centerIndex, state);
232 else if (rightIndex == this->Input.GetNumberOfValues())
236 const ValueType centerValue = this->Input.Get(centerIndex);
237 const ValueType leftValue = this->Input.Get(leftIndex);
238 const KeyStateType state = ReduceKeySeriesStates(leftValue != centerValue,
true);
239 this->KeyState.Set(centerIndex, state);
243 const ValueType centerValue = this->Input.Get(centerIndex);
244 const bool leftMatches(this->Input.Get(leftIndex) == centerValue);
245 const bool rightMatches(this->Input.Get(rightIndex) == centerValue);
248 KeyStateType state = ReduceKeySeriesStates(!leftMatches, !rightMatches);
249 this->KeyState.Set(centerIndex, state);
254 template <
typename BinaryFunctor>
255 struct ReduceByKeyAdd
257 BinaryFunctor BinaryOperator;
259 ReduceByKeyAdd(BinaryFunctor binary_functor)
260 : BinaryOperator(binary_functor)
264 template <
typename T>
280 return ReturnType(this->BinaryOperator(a.
first, b.
first),
287 struct ReduceByKeyUnaryStencilOp
290 bool operator()(ReduceKeySeriesStates keySeriesState)
const {
return keySeriesState.fEnd; }
293 template <
typename T,
294 typename InputPortalType,
295 typename KeyStatePortalType,
296 typename OutputPortalType>
299 InputPortalType Input;
300 KeyStatePortalType KeyState;
301 OutputPortalType Output;
304 ShiftCopyAndInit(
const InputPortalType& _input,
305 const KeyStatePortalType& kstate,
306 OutputPortalType& _output,
316 void operator()(
vtkm::Id index)
const
318 if (this->KeyState.Get(index).fStart)
320 Output.Set(index, initValue);
324 Output.Set(index, Input.Get(index - 1));
329 template <
class BitsPortal,
class IndicesPortal>
332 using WordType =
typename BitsPortal::WordTypePreferred;
337 static constexpr
vtkm::Id WordsPerCacheLine =
338 CacheLineSize /
static_cast<vtkm::Id>(
sizeof(WordType));
339 static constexpr
vtkm::Id CacheLinesPerInstance = 2;
340 static constexpr
vtkm::Id WordsPerInstance = CacheLinesPerInstance * WordsPerCacheLine;
343 VTKM_PASS_COMMAS(std::is_same<typename IndicesPortal::ValueType, vtkm::Id>::value));
346 BitFieldToUnorderedSetFunctor(
const BitsPortal& input,
347 IndicesPortal& output,
348 std::atomic<vtkm::UInt64>& popCount)
352 , FinalWordIndex{ input.GetNumberOfWords() - 1 }
353 , FinalWordMask(input.GetFinalWordMask())
359 const auto numWords = this->Input.GetNumberOfWords();
360 return (numWords + WordsPerInstance - 1) / WordsPerInstance;
365 const vtkm::Id numWords = this->Input.GetNumberOfWords();
366 const vtkm::Id wordStart = vtkm::Min(instanceIdx * WordsPerInstance, numWords);
367 const vtkm::Id wordEnd = vtkm::Min(wordStart + WordsPerInstance, numWords);
369 if (wordStart != wordEnd)
371 this->ExecuteRange(wordStart, wordEnd);
377 #ifndef VTKM_CUDA_DEVICE_PASS // for std::atomic call from VTKM_EXEC function:
379 vtkm::UInt64 chunkBits = this->CountChunkBits(wordStart, wordEnd);
382 vtkm::UInt64 outIdx = this->PopCount.fetch_add(chunkBits, std::memory_order_relaxed);
384 this->ProcessWords(wordStart, wordEnd,
static_cast<vtkm::Id>(outIdx));
398 const bool isFinalChunk = wordEnd == (this->FinalWordIndex + 1);
402 wordEnd = this->FinalWordIndex;
406 for (
vtkm::Id i = wordStart; i < wordEnd; ++i)
413 tmp +=
vtkm::CountSetBits(this->Input.GetWord(this->FinalWordIndex) & this->FinalWordMask);
422 const bool isFinalChunk = wordEnd == (this->FinalWordIndex + 1);
426 wordEnd = this->FinalWordIndex;
429 for (
vtkm::Id i = wordStart; i < wordEnd; ++i)
431 const vtkm::Id firstBitIdx = i *
static_cast<vtkm::Id>(
sizeof(WordType)) * CHAR_BIT;
432 WordType word = this->Input.GetWord(i);
437 this->Output.Set(outputStartIdx++, firstBitIdx + bit);
444 const vtkm::Id i = this->FinalWordIndex;
445 const vtkm::Id firstBitIdx = i *
static_cast<vtkm::Id>(
sizeof(WordType)) * CHAR_BIT;
446 WordType word = this->Input.GetWord(i) & this->FinalWordMask;
451 this->Output.Set(outputStartIdx++, firstBitIdx + bit);
458 IndicesPortal Output;
459 std::atomic<vtkm::UInt64>& PopCount;
462 WordType FinalWordMask{ 0 };
465 template <
class InputPortalType,
class OutputPortalType>
468 InputPortalType InputPortal;
469 OutputPortalType OutputPortal;
474 CopyKernel(InputPortalType inputPortal,
475 OutputPortalType outputPortal,
478 : InputPortal(inputPortal)
479 , OutputPortal(outputPortal)
480 , InputOffset(inputOffset)
481 , OutputOffset(outputOffset)
486 void operator()(
vtkm::Id index)
const
488 using ValueType =
typename OutputPortalType::ValueType;
489 this->OutputPortal.Set(
490 index + this->OutputOffset,
491 static_cast<ValueType
>(this->InputPortal.Get(index + this->InputOffset)));
495 void SetErrorMessageBuffer(
const vtkm::exec::internal::ErrorMessageBuffer&) {}
498 template <
typename BitsPortal>
501 using WordType =
typename BitsPortal::WordTypePreferred;
507 static constexpr
vtkm::Id WordsPerCacheLine =
508 CacheLineSize /
static_cast<vtkm::Id>(
sizeof(WordType));
509 static constexpr
vtkm::Id CacheLinesPerInstance = 2;
510 static constexpr
vtkm::Id WordsPerInstance = CacheLinesPerInstance * WordsPerCacheLine;
513 CountSetBitsFunctor(
const BitsPortal& input, std::atomic<vtkm::UInt64>& popCount)
516 , FinalWordIndex{ input.GetNumberOfWords() - 1 }
517 , FinalWordMask{ input.GetFinalWordMask() }
523 const auto numWords = this->Input.GetNumberOfWords();
524 return (numWords + WordsPerInstance - 1) / WordsPerInstance;
529 const vtkm::Id numWords = this->Input.GetNumberOfWords();
530 const vtkm::Id wordStart = vtkm::Min(instanceIdx * WordsPerInstance, numWords);
531 const vtkm::Id wordEnd = vtkm::Min(wordStart + WordsPerInstance, numWords);
533 if (wordStart != wordEnd)
535 this->ExecuteRange(wordStart, wordEnd);
544 #ifndef VTKM_CUDA_DEVICE_PASS // for std::atomic call from VTKM_EXEC function:
546 vtkm::UInt64 chunkBits = this->CountChunkBits(wordStart, wordEnd);
547 this->PopCount.fetch_add(chunkBits, std::memory_order_relaxed);
557 const bool isFinalChunk = wordEnd == (this->FinalWordIndex + 1);
561 wordEnd = this->FinalWordIndex;
565 for (
vtkm::Id i = wordStart; i < wordEnd; ++i)
572 tmp +=
vtkm::CountSetBits(this->Input.GetWord(this->FinalWordIndex) & this->FinalWordMask);
579 std::atomic<vtkm::UInt64>& PopCount;
582 WordType FinalWordMask{ 0 };
589 template <
typename WordType,
typename =
typename std::enable_if<(sizeof(WordType) >= 4)>::type>
590 static constexpr
VTKM_CONT WordType RepeatTo32BitsIfNeeded(WordType pattern)
597 return static_cast<vtkm::UInt32>(pattern << 16 | pattern);
602 return RepeatTo32BitsIfNeeded(
static_cast<vtkm::UInt16>(pattern << 8 | pattern));
605 template <
typename BitsPortal,
typename WordType>
609 FillBitFieldFunctor(
const BitsPortal& portal, WordType mask)
615 VTKM_EXEC void operator()(
vtkm::Id wordIdx)
const { this->Portal.SetWord(wordIdx, this->Mask); }
622 template <
typename PortalType>
625 using ValueType =
typename PortalType::ValueType;
628 FillArrayHandleFunctor(
const PortalType& portal, ValueType value)
634 VTKM_EXEC void operator()(
vtkm::Id idx)
const { this->Portal.Set(idx, this->Value); }
641 template <
typename Iterator,
typename IteratorTag>
647 for (
auto it = from; it != to; ++it)
654 template <
typename Iterator>
657 std::random_access_iterator_tag)
659 return static_cast<vtkm::Id>(to - from);
662 #if defined(VTKM_HIP)
664 template <
typename Iterator>
665 __host__
static inline vtkm::Id IteratorDistance(
const Iterator& from,
const Iterator& to)
667 return static_cast<vtkm::Id>(std::distance(from, to));
670 template <
typename Iterator>
671 __device__
static inline vtkm::Id IteratorDistance(
const Iterator& from,
const Iterator& to)
673 return IteratorDistanceImpl(
674 from, to,
typename std::iterator_traits<Iterator>::iterator_category{});
679 template <
typename Iterator>
680 VTKM_EXEC static inline vtkm::Id IteratorDistance(
const Iterator& from,
const Iterator& to)
682 #ifndef VTKM_CUDA_DEVICE_PASS
683 return static_cast<vtkm::Id>(std::distance(from, to));
685 return IteratorDistanceImpl(
686 from, to,
typename std::iterator_traits<Iterator>::iterator_category{});
692 template <
class InputPortalType,
class ValuesPortalType,
class OutputPortalType>
693 struct LowerBoundsKernel
695 InputPortalType InputPortal;
696 ValuesPortalType ValuesPortal;
697 OutputPortalType OutputPortal;
700 LowerBoundsKernel(InputPortalType inputPortal,
701 ValuesPortalType valuesPortal,
702 OutputPortalType outputPortal)
703 : InputPortal(inputPortal)
704 , ValuesPortal(valuesPortal)
705 , OutputPortal(outputPortal)
711 void operator()(
vtkm::Id index)
const
721 InputIteratorsType inputIterators(this->InputPortal);
723 inputIterators.GetBegin(), inputIterators.GetEnd(), this->ValuesPortal.Get(index));
725 vtkm::Id resultIndex = IteratorDistance(inputIterators.GetBegin(), resultPos);
726 this->OutputPortal.Set(index, resultIndex);
730 void SetErrorMessageBuffer(
const vtkm::exec::internal::ErrorMessageBuffer&) {}
733 template <
class InputPortalType,
734 class ValuesPortalType,
735 class OutputPortalType,
737 struct LowerBoundsComparisonKernel
739 InputPortalType InputPortal;
740 ValuesPortalType ValuesPortal;
741 OutputPortalType OutputPortal;
742 BinaryCompare CompareFunctor;
745 LowerBoundsComparisonKernel(InputPortalType inputPortal,
746 ValuesPortalType valuesPortal,
747 OutputPortalType outputPortal,
748 BinaryCompare binary_compare)
749 : InputPortal(inputPortal)
750 , ValuesPortal(valuesPortal)
751 , OutputPortal(outputPortal)
752 , CompareFunctor(binary_compare)
758 void operator()(
vtkm::Id index)
const
768 InputIteratorsType inputIterators(this->InputPortal);
770 inputIterators.GetEnd(),
771 this->ValuesPortal.Get(index),
772 this->CompareFunctor);
774 vtkm::Id resultIndex = IteratorDistance(inputIterators.GetBegin(), resultPos);
775 this->OutputPortal.Set(index, resultIndex);
779 void SetErrorMessageBuffer(
const vtkm::exec::internal::ErrorMessageBuffer&) {}
782 template <
typename PortalType>
783 struct SetConstantKernel
785 using ValueType =
typename PortalType::ValueType;
790 SetConstantKernel(
const PortalType& portal, ValueType value)
798 void operator()(
vtkm::Id index)
const { this->Portal.Set(index, this->Value); }
801 void SetErrorMessageBuffer(
const vtkm::exec::internal::ErrorMessageBuffer&) {}
804 template <
typename PortalType,
typename BinaryCompare>
808 BinaryCompare Compare;
812 BitonicSortMergeKernel(
const PortalType& portal,
const BinaryCompare& compare,
vtkm::Id groupSize)
815 , GroupSize(groupSize)
821 void operator()(
vtkm::Id index)
const
823 using ValueType =
typename PortalType::ValueType;
825 vtkm::Id groupIndex = index % this->GroupSize;
826 vtkm::Id blockSize = 2 * this->GroupSize;
827 vtkm::Id blockIndex = index / this->GroupSize;
829 vtkm::Id lowIndex = blockIndex * blockSize + groupIndex;
830 vtkm::Id highIndex = lowIndex + this->GroupSize;
832 if (highIndex < this->Portal.GetNumberOfValues())
834 ValueType lowValue = this->Portal.Get(lowIndex);
835 ValueType highValue = this->Portal.Get(highIndex);
836 if (this->Compare(highValue, lowValue))
838 this->Portal.Set(highIndex, lowValue);
839 this->Portal.Set(lowIndex, highValue);
845 template <
typename PortalType,
typename BinaryCompare>
849 BinaryCompare Compare;
853 BitonicSortCrossoverKernel(
const PortalType& portal,
854 const BinaryCompare& compare,
858 , GroupSize(groupSize)
864 void operator()(
vtkm::Id index)
const
866 using ValueType =
typename PortalType::ValueType;
868 vtkm::Id groupIndex = index % this->GroupSize;
869 vtkm::Id blockSize = 2 * this->GroupSize;
870 vtkm::Id blockIndex = index / this->GroupSize;
872 vtkm::Id lowIndex = blockIndex * blockSize + groupIndex;
873 vtkm::Id highIndex = blockIndex * blockSize + (blockSize - groupIndex - 1);
875 if (highIndex < this->Portal.GetNumberOfValues())
877 ValueType lowValue = this->Portal.Get(lowIndex);
878 ValueType highValue = this->Portal.Get(highIndex);
879 if (this->Compare(highValue, lowValue))
881 this->Portal.Set(highIndex, lowValue);
882 this->Portal.Set(lowIndex, highValue);
888 template <
class StencilPortalType,
class OutputPortalType,
class UnaryPredicate>
889 struct StencilToIndexFlagKernel
891 using StencilValueType =
typename StencilPortalType::ValueType;
892 StencilPortalType StencilPortal;
893 OutputPortalType OutputPortal;
894 UnaryPredicate Predicate;
897 StencilToIndexFlagKernel(StencilPortalType stencilPortal,
898 OutputPortalType outputPortal,
899 UnaryPredicate unary_predicate)
900 : StencilPortal(stencilPortal)
901 , OutputPortal(outputPortal)
902 , Predicate(unary_predicate)
908 void operator()(
vtkm::Id index)
const
910 StencilValueType value = this->StencilPortal.Get(index);
911 this->OutputPortal.Set(index, this->Predicate(value) ? 1 : 0);
915 void SetErrorMessageBuffer(
const vtkm::exec::internal::ErrorMessageBuffer&) {}
918 template <
class InputPortalType,
919 class StencilPortalType,
920 class IndexPortalType,
921 class OutputPortalType,
922 class PredicateOperator>
925 InputPortalType InputPortal;
926 StencilPortalType StencilPortal;
927 IndexPortalType IndexPortal;
928 OutputPortalType OutputPortal;
929 PredicateOperator Predicate;
932 CopyIfKernel(InputPortalType inputPortal,
933 StencilPortalType stencilPortal,
934 IndexPortalType indexPortal,
935 OutputPortalType outputPortal,
936 PredicateOperator unary_predicate)
937 : InputPortal(inputPortal)
938 , StencilPortal(stencilPortal)
939 , IndexPortal(indexPortal)
940 , OutputPortal(outputPortal)
941 , Predicate(unary_predicate)
947 void operator()(
vtkm::Id index)
const
949 using StencilValueType =
typename StencilPortalType::ValueType;
950 StencilValueType stencilValue = this->StencilPortal.Get(index);
951 if (Predicate(stencilValue))
953 vtkm::Id outputIndex = this->IndexPortal.Get(index);
955 using OutputValueType =
typename OutputPortalType::ValueType;
956 OutputValueType value = this->InputPortal.Get(index);
958 this->OutputPortal.Set(outputIndex, value);
963 void SetErrorMessageBuffer(
const vtkm::exec::internal::ErrorMessageBuffer&) {}
966 template <
class InputPortalType,
class StencilPortalType>
967 struct ClassifyUniqueKernel
969 InputPortalType InputPortal;
970 StencilPortalType StencilPortal;
973 ClassifyUniqueKernel(InputPortalType inputPortal, StencilPortalType stencilPortal)
974 : InputPortal(inputPortal)
975 , StencilPortal(stencilPortal)
981 void operator()(
vtkm::Id index)
const
983 using ValueType =
typename StencilPortalType::ValueType;
987 this->StencilPortal.Set(index, ValueType(1));
991 ValueType flag = ValueType(this->InputPortal.Get(index - 1) != this->InputPortal.Get(index));
992 this->StencilPortal.Set(index, flag);
997 void SetErrorMessageBuffer(
const vtkm::exec::internal::ErrorMessageBuffer&) {}
1000 template <
class InputPortalType,
class StencilPortalType,
class BinaryCompare>
1001 struct ClassifyUniqueComparisonKernel
1003 InputPortalType InputPortal;
1004 StencilPortalType StencilPortal;
1005 BinaryCompare CompareFunctor;
1008 ClassifyUniqueComparisonKernel(InputPortalType inputPortal,
1009 StencilPortalType stencilPortal,
1010 BinaryCompare binary_compare)
1011 : InputPortal(inputPortal)
1012 , StencilPortal(stencilPortal)
1013 , CompareFunctor(binary_compare)
1019 void operator()(
vtkm::Id index)
const
1021 using ValueType =
typename StencilPortalType::ValueType;
1025 this->StencilPortal.Set(index, ValueType(1));
1031 !(this->CompareFunctor(this->InputPortal.Get(index - 1), this->InputPortal.Get(index)));
1032 ValueType flag = ValueType(same);
1033 this->StencilPortal.Set(index, flag);
1038 void SetErrorMessageBuffer(
const vtkm::exec::internal::ErrorMessageBuffer&) {}
1041 template <
class InputPortalType,
class ValuesPortalType,
class OutputPortalType>
1042 struct UpperBoundsKernel
1044 InputPortalType InputPortal;
1045 ValuesPortalType ValuesPortal;
1046 OutputPortalType OutputPortal;
1049 UpperBoundsKernel(InputPortalType inputPortal,
1050 ValuesPortalType valuesPortal,
1051 OutputPortalType outputPortal)
1052 : InputPortal(inputPortal)
1053 , ValuesPortal(valuesPortal)
1054 , OutputPortal(outputPortal)
1060 void operator()(
vtkm::Id index)
const
1070 InputIteratorsType inputIterators(this->InputPortal);
1072 inputIterators.GetBegin(), inputIterators.GetEnd(), this->ValuesPortal.Get(index));
1074 vtkm::Id resultIndex = IteratorDistance(inputIterators.GetBegin(), resultPos);
1075 this->OutputPortal.Set(index, resultIndex);
1079 void SetErrorMessageBuffer(
const vtkm::exec::internal::ErrorMessageBuffer&) {}
1082 template <
class InputPortalType,
1083 class ValuesPortalType,
1084 class OutputPortalType,
1085 class BinaryCompare>
1086 struct UpperBoundsKernelComparisonKernel
1088 InputPortalType InputPortal;
1089 ValuesPortalType ValuesPortal;
1090 OutputPortalType OutputPortal;
1091 BinaryCompare CompareFunctor;
1094 UpperBoundsKernelComparisonKernel(InputPortalType inputPortal,
1095 ValuesPortalType valuesPortal,
1096 OutputPortalType outputPortal,
1097 BinaryCompare binary_compare)
1098 : InputPortal(inputPortal)
1099 , ValuesPortal(valuesPortal)
1100 , OutputPortal(outputPortal)
1101 , CompareFunctor(binary_compare)
1107 void operator()(
vtkm::Id index)
const
1117 InputIteratorsType inputIterators(this->InputPortal);
1119 inputIterators.GetEnd(),
1120 this->ValuesPortal.Get(index),
1121 this->CompareFunctor);
1123 vtkm::Id resultIndex = IteratorDistance(inputIterators.GetBegin(), resultPos);
1124 this->OutputPortal.Set(index, resultIndex);
1128 void SetErrorMessageBuffer(
const vtkm::exec::internal::ErrorMessageBuffer&) {}
1131 template <
typename InPortalType,
typename OutPortalType,
typename BinaryFunctor>
1134 using ValueType =
typename InPortalType::ValueType;
1136 InPortalType InPortal;
1137 OutPortalType OutPortal;
1138 BinaryFunctor BinaryOperator;
1139 ValueType InitialValue;
1142 InclusiveToExclusiveKernel(
const InPortalType& inPortal,
1143 const OutPortalType& outPortal,
1144 BinaryFunctor& binaryOperator,
1145 ValueType initialValue)
1146 : InPortal(inPortal)
1147 , OutPortal(outPortal)
1148 , BinaryOperator(binaryOperator)
1149 , InitialValue(initialValue)
1155 void operator()(
vtkm::Id index)
const
1157 const ValueType result = (index == 0)
1158 ? this->InitialValue
1159 : this->BinaryOperator(this->InitialValue, this->InPortal.Get(index - 1));
1161 this->OutPortal.Set(index, result);
1165 template <
typename InPortalType,
typename OutPortalType,
typename BinaryFunctor>
1168 using ValueType =
typename InPortalType::ValueType;
1170 InPortalType InPortal;
1171 OutPortalType OutPortal;
1172 BinaryFunctor BinaryOperator;
1173 ValueType InitialValue;
1174 ValueType FinalValue;
1177 InclusiveToExtendedKernel(
const InPortalType& inPortal,
1178 const OutPortalType& outPortal,
1179 BinaryFunctor& binaryOperator,
1180 ValueType initialValue,
1181 ValueType finalValue)
1182 : InPortal(inPortal)
1183 , OutPortal(outPortal)
1184 , BinaryOperator(binaryOperator)
1185 , InitialValue(initialValue)
1186 , FinalValue(finalValue)
1192 void operator()(
vtkm::Id index)
const
1196 const ValueType result = (index == 0) ? this->InitialValue
1197 : (index == this->InPortal.GetNumberOfValues())
1199 : this->BinaryOperator(this->InitialValue, this->InPortal.Get(index - 1));
1201 this->OutPortal.Set(index, result);
1205 template <
typename PortalType,
typename BinaryFunctor>
1209 BinaryFunctor BinaryOperator;
1215 ScanKernel(
const PortalType& portal,
1216 BinaryFunctor binary_functor,
1220 , BinaryOperator(binary_functor)
1223 , Distance(stride / 2)
1229 void operator()(
vtkm::Id index)
const
1231 using ValueType =
typename PortalType::ValueType;
1233 vtkm::Id leftIndex = this->Offset + index * this->Stride;
1234 vtkm::Id rightIndex = leftIndex + this->Distance;
1236 if (rightIndex < this->Portal.GetNumberOfValues())
1238 ValueType leftValue = this->Portal.Get(leftIndex);
1239 ValueType rightValue = this->Portal.Get(rightIndex);
1240 this->Portal.Set(rightIndex, BinaryOperator(leftValue, rightValue));
1245 template <
typename InPortalType1,
1246 typename InPortalType2,
1247 typename OutPortalType,
1248 typename BinaryFunctor>
1251 InPortalType1 InPortal1;
1252 InPortalType2 InPortal2;
1253 OutPortalType OutPortal;
1254 BinaryFunctor BinaryOperator;
1257 BinaryTransformKernel(
const InPortalType1& inPortal1,
1258 const InPortalType2& inPortal2,
1259 const OutPortalType& outPortal,
1260 BinaryFunctor binaryOperator)
1261 : InPortal1(inPortal1)
1262 , InPortal2(inPortal2)
1263 , OutPortal(outPortal)
1264 , BinaryOperator(binaryOperator)
1270 void operator()(
vtkm::Id index)
const
1272 this->OutPortal.Set(
1273 index, this->BinaryOperator(this->InPortal1.Get(index), this->InPortal2.Get(index)));
1280 #endif //vtk_m_cont_internal_FunctorsGeneral_h