Disable resizing of ArrayHandleStride

The typical use case of `ArrayHandleStride` is to flexibly point into
another array, often looking at a single component in an array. It is
typical that multiple things will be accessing the same array, and bad
things could happen as they all try to resize. There was some code to
try to figure out what the size of the original array was, but it was
fragile.

It is safer for now to disable the behavior altogether. If a use case
pops up, we can reintroduce the code.
This commit is contained in:
Kenneth Moreland 2020-12-15 13:50:58 -07:00
parent 760553725c
commit 0f24f82dad
3 changed files with 5 additions and 39 deletions

@ -53,7 +53,7 @@ ArrayExtractComponentFallback(const vtkm::cont::ArrayHandle<T, S>& src,
using BaseComponentType = typename vtkm::VecTraits<T>::BaseComponentType;
vtkm::Id numValues = src.GetNumberOfValues();
vtkm::cont::ArrayHandleStride<BaseComponentType> dest;
vtkm::cont::ArrayHandleBasic<BaseComponentType> dest;
dest.Allocate(numValues);
auto srcPortal = src.ReadPortal();
auto destPortal = dest.WritePortal();
@ -63,7 +63,7 @@ ArrayExtractComponentFallback(const vtkm::cont::ArrayHandle<T, S>& src,
vtkm::internal::GetFlatVecComponent(srcPortal.Get(arrayIndex), componentIndex));
}
return dest;
return vtkm::cont::ArrayHandleStride<BaseComponentType>(dest, numValues, 1, 0);
}
template <typename S>

@ -157,6 +157,8 @@ class VTKM_ALWAYS_EXPORT Storage<T, vtkm::cont::StorageTagStride>
using StrideInfo = vtkm::internal::ArrayStrideInfo;
public:
VTKM_STORAGE_NO_RESIZE;
using ReadPortalType = vtkm::internal::ArrayPortalStrideRead<T>;
using WritePortalType = vtkm::internal::ArrayPortalStrideWrite<T>;
@ -167,42 +169,6 @@ public:
VTKM_CONT static vtkm::IdComponent GetNumberOfBuffers() { return 2; }
VTKM_CONT static void ResizeBuffers(vtkm::Id numberOfValues,
vtkm::cont::internal::Buffer* buffers,
vtkm::CopyFlag preserve,
vtkm::cont::Token& token)
{
StrideInfo& info = GetInfo(buffers);
vtkm::Id arraySize;
if (info.Modulo < 1)
{
if (info.Offset < info.Stride)
{
arraySize = numberOfValues * info.Stride;
}
else
{
// This is probably an uncommon case. Offset is most often used to identify components
// in AOS arrays. That must not be the case here.
arraySize = (numberOfValues - 1) * info.Stride + info.Offset + 1;
}
}
else
{
arraySize = info.Modulo;
}
if (info.Divisor > 1)
{
arraySize /= info.Divisor;
}
buffers[1].SetNumberOfBytes(
vtkm::internal::NumberOfValuesToNumberOfBytes<T>(arraySize), preserve, token);
info.NumberOfValues = numberOfValues;
}
VTKM_CONT static vtkm::Id GetNumberOfValues(const vtkm::cont::internal::Buffer* buffers)
{
return GetInfo(buffers).NumberOfValues;

@ -150,7 +150,7 @@ void DoTest()
{
vtkm::cont::ArrayHandleStride<vtkm::Vec3f> strideArray(
originalArray, ARRAY_SIZE, STRIDE, offset);
CheckOutputArray(strideArray);
CheckInputArray(strideArray);
}
}