From 68ac808dbda73167993a2ed6812fe30298601e58 Mon Sep 17 00:00:00 2001 From: Nikita Grigorian Date: Wed, 7 Jan 2026 01:07:12 -0800 Subject: [PATCH] usm_ndarray constructor uses offset when buffer is usm_ndarray this necessitates restricting the constructor to no longer permit arrays that aren't contiguous --- dpctl/tensor/_usmarray.pyx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/dpctl/tensor/_usmarray.pyx b/dpctl/tensor/_usmarray.pyx index 70bb4243f6..7fc4fccb8e 100644 --- a/dpctl/tensor/_usmarray.pyx +++ b/dpctl/tensor/_usmarray.pyx @@ -219,7 +219,9 @@ cdef class usm_ndarray: Offset of the array element with all zero indexes relative to the start of the provided `buffer` in elements. The argument is ignored if the ``buffer`` value is a string and the memory is allocated by - the constructor. Default: ``0``. + the constructor. If the ``buffer`` value is another + :class:`dpctl.tensor.usm_ndarray` instance, the provided offset is + added to the offset of the provided array. Default: ``0``. order ({"C", "F"}, optional): The memory layout of the array when constructing using a new allocation. Value ``"C"`` corresponds to C-contiguous, or row-major @@ -379,9 +381,15 @@ cdef class usm_ndarray: "".format(buffer) ) elif isinstance(buffer, usm_ndarray): + if not buffer.flags.contiguous: + self._cleanup() + raise ValueError( + "When buffer is usm_ndarray, it must be contiguous." + ) if not buffer.flags.writable: writable_flag = 0 _buffer = buffer.usm_data + _offset += buffer._element_offset else: self._cleanup() raise ValueError("buffer='{}' was not understood.".format(buffer))