Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes _from_input_shape_strides not validating order in all paths #1728

Merged
merged 2 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions dpctl/tensor/_stride_utils.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ cdef int _from_input_shape_strides(
cdef Py_ssize_t* shape_arr
cdef Py_ssize_t* strides_arr

if (int(order) not in [ord('C'), ord('F'), ord('c'), ord('f')]):
return ERROR_INCORRECT_ORDER

# 0-d array
if (nd == 0):
contig[0] = (USM_ARRAY_C_CONTIGUOUS | USM_ARRAY_F_CONTIGUOUS)
Expand Down Expand Up @@ -109,10 +112,6 @@ cdef int _from_input_shape_strides(
nelems[0] = elem_count
if (strides is None):
# no need to allocate and populate strides
if (int(order) not in [ord('C'), ord('F'), ord('c'), ord('f')]):
PyMem_Free(shape_ptr[0]);
shape_ptr[0] = <Py_ssize_t *>(<size_t>0)
return ERROR_INCORRECT_ORDER
if order == <char> ord('C') or order == <char> ord('c'):
contig[0] = USM_ARRAY_C_CONTIGUOUS
else:
Expand Down
4 changes: 4 additions & 0 deletions dpctl/tests/test_usm_ndarray_ctor.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,10 @@ def test_ctor_invalid_order():
get_queue_or_skip()
with pytest.raises(ValueError):
dpt.usm_ndarray((5, 5, 3), order="Z")
with pytest.raises(ValueError):
dpt.usm_ndarray((10), strides=(1,), order="Z")
with pytest.raises(ValueError):
dpt.usm_ndarray((), order="Z")


def test_ctor_buffer_kwarg():
Expand Down
Loading