10 #ifndef vtk_m_cont_ArrayHandlePermutation_h
11 #define vtk_m_cont_ArrayHandlePermutation_h
22 template <
typename IndexPortalType,
typename ValuePortalType>
25 using Writable = vtkm::internal::PortalSupportsSets<ValuePortalType>;
28 using ValueType =
typename ValuePortalType::ValueType;
31 ArrayPortalPermutation()
38 ArrayPortalPermutation(
const IndexPortalType& indexPortal,
const ValuePortalType& valuePortal)
39 : IndexPortal(indexPortal)
40 , ValuePortal(valuePortal)
49 template <
typename OtherIP,
typename OtherVP>
50 VTKM_EXEC_CONT ArrayPortalPermutation(
const ArrayPortalPermutation<OtherIP, OtherVP>& src)
51 : IndexPortal(src.GetIndexPortal())
52 , ValuePortal(src.GetValuePortal())
57 vtkm::Id GetNumberOfValues()
const {
return this->IndexPortal.GetNumberOfValues(); }
62 vtkm::Id permutedIndex = this->IndexPortal.Get(index);
63 return this->ValuePortal.Get(permutedIndex);
66 template <
typename Writable_ = Writable,
67 typename =
typename std::enable_if<Writable_::value>::type>
70 vtkm::Id permutedIndex = this->IndexPortal.Get(index);
71 this->ValuePortal.Set(permutedIndex, value);
75 const IndexPortalType& GetIndexPortal()
const {
return this->IndexPortal; }
78 const ValuePortalType& GetValuePortal()
const {
return this->ValuePortal; }
81 IndexPortalType IndexPortal;
82 ValuePortalType ValuePortal;
92 template <
typename IndexStorageTag,
typename ValueStorageTag>
100 template <
typename T,
typename IndexStorageTag,
typename ValueStorageTag>
104 (vtkm::cont::internal::IsValidArrayHandle<vtkm::Id, IndexStorageTag>::value),
105 "Invalid index storage tag.");
107 "Invalid value storage tag.");
109 using IndexStorage = vtkm::cont::internal::Storage<vtkm::Id, IndexStorageTag>;
110 using ValueStorage = vtkm::cont::internal::Storage<T, ValueStorageTag>;
117 std::size_t ValueBufferOffset;
120 VTKM_CONT static std::vector<vtkm::cont::internal::Buffer> IndexBuffers(
121 const std::vector<vtkm::cont::internal::Buffer>& buffers)
123 Info info = buffers[0].GetMetaData<Info>();
124 return std::vector<vtkm::cont::internal::Buffer>(buffers.begin() + 1,
125 buffers.begin() + info.ValueBufferOffset);
127 VTKM_CONT static std::vector<vtkm::cont::internal::Buffer> ValueBuffers(
128 const std::vector<vtkm::cont::internal::Buffer>& buffers)
130 Info info = buffers[0].GetMetaData<Info>();
131 return std::vector<vtkm::cont::internal::Buffer>(buffers.begin() + info.ValueBufferOffset,
138 using ReadPortalType =
139 vtkm::internal::ArrayPortalPermutation<
typename IndexStorage::ReadPortalType,
140 typename ValueStorage::ReadPortalType>;
141 using WritePortalType =
142 vtkm::internal::ArrayPortalPermutation<
typename IndexStorage::ReadPortalType,
143 typename ValueStorage::WritePortalType>;
146 const std::vector<vtkm::cont::internal::Buffer>& buffers)
148 return IndexStorage::GetNumberOfValues(IndexBuffers(buffers));
151 VTKM_CONT static void Fill(
const std::vector<vtkm::cont::internal::Buffer>&,
160 VTKM_CONT static ReadPortalType CreateReadPortal(
161 const std::vector<vtkm::cont::internal::Buffer>& buffers,
165 return ReadPortalType(IndexStorage::CreateReadPortal(IndexBuffers(buffers), device, token),
166 ValueStorage::CreateReadPortal(ValueBuffers(buffers), device, token));
169 VTKM_CONT static WritePortalType CreateWritePortal(
170 const std::vector<vtkm::cont::internal::Buffer>& buffers,
175 return WritePortalType(IndexStorage::CreateReadPortal(IndexBuffers(buffers), device, token),
176 ValueStorage::CreateWritePortal(ValueBuffers(buffers), device, token));
179 VTKM_CONT static std::vector<vtkm::cont::internal::Buffer> CreateBuffers(
180 const IndexArray& indexArray = IndexArray{},
181 const ValueArray& valueArray = ValueArray{})
184 info.ValueBufferOffset = 1 + indexArray.GetBuffers().size();
185 return vtkm::cont::internal::CreateBuffers(info, indexArray, valueArray);
188 VTKM_CONT static IndexArray GetIndexArray(
189 const std::vector<vtkm::cont::internal::Buffer>& buffers)
191 return IndexArray(IndexBuffers(buffers));
194 VTKM_CONT static ValueArray GetValueArray(
195 const std::vector<vtkm::cont::internal::Buffer>& buffers)
197 return ValueArray(ValueBuffers(buffers));
226 template <
typename IndexArrayHandleType,
typename ValueArrayHandleType>
229 typename ValueArrayHandleType::ValueType,
230 vtkm::cont::StorageTagPermutation<typename IndexArrayHandleType::StorageTag,
231 typename ValueArrayHandleType::StorageTag>>
239 (std::is_same<vtkm::Id, typename IndexArrayHandleType::ValueType>::value),
240 "Permutation array in ArrayHandlePermutation must have vtkm::Id value type.");
247 typename ValueArrayHandleType::ValueType,
249 typename ValueArrayHandleType::StorageTag>>));
252 using StorageType = vtkm::cont::internal::Storage<ValueType, StorageTag>;
257 const ValueArrayHandleType& valueArray)
258 : Superclass(
StorageType::CreateBuffers(indexArray, valueArray))
264 return StorageType::GetIndexArray(this->
GetBuffers());
269 return StorageType::GetValueArray(this->
GetBuffers());
277 template <
typename IndexArrayHandleType,
typename ValueArrayHandleType>
294 template <
typename IdxAH,
typename ValAH>
295 struct SerializableTypeString<
vtkm::cont::ArrayHandlePermutation<IdxAH, ValAH>>
305 template <
typename T,
typename IdxST,
typename ValST>
306 struct SerializableTypeString<
307 vtkm::cont::ArrayHandle<T, vtkm::cont::StorageTagPermutation<IdxST, ValST>>>
308 : SerializableTypeString<
309 vtkm::cont::ArrayHandlePermutation<vtkm::cont::ArrayHandle<vtkm::Id, IdxST>,
310 vtkm::cont::ArrayHandle<T, ValST>>>
319 template <
typename IdxAH,
typename ValAH>
320 struct Serialization<
vtkm::cont::ArrayHandlePermutation<IdxAH, ValAH>>
327 static VTKM_CONT void save(BinaryBuffer& bb,
const BaseType& obj)
329 vtkmdiy::save(bb, Type(obj).GetIndexArray());
330 vtkmdiy::save(bb, Type(obj).GetValueArray());
345 template <
typename T,
typename IdxST,
typename ValST>
346 struct Serialization<
vtkm::cont::ArrayHandle<T, vtkm::cont::StorageTagPermutation<IdxST, ValST>>>
347 : Serialization<vtkm::cont::ArrayHandlePermutation<vtkm::cont::ArrayHandle<vtkm::Id, IdxST>,
348 vtkm::cont::ArrayHandle<T, ValST>>>
355 #endif //vtk_m_cont_ArrayHandlePermutation_h