10 #ifndef vtk_m_cont_ArrayHandleZip_h
11 #define vtk_m_cont_ArrayHandleZip_h
26 template <
typename PortalTypeFirst,
typename PortalTypeSecond>
29 using ReadableP1 = vtkm::internal::PortalSupportsGets<PortalTypeFirst>;
30 using ReadableP2 = vtkm::internal::PortalSupportsGets<PortalTypeSecond>;
31 using WritableP1 = vtkm::internal::PortalSupportsSets<PortalTypeFirst>;
32 using WritableP2 = vtkm::internal::PortalSupportsSets<PortalTypeSecond>;
34 using Readable = std::integral_constant<bool, ReadableP1::value && ReadableP2::value>;
35 using Writable = std::integral_constant<bool, WritableP1::value && WritableP2::value>;
38 using T =
typename PortalTypeFirst::ValueType;
39 using U =
typename PortalTypeSecond::ValueType;
51 ArrayPortalZip(
const PortalTypeFirst& portalfirst,
const PortalTypeSecond& portalsecond)
52 : PortalFirst(portalfirst)
53 , PortalSecond(portalsecond)
61 template <
class OtherF,
class OtherS>
62 VTKM_CONT ArrayPortalZip(
const ArrayPortalZip<OtherF, OtherS>& src)
63 : PortalFirst(src.GetFirstPortal())
64 , PortalSecond(src.GetSecondPortal())
70 vtkm::Id GetNumberOfValues()
const {
return this->PortalFirst.GetNumberOfValues(); }
73 template <
typename Readable_ = Readable,
74 typename =
typename std::enable_if<Readable_::value>::type>
77 return vtkm::make_Pair(this->PortalFirst.Get(index), this->PortalSecond.Get(index));
81 template <
typename Writable_ = Writable,
82 typename =
typename std::enable_if<Writable_::value>::type>
85 this->PortalFirst.Set(index, value.first);
86 this->PortalSecond.Set(index, value.second);
90 const PortalTypeFirst& GetFirstPortal()
const {
return this->PortalFirst; }
93 const PortalTypeSecond& GetSecondPortal()
const {
return this->PortalSecond; }
96 PortalTypeFirst PortalFirst;
97 PortalTypeSecond PortalSecond;
108 template <
typename ST1,
typename ST2>
119 template <
typename FirstHandleType,
typename SecondHandleType>
120 struct ArrayHandleZipTraits
137 template <
typename T1,
typename T2,
typename ST1,
typename ST2>
140 using FirstStorage = Storage<T1, ST1>;
141 using SecondStorage = Storage<T2, ST2>;
149 std::size_t SecondBuffersOffset;
152 VTKM_CONT static std::vector<vtkm::cont::internal::Buffer> FirstArrayBuffers(
153 const std::vector<vtkm::cont::internal::Buffer>& buffers)
155 const Info& info = buffers[0].GetMetaData<Info>();
156 return std::vector<vtkm::cont::internal::Buffer>(buffers.begin() + 1,
157 buffers.begin() + info.SecondBuffersOffset);
159 VTKM_CONT static std::vector<vtkm::cont::internal::Buffer> SecondArrayBuffers(
160 const std::vector<vtkm::cont::internal::Buffer>& buffers)
162 const Info& info = buffers[0].GetMetaData<
Info>();
163 return std::vector<vtkm::cont::internal::Buffer>(buffers.begin() + info.SecondBuffersOffset,
168 using ReadPortalType =
169 vtkm::exec::internal::ArrayPortalZip<
typename FirstStorage::ReadPortalType,
170 typename SecondStorage::ReadPortalType>;
171 using WritePortalType =
172 vtkm::exec::internal::ArrayPortalZip<
typename FirstStorage::WritePortalType,
173 typename SecondStorage::WritePortalType>;
175 static std::vector<vtkm::cont::internal::Buffer> CreateBuffers(
176 const FirstArrayType& firstArray = FirstArrayType{},
177 const SecondArrayType& secondArray = SecondArrayType{})
180 info.SecondBuffersOffset = 1 + firstArray.GetBuffers().size();
181 return vtkm::cont::internal::CreateBuffers(info, firstArray, secondArray);
185 const std::vector<vtkm::cont::internal::Buffer>&)
191 const std::vector<vtkm::cont::internal::Buffer>& buffers,
195 FirstStorage::ResizeBuffers(numValues, FirstArrayBuffers(buffers), preserve, token);
196 SecondStorage::ResizeBuffers(numValues, SecondArrayBuffers(buffers), preserve, token);
200 const std::vector<vtkm::cont::internal::Buffer>& buffers)
202 vtkm::Id numValues = FirstStorage::GetNumberOfValues(FirstArrayBuffers(buffers));
203 VTKM_ASSERT(numValues == SecondStorage::GetNumberOfValues(SecondArrayBuffers(buffers)));
207 VTKM_CONT static void Fill(
const std::vector<vtkm::cont::internal::Buffer>& buffers,
208 const ValueType& fillValue,
213 FirstStorage::Fill(FirstArrayBuffers(buffers), fillValue.first, startIndex, endIndex, token);
214 SecondStorage::Fill(SecondArrayBuffers(buffers), fillValue.second, startIndex, endIndex, token);
217 VTKM_CONT static ReadPortalType CreateReadPortal(
218 const std::vector<vtkm::cont::internal::Buffer>& buffers,
222 return ReadPortalType(
223 FirstStorage::CreateReadPortal(FirstArrayBuffers(buffers), device, token),
224 SecondStorage::CreateReadPortal(SecondArrayBuffers(buffers), device, token));
227 VTKM_CONT static WritePortalType CreateWritePortal(
228 const std::vector<vtkm::cont::internal::Buffer>& buffers,
232 return WritePortalType(
233 FirstStorage::CreateWritePortal(FirstArrayBuffers(buffers), device, token),
234 SecondStorage::CreateWritePortal(SecondArrayBuffers(buffers), device, token));
237 static FirstArrayType GetFirstArray(
const std::vector<vtkm::cont::internal::Buffer>& buffers)
239 return FirstArrayType(FirstArrayBuffers(buffers));
241 static SecondArrayType GetSecondArray(
const std::vector<vtkm::cont::internal::Buffer>& buffers)
243 return SecondArrayType(SecondArrayBuffers(buffers));
252 template <
typename FirstHandleType,
typename SecondHandleType>
254 :
public internal::ArrayHandleZipTraits<FirstHandleType, SecondHandleType>
::Superclass
272 ArrayHandleZip(
const FirstHandleType& firstArray,
const SecondHandleType& secondArray)
282 return StorageType::GetSecondArray(this->
GetBuffers());
289 template <
typename FirstHandleType,
typename SecondHandleType>
291 const FirstHandleType& first,
292 const SecondHandleType& second)
307 template <
typename AH1,
typename AH2>
308 struct SerializableTypeString<
vtkm::cont::ArrayHandleZip<AH1, AH2>>
318 template <
typename T1,
typename T2,
typename ST1,
typename ST2>
319 struct SerializableTypeString<
320 vtkm::cont::ArrayHandle<vtkm::Pair<T1, T2>, vtkm::cont::StorageTagZip<ST1, ST2>>>
321 : SerializableTypeString<vtkm::cont::ArrayHandleZip<vtkm::cont::ArrayHandle<T1, ST1>,
322 vtkm::cont::ArrayHandle<T2, ST2>>>
331 template <
typename AH1,
typename AH2>
332 struct Serialization<
vtkm::cont::ArrayHandleZip<AH1, AH2>>
339 static VTKM_CONT void save(BinaryBuffer& bb,
const BaseType& obj)
341 auto storage = obj.GetStorage();
342 vtkmdiy::save(bb, storage.GetFirstArray());
343 vtkmdiy::save(bb, storage.GetSecondArray());
358 template <
typename T1,
typename T2,
typename ST1,
typename ST2>
359 struct Serialization<
360 vtkm::cont::ArrayHandle<vtkm::Pair<T1, T2>, vtkm::cont::StorageTagZip<ST1, ST2>>>
361 : Serialization<vtkm::cont::ArrayHandleZip<vtkm::cont::ArrayHandle<T1, ST1>,
362 vtkm::cont::ArrayHandle<T2, ST2>>>
369 #endif //vtk_m_cont_ArrayHandleZip_h