Fail on construction of `StridedMemoryView` when unsupported strides are used
Since strides in SMV are defined as counts of itemsize, they are a subset of what Numpy can handle and we should make sure arrays we can't handle are properly rejected. It seems that this is /mostly/ the case, but due to the lazy construction, the exception happens a little later than ideal. For example:
def test_from_array_interface_exception(init_cuda):
# Create an array with strides that aren't a multiple of itemsize
x = np.array([(1, 2.0), (3, 4.0)], dtype=[("a", "i4"), ("b", "f8")])["b"]
# with pytest.raises(ValueError) as e:
smv = StridedMemoryView.from_array_interface(x)
with pytest.raises(ValueError) as e:
smv.strides
assert "strides must be divisible by itemsize" in str(e)
In user code, this could make it harder for the user to find the source of the error.
But given this is a latent bug that I think also applies to CAI, and not introduced by this PR, I'd be fine with (a) adding this test above, (b) creating a follow-up issue to detect this case during construction.
Originally posted by @mdboom in https://github.com/NVIDIA/cuda-python/pull/1428#discussion_r2665181777
I would prefer that we do no checks. The source provider (ex: cupy or our own StridedLayout, should we choose to make it public) is responsible for ensuring proper strides. SMV doing extra checks would just add overhead and it is unlikely actionable by the end users.