10 #ifndef vtk_m_cont_ArrayHandleRecombineVec_h
11 #define vtk_m_cont_ArrayHandleRecombineVec_h
29 template <
typename SourcePortalType>
30 class ArrayPortalRecombineVec;
32 template <
typename PortalType>
39 friend vtkm::internal::ArrayPortalRecombineVec<PortalType>;
43 using ComponentType =
typename std::remove_const<typename PortalType::ValueType>::type;
45 RecombineVec(
const RecombineVec&) =
default;
59 vtkm::internal::ArrayPortalValueReference<PortalType> operator[](
vtkm::IdComponent cIndex)
const
61 return vtkm::internal::ArrayPortalValueReference<PortalType>(this->Portals[cIndex],
65 template <
typename T, vtkm::IdComponent DestSize>
68 vtkm::IdComponent numComponents = vtkm::Min(DestSize, this->GetNumberOfComponents());
71 dest[cIndex] = this->Portals[cIndex].Get(this->Index);
84 if ((&this->Portals[0] != &src.Portals[0]) || (this->Index != src.Index))
102 VTKM_EXEC_CONT operator ComponentType()
const {
return this->Portals[0].Get(this->Index); }
104 template <vtkm::IdComponent N>
108 this->CopyInto(result);
112 template <
typename T>
116 VTKM_ASSERT(this->GetNumberOfComponents() == VTraits::GetNumberOfComponents(src));
117 for (
vtkm::IdComponent cIndex = 0; cIndex < this->GetNumberOfComponents(); ++cIndex)
119 (*this)[cIndex] += VTraits::GetComponent(src, cIndex);
123 template <
typename T>
127 VTKM_ASSERT(this->GetNumberOfComponents() == VTraits::GetNumberOfComponents(src));
128 for (
vtkm::IdComponent cIndex = 0; cIndex < this->GetNumberOfComponents(); ++cIndex)
130 (*this)[cIndex] -= VTraits::GetComponent(src, cIndex);
134 template <
typename T>
138 VTKM_ASSERT(this->GetNumberOfComponents() == VTraits::GetNumberOfComponents(src));
139 for (
vtkm::IdComponent cIndex = 0; cIndex < this->GetNumberOfComponents(); ++cIndex)
141 (*this)[cIndex] *= VTraits::GetComponent(src, cIndex);
145 template <
typename T>
149 VTKM_ASSERT(this->GetNumberOfComponents() == VTraits::GetNumberOfComponents(src));
150 for (
vtkm::IdComponent cIndex = 0; cIndex < this->GetNumberOfComponents(); ++cIndex)
152 (*this)[cIndex] /= VTraits::GetComponent(src, cIndex);
156 template <
typename T>
160 VTKM_ASSERT(this->GetNumberOfComponents() == VTraits::GetNumberOfComponents(src));
161 for (
vtkm::IdComponent cIndex = 0; cIndex < this->GetNumberOfComponents(); ++cIndex)
163 (*this)[cIndex] %= VTraits::GetComponent(src, cIndex);
167 template <
typename T>
171 VTKM_ASSERT(this->GetNumberOfComponents() == VTraits::GetNumberOfComponents(src));
172 for (
vtkm::IdComponent cIndex = 0; cIndex < this->GetNumberOfComponents(); ++cIndex)
174 (*this)[cIndex] &= VTraits::GetComponent(src, cIndex);
178 template <
typename T>
182 VTKM_ASSERT(this->GetNumberOfComponents() == VTraits::GetNumberOfComponents(src));
183 for (
vtkm::IdComponent cIndex = 0; cIndex < this->GetNumberOfComponents(); ++cIndex)
185 (*this)[cIndex] |= VTraits::GetComponent(src, cIndex);
189 template <
typename T>
193 VTKM_ASSERT(this->GetNumberOfComponents() == VTraits::GetNumberOfComponents(src));
194 for (
vtkm::IdComponent cIndex = 0; cIndex < this->GetNumberOfComponents(); ++cIndex)
196 (*this)[cIndex] ^= VTraits::GetComponent(src, cIndex);
200 template <
typename T>
204 VTKM_ASSERT(this->GetNumberOfComponents() == VTraits::GetNumberOfComponents(src));
205 for (
vtkm::IdComponent cIndex = 0; cIndex < this->GetNumberOfComponents(); ++cIndex)
207 (*this)[cIndex] >>= VTraits::GetComponent(src, cIndex);
211 template <
typename T>
215 VTKM_ASSERT(this->GetNumberOfComponents() == VTraits::GetNumberOfComponents(src));
216 for (
vtkm::IdComponent cIndex = 0; cIndex < this->GetNumberOfComponents(); ++cIndex)
218 (*this)[cIndex] <<= VTraits::GetComponent(src, cIndex);
224 template <
typename T>
229 if (numComponents > 1)
231 if (numComponents > this->GetNumberOfComponents())
233 numComponents = this->GetNumberOfComponents();
237 this->Portals[cIndex].Set(this->Index,
238 static_cast<ComponentType
>(VTraits::GetComponent(src, cIndex)));
244 for (
vtkm::IdComponent cIndex = 0; cIndex < this->GetNumberOfComponents(); ++cIndex)
246 this->Portals[cIndex].Set(this->Index,
247 static_cast<ComponentType
>(VTraits::GetComponent(src, 0)));
255 template <
typename PortalType>
256 struct TypeTraits<
vtkm::internal::RecombineVec<PortalType>>
259 using VecType = vtkm::internal::RecombineVec<PortalType>;
260 using ComponentType =
typename VecType::ComponentType;
269 return vtkm::internal::RecombineVec<PortalType>{};
273 template <
typename PortalType>
274 struct VecTraits<
vtkm::internal::RecombineVec<PortalType>>
276 using VecType = vtkm::internal::RecombineVec<PortalType>;
284 return vector.GetNumberOfComponents();
290 return vector[componentIndex];
297 vector[componentIndex] = component;
300 template <vtkm::IdComponent destSize>
310 template <
typename SourcePortalType>
311 class ArrayPortalRecombineVec
317 const SourcePortalType* Portals;
321 using ValueType = vtkm::internal::RecombineVec<SourcePortalType>;
323 ArrayPortalRecombineVec() =
default;
324 ArrayPortalRecombineVec(
const SourcePortalType* portals,
vtkm::IdComponent numComponents)
326 , NumberOfComponents(numComponents)
334 return ValueType({ this->Portals, this->NumberOfComponents }, index);
339 if ((value.GetIndex() == index) && (value.Portals.GetPointer() == this->Portals))
346 this->DoCopy(index, value);
350 template <
typename T>
353 this->DoCopy(index, value);
357 template <
typename T>
361 VTKM_ASSERT(Traits::GetNumberOfComponents(value) == this->NumberOfComponents);
364 this->Portals[cIndex].Set(index, Traits::GetComponent(value, cIndex));
380 struct StorageTagRecombineVec
387 struct RecombineVecMetaData
389 mutable std::vector<vtkm::cont::internal::Buffer> PortalBuffers;
390 std::vector<std::size_t> ArrayBufferOffsets;
392 RecombineVecMetaData() =
default;
394 RecombineVecMetaData(
const RecombineVecMetaData& src) { *
this = src; }
396 RecombineVecMetaData& operator=(
const RecombineVecMetaData& src)
398 this->ArrayBufferOffsets = src.ArrayBufferOffsets;
400 this->PortalBuffers.clear();
407 template <
typename T>
408 using RecombinedPortalType = vtkm::internal::ArrayPortalMultiplexer<
409 typename vtkm::cont::internal::Storage<T, vtkm::cont::StorageTagStride>::ReadPortalType,
410 typename vtkm::cont::internal::Storage<T, vtkm::cont::StorageTagStride>::WritePortalType>;
412 template <
typename T>
413 using RecombinedValueType = vtkm::internal::RecombineVec<RecombinedPortalType<T>>;
417 template <
typename ReadWritePortal>
418 class Storage<
vtkm::internal::RecombineVec<ReadWritePortal>,
419 vtkm::cont::internal::StorageTagRecombineVec>
421 using ComponentType =
typename ReadWritePortal::ValueType;
422 using SourceStorage = vtkm::cont::internal::Storage<ComponentType, vtkm::cont::StorageTagStride>;
426 (std::is_same<ReadWritePortal, detail::RecombinedPortalType<ComponentType>>::value));
428 VTKM_CONT static std::vector<vtkm::cont::internal::Buffer> BuffersForComponent(
429 const std::vector<vtkm::cont::internal::Buffer>& buffers,
432 auto& metaData = buffers[0].GetMetaData<detail::RecombineVecMetaData>();
433 std::size_t index =
static_cast<std::size_t
>(componentIndex);
434 return std::vector<vtkm::cont::internal::Buffer>(
435 buffers.begin() + metaData.ArrayBufferOffsets[index],
436 buffers.begin() + metaData.ArrayBufferOffsets[index + 1]);
440 using ReadPortalType = vtkm::internal::ArrayPortalRecombineVec<ReadWritePortal>;
441 using WritePortalType = vtkm::internal::ArrayPortalRecombineVec<ReadWritePortal>;
444 const std::vector<vtkm::cont::internal::Buffer>& buffers)
447 buffers[0].GetMetaData<detail::RecombineVecMetaData>().ArrayBufferOffsets.size() - 1);
451 const std::vector<vtkm::cont::internal::Buffer>& buffers)
455 SourceStorage::GetNumberOfComponentsFlat(BuffersForComponent(buffers, 0));
456 return numComponents * numSubComponents;
460 const std::vector<vtkm::cont::internal::Buffer>& buffers)
462 return SourceStorage::GetNumberOfValues(BuffersForComponent(buffers, 0));
466 const std::vector<vtkm::cont::internal::Buffer>& buffers,
473 SourceStorage::ResizeBuffers(
474 numValues, BuffersForComponent(buffers, component), preserve, token);
478 VTKM_CONT static void Fill(
const std::vector<vtkm::cont::internal::Buffer>&,
479 const vtkm::internal::RecombineVec<ReadWritePortal>&,
487 VTKM_CONT static ReadPortalType CreateReadPortal(
488 const std::vector<vtkm::cont::internal::Buffer>& buffers,
497 vtkm::cont::internal::Buffer portalBuffer;
507 buffers[0].GetMetaData<detail::RecombineVecMetaData>().PortalBuffers.push_back(portalBuffer);
510 ReadWritePortal* portals =
511 reinterpret_cast<ReadWritePortal*
>(portalBuffer.WritePointerHost(token));
514 portals[cIndex] = ReadWritePortal(
515 SourceStorage::CreateReadPortal(BuffersForComponent(buffers, cIndex), device, token));
520 return ReadPortalType(
521 reinterpret_cast<const ReadWritePortal*
>(portalBuffer.ReadPointerDevice(device, token)),
525 VTKM_CONT static WritePortalType CreateWritePortal(
526 const std::vector<vtkm::cont::internal::Buffer>& buffers,
535 vtkm::cont::internal::Buffer portalBuffer;
545 buffers[0].GetMetaData<detail::RecombineVecMetaData>().PortalBuffers.push_back(portalBuffer);
548 ReadWritePortal* portals =
549 reinterpret_cast<ReadWritePortal*
>(portalBuffer.WritePointerHost(token));
552 portals[cIndex] = ReadWritePortal(
553 SourceStorage::CreateWritePortal(BuffersForComponent(buffers, cIndex), device, token));
558 return WritePortalType(
559 reinterpret_cast<const ReadWritePortal*
>(portalBuffer.ReadPointerDevice(device, token)),
563 VTKM_CONT static ArrayType ArrayForComponent(
564 const std::vector<vtkm::cont::internal::Buffer>& buffers,
567 return ArrayType(BuffersForComponent(buffers, componentIndex));
570 VTKM_CONT static std::vector<vtkm::cont::internal::Buffer> CreateBuffers()
572 detail::RecombineVecMetaData metaData;
573 metaData.ArrayBufferOffsets.push_back(1);
574 return vtkm::cont::internal::CreateBuffers(metaData);
577 VTKM_CONT static void AppendComponent(std::vector<vtkm::cont::internal::Buffer>& buffers,
578 const ArrayType& array)
581 buffers.insert(buffers.end(), array.GetBuffers().begin(), array.GetBuffers().end());
583 buffers[0].GetMetaData<detail::RecombineVecMetaData>().ArrayBufferOffsets.push_back(
609 template <
typename ComponentType>
612 vtkm::cont::internal::StorageTagRecombineVec>
619 vtkm::cont::internal::StorageTagRecombineVec>));
630 return StorageType::GetNumberOfComponents(this->
GetBuffers());
641 return StorageType::ArrayForComponent(this->
GetBuffers(), componentIndex);
651 std::vector<vtkm::cont::internal::Buffer> buffers = this->
GetBuffers();
652 StorageType::AppendComponent(buffers, array);
661 struct ArrayExtractComponentImpl<
vtkm::cont::internal::StorageTagRecombineVec>
663 template <
typename RecombineVec>
671 using ComponentType =
typename RecombineVec::ComponentType;
675 array.GetComponentArray(componentIndex / subComponents),
676 componentIndex % subComponents,
682 template <
typename S>
683 struct ArrayRangeComputeImpl;
685 template <
typename S>
686 struct ArrayRangeComputeMagnitudeImpl;
688 template <
typename T,
typename S>
692 bool computeFiniteRange,
695 return vtkm::cont::internal::ArrayRangeComputeImpl<S>{}(
696 input, maskArray, computeFiniteRange, device);
699 template <
typename T,
typename S>
700 inline vtkm::Range ArrayRangeComputeMagnitudeImplCaller(
703 bool computeFiniteRange,
706 return vtkm::cont::internal::ArrayRangeComputeMagnitudeImpl<S>{}(
707 input, maskArray, computeFiniteRange, device);
713 template <
typename RecombineVecType>
718 bool computeFiniteRange,
726 result.Allocate(input.GetNumberOfComponents());
728 if (input.GetNumberOfValues() < 1)
734 auto resultPortal = result.WritePortal();
737 auto rangeAH = ArrayRangeComputeImplCaller(
738 input.GetComponentArray(i), maskArray, computeFiniteRange, device);
739 resultPortal.Set(i, rangeAH.ReadPortal().Get(0));
746 template <
typename ArrayHandleType>
747 struct ArrayValueIsNested;
749 template <
typename RecombineVecType>
750 struct ArrayValueIsNested<
751 vtkm::cont::ArrayHandle<RecombineVecType, vtkm::cont::internal::StorageTagRecombineVec>>
753 static constexpr
bool Value =
false;
757 struct VTKM_CONT_EXPORT ArrayRangeComputeMagnitudeImpl<
vtkm::cont::internal::StorageTagRecombineVec>
759 template <
typename RecombineVecType>
764 bool computeFiniteRange,
771 if (input.GetNumberOfValues() < 1)
775 if (input.GetNumberOfComponents() == 1)
777 return ArrayRangeComputeMagnitudeImplCaller(
778 input.GetComponentArray(0), maskArray, computeFiniteRange, device);
781 return ArrayRangeComputeMagnitudeGeneric(input_, maskArray, computeFiniteRange, device);
790 #endif //vtk_m_cont_ArrayHandleRecombineVec_h