10 #ifndef vtk_m_cont_ArrayHandleStride_h
11 #define vtk_m_cont_ArrayHandleStride_h
24 struct ArrayStrideInfo
32 ArrayStrideInfo() =
default;
39 : NumberOfValues(numValues)
50 if (this->Divisor > 1)
52 arrayIndex = arrayIndex / this->Divisor;
56 arrayIndex = arrayIndex % this->Modulo;
58 arrayIndex = (arrayIndex * this->Stride) + this->Offset;
64 class ArrayPortalStrideRead
66 const T* Array =
nullptr;
70 ArrayPortalStrideRead() =
default;
71 ArrayPortalStrideRead(ArrayPortalStrideRead&&) =
default;
72 ArrayPortalStrideRead(
const ArrayPortalStrideRead&) =
default;
73 ArrayPortalStrideRead& operator=(ArrayPortalStrideRead&&) =
default;
74 ArrayPortalStrideRead& operator=(
const ArrayPortalStrideRead&) =
default;
76 ArrayPortalStrideRead(
const T* array,
const ArrayStrideInfo& info)
91 return detail::ArrayPortalBasicReadGet(this->Array + this->Info.ArrayIndex(index));
94 VTKM_EXEC_CONT const ValueType* GetArray()
const {
return this->Array; }
95 VTKM_EXEC_CONT const ArrayStrideInfo& GetInfo()
const {
return this->Info; }
99 class ArrayPortalStrideWrite
102 ArrayStrideInfo
Info;
105 ArrayPortalStrideWrite() =
default;
106 ArrayPortalStrideWrite(ArrayPortalStrideWrite&&) =
default;
107 ArrayPortalStrideWrite(
const ArrayPortalStrideWrite&) =
default;
108 ArrayPortalStrideWrite& operator=(ArrayPortalStrideWrite&&) =
default;
109 ArrayPortalStrideWrite& operator=(
const ArrayPortalStrideWrite&) =
default;
111 ArrayPortalStrideWrite(T* array,
const ArrayStrideInfo& info)
126 return detail::ArrayPortalBasicWriteGet(this->Array + this->Info.ArrayIndex(index));
134 detail::ArrayPortalBasicWriteSet(this->Array + this->Info.ArrayIndex(index), value);
137 VTKM_EXEC_CONT ValueType* GetArray()
const {
return this->Array; }
138 VTKM_EXEC_CONT const ArrayStrideInfo& GetInfo()
const {
return this->Info; }
156 template <
typename T>
159 using StrideInfo = vtkm::internal::ArrayStrideInfo;
162 using ReadPortalType = vtkm::internal::ArrayPortalStrideRead<T>;
163 using WritePortalType = vtkm::internal::ArrayPortalStrideWrite<T>;
165 VTKM_CONT static StrideInfo& GetInfo(
const std::vector<vtkm::cont::internal::Buffer>& buffers)
167 return buffers[0].GetMetaData<StrideInfo>();
171 const std::vector<vtkm::cont::internal::Buffer>&)
177 const std::vector<vtkm::cont::internal::Buffer>& buffers)
179 return GetInfo(buffers).NumberOfValues;
183 const std::vector<vtkm::cont::internal::Buffer>& buffers,
187 StrideInfo& info = GetInfo(buffers);
189 if (info.NumberOfValues == numValues)
197 vtkm::Id resultLength = ((length - 1) / info.Divisor) + 1;
198 if ((info.Modulo > 0) && (info.Modulo < resultLength))
200 resultLength = info.Modulo;
204 vtkm::Id lastStridedIndex = lengthDivMod(numValues);
210 originalStride = info.Stride;
211 originalOffset = info.Offset;
218 originalStride = -info.Stride;
220 vtkm::Id originalSize = lengthDivMod(info.NumberOfValues);
224 originalOffset = originalSize - info.Offset - 1;
231 if (originalOffset >= originalStride)
240 "Cannot resize stride array with offset greater than stride (start of stride unknown).");
246 vtkm::Id lastIndex = lastStridedIndex * originalStride;
248 buffers[1].SetNumberOfBytes(
249 vtkm::internal::NumberOfValuesToNumberOfBytes<T>(lastIndex), preserve, token);
250 info.NumberOfValues = numValues;
257 info.Offset = lastIndex - originalOffset - 1;
261 VTKM_CONT static void Fill(
const std::vector<vtkm::cont::internal::Buffer>& buffers,
267 VTKM_CONT static ReadPortalType CreateReadPortal(
268 const std::vector<vtkm::cont::internal::Buffer>& buffers,
272 return ReadPortalType(
reinterpret_cast<const T*
>(buffers[1].ReadPointerDevice(device, token)),
276 VTKM_CONT static WritePortalType CreateWritePortal(
277 const std::vector<vtkm::cont::internal::Buffer>& buffers,
281 return WritePortalType(
reinterpret_cast<T*
>(buffers[1].WritePointerDevice(device, token)),
285 static std::vector<vtkm::cont::internal::Buffer> CreateBuffers(
286 const vtkm::cont::internal::Buffer& sourceBuffer = vtkm::cont::internal::Buffer{},
287 vtkm::internal::ArrayStrideInfo&& info = vtkm::internal::ArrayStrideInfo{})
289 return vtkm::cont::internal::CreateBuffers(info, sourceBuffer);
293 const std::vector<vtkm::cont::internal::Buffer>& buffers)
331 template <
typename T>
342 vtkm::cont::internal::Buffer{},
343 vtkm::internal::ArrayStrideInfo(0, stride, offset, modulo, divisor)))
355 array.GetBuffers()[0],
356 vtkm::internal::ArrayStrideInfo(numValues, stride, offset, modulo, divisor)))
368 vtkm::internal::ArrayStrideInfo(numValues, stride, offset, modulo, divisor)))
412 return StorageType::GetBasicArray(this->GetBuffers());
418 template <
typename T>
427 return { array, numValues, stride, offset, modulo, divisor };
440 template <
typename T>
441 VTKM_CONT inline void Storage<T, vtkm::cont::StorageTagStride>::Fill(
442 const std::vector<vtkm::cont::internal::Buffer>& buffers,
448 const StrideInfo& info = GetInfo(buffers);
450 if ((info.Stride == 1) && (info.Modulo == 0) && (info.Divisor <= 1))
453 basicArray.
Fill(fillValue, startIndex + info.Offset, endIndex + info.Offset, token);
462 const vtkm::Id numFill = endIndex - startIndex;
468 info.ArrayIndex(startIndex),
476 vtkm::cont::internal::ArrayCopyUnknown(constantArray, outputView);
492 template <
typename T>
493 struct SerializableTypeString<
vtkm::cont::ArrayHandleStride<T>>
502 template <
typename T>
503 struct SerializableTypeString<
vtkm::cont::ArrayHandle<T, vtkm::cont::StorageTagStride>>
504 : SerializableTypeString<vtkm::cont::ArrayHandleStride<T>>
514 template <
typename T>
515 struct Serialization<
vtkm::cont::ArrayHandleStride<T>>
521 static VTKM_CONT void save(BinaryBuffer& bb,
const BaseType& obj_)
539 vtkm::cont::internal::Buffer buffer;
557 #ifndef vtk_m_cont_ArrayHandleStride_cxx
596 #endif //vtk_m_cont_ArrayHandleStride_cxx
599 #endif //vtk_m_cont_ArrayHandleStride_h