10 #ifndef vtk_m_cont_ArrayHandleRuntimeVec_h
11 #define vtk_m_cont_ArrayHandleRuntimeVec_h
38 template <
typename T, vtkm::IdComponent N>
39 struct UnrollVecImpl<
vtkm::Vec<T, N>>
41 using subtype =
typename UnrollVecImpl<T>::type;
52 using UnrollVec =
typename detail::UnrollVecImpl<T>::type;
54 template <
typename ComponentsPortalType>
58 using ComponentType =
typename std::remove_const<typename ComponentsPortalType::ValueType>::type;
61 ArrayPortalRuntimeVec() =
default;
63 VTKM_EXEC_CONT ArrayPortalRuntimeVec(
const ComponentsPortalType& componentsPortal,
65 : ComponentsPortal(componentsPortal)
66 , NumberOfComponents(numComponents)
73 template <
typename OtherComponentsPortalType>
74 VTKM_EXEC_CONT ArrayPortalRuntimeVec(
const ArrayPortalRuntimeVec<OtherComponentsPortalType>& src)
75 : ComponentsPortal(src.GetComponentsPortal())
76 , NumberOfComponents(src.GetNumberOfComponents())
82 return this->ComponentsPortal.GetNumberOfValues() / this->NumberOfComponents;
88 this->ComponentsPortal, this->NumberOfComponents, index * this->NumberOfComponents);
93 if ((&value.GetPortal() == &this->ComponentsPortal) &&
94 (value.GetOffset() == (index * this->NumberOfComponents)))
102 this->
Get(index) = value;
106 VTKM_EXEC_CONT const ComponentsPortalType& GetComponentsPortal()
const
108 return this->ComponentsPortal;
113 return this->NumberOfComponents;
117 ComponentsPortalType ComponentsPortal;
136 struct RuntimeVecMetaData
141 template <
typename ComponentsPortal>
144 using ComponentType =
typename ComponentsPortal::ValueType;
145 using ComponentsStorage =
146 vtkm::cont::internal::Storage<ComponentType, vtkm::cont::StorageTagBasic>;
150 "ArrayHandleRuntimeVec only supports scalars grouped into a single Vec. Nested Vecs can "
151 "still be used with ArrayHandleRuntimeVec. The values are treated as flattened (like "
157 (std::is_same<ComponentsPortal, typename ComponentsStorage::WritePortalType>::value),
158 "Used invalid ComponentsPortal type with expected ComponentsStorageTag.");
160 using Info = RuntimeVecMetaData;
162 VTKM_CONT static std::vector<vtkm::cont::internal::Buffer> ComponentsBuffers(
163 const std::vector<vtkm::cont::internal::Buffer>& buffers)
165 return std::vector<vtkm::cont::internal::Buffer>(buffers.begin() + 1, buffers.end());
169 using ReadPortalType =
170 vtkm::internal::ArrayPortalRuntimeVec<typename ComponentsStorage::ReadPortalType>;
171 using WritePortalType =
172 vtkm::internal::ArrayPortalRuntimeVec<typename ComponentsStorage::WritePortalType>;
175 const std::vector<vtkm::cont::internal::Buffer>& buffers)
177 return buffers[0].GetMetaData<Info>().NumberOfComponents;
181 const std::vector<vtkm::cont::internal::Buffer>& buffers)
185 ComponentsStorage::GetNumberOfComponentsFlat(ComponentsBuffers(buffers));
186 return numComponents * numSubComponents;
190 const std::vector<vtkm::cont::internal::Buffer>& buffers)
192 return ComponentsStorage::GetNumberOfValues(ComponentsBuffers(buffers)) /
193 GetNumberOfComponents(buffers);
197 const std::vector<vtkm::cont::internal::Buffer>& buffers,
201 ComponentsStorage::ResizeBuffers(
202 numValues * GetNumberOfComponents(buffers), ComponentsBuffers(buffers), preserve, token);
205 VTKM_CONT static void Fill(
const std::vector<vtkm::cont::internal::Buffer>&,
214 VTKM_CONT static ReadPortalType CreateReadPortal(
215 const std::vector<vtkm::cont::internal::Buffer>& buffers,
219 return ReadPortalType(
220 ComponentsStorage::CreateReadPortal(ComponentsBuffers(buffers), device, token),
221 GetNumberOfComponents(buffers));
224 VTKM_CONT static WritePortalType CreateWritePortal(
225 const std::vector<vtkm::cont::internal::Buffer>& buffers,
229 return WritePortalType(
230 ComponentsStorage::CreateWritePortal(ComponentsBuffers(buffers), device, token),
231 GetNumberOfComponents(buffers));
234 VTKM_CONT static std::vector<vtkm::cont::internal::Buffer> CreateBuffers(
236 const ComponentsArray& componentsArray = ComponentsArray{})
239 (componentsArray.GetNumberOfValues() % numComponents) != 0,
240 "Array given to ArrayHandleRuntimeVec has size ("
241 << componentsArray.GetNumberOfValues()
242 <<
") that is not divisible by the number of components selected ("
243 << numComponents <<
").");
245 info.NumberOfComponents = numComponents;
246 return vtkm::cont::internal::CreateBuffers(info, componentsArray);
249 VTKM_CONT static ComponentsArray GetComponentsArray(
250 const std::vector<vtkm::cont::internal::Buffer>& buffers)
252 return ComponentsArray(ComponentsBuffers(buffers));
255 VTKM_CONT static void AsArrayHandleBasic(
256 const std::vector<vtkm::cont::internal::Buffer>& buffers,
259 if (GetNumberOfComponents(buffers) != 1)
262 "Attempted to pull a scalar array from an ArrayHandleRuntime that does not hold scalars.");
264 dest = GetComponentsArray(buffers);
267 template <vtkm::IdComponent N>
268 VTKM_CONT static void AsArrayHandleBasic(
269 const std::vector<vtkm::cont::internal::Buffer>& buffers,
272 if (GetNumberOfComponents(buffers) != N)
275 "Attempted to pull an array of Vecs of the wrong size from an ArrayHandleRuntime.");
278 ComponentsBuffers(buffers));
281 template <
typename T, vtkm::IdComponent NInner, vtkm::IdComponent NOuter>
282 VTKM_CONT static void AsArrayHandleBasic(
283 const std::vector<vtkm::cont::internal::Buffer>& buffers,
289 AsArrayHandleBasic(buffers, squashedArray);
326 template <
typename ComponentType>
329 vtkm::VecFromPortal<typename ArrayHandleBasic<ComponentType>::WritePortalType>,
330 vtkm::cont::StorageTagRuntimeVec>
355 :
Superclass(StorageType::CreateBuffers(numComponents, componentsArray))
362 return StorageType::GetNumberOfComponents(this->
GetBuffers());
371 return StorageType::GetComponentsArray(this->
GetBuffers());
380 template <
typename ValueType>
383 StorageType::AsArrayHandleBasic(this->
GetBuffers(), array);
387 template <
typename ArrayType>
404 template <
typename T>
410 using UnrolledVec = vtkm::internal::UnrollVec<T>;
411 using ComponentType =
typename UnrolledVec::ComponentType;
416 componentsArray.GetBuffers());
419 numComponents * UnrolledVec::NUM_COMPONENTS, flatComponents);
424 template <
typename T>
433 template <
typename T>
448 template <
typename T>
453 vtkm::cont::internal::BufferInfo::Deleter deleter = internal::SimpleArrayDeleter<T>,
454 vtkm::cont::internal::BufferInfo::Reallocater reallocater = internal::SimpleArrayReallocater<T>)
462 template <
typename T,
typename Allocator>
464 const std::vector<T, Allocator>& array,
472 template <
typename T,
typename Allocator>
474 std::vector<T, Allocator>&& array)
479 template <
typename T,
typename Allocator>
481 std::vector<T, Allocator>&& array,
493 template <
typename T>
498 using ComponentType =
typename T::ComponentType;
502 ArrayExtractComponentImpl<vtkm::cont::StorageTagBasic>{}(
503 array.GetComponentsArray(), componentIndex % NUM_SUB_COMPONENTS, allowCopy);
530 template <
typename T>
531 struct SerializableTypeString<
vtkm::cont::ArrayHandleRuntimeVec<T>>
540 template <
typename VecType>
541 struct SerializableTypeString<
vtkm::cont::ArrayHandle<VecType, vtkm::cont::StorageTagRuntimeVec>>
542 : SerializableTypeString<vtkm::cont::ArrayHandleRuntimeVec<typename VecType::ComponentType>>
552 template <
typename T>
553 struct Serialization<
vtkm::cont::ArrayHandleRuntimeVec<T>>
560 static VTKM_CONT void save(BinaryBuffer& bb,
const BaseType& obj)
562 vtkmdiy::save(bb, Type(obj).GetNumberOfComponents());
563 vtkmdiy::save(bb, Type(obj).GetComponentsArray());
578 template <
typename VecType>
579 struct Serialization<
vtkm::cont::ArrayHandle<VecType, vtkm::cont::StorageTagRuntimeVec>>
580 : Serialization<vtkm::cont::ArrayHandleRuntimeVec<typename VecType::ComponentType>>
587 #endif //vtk_m_cont_ArrayHandleRuntimeVec_h