Skip to content

dpt.usm_ndarray does not validate order argument when strides keyword is passed #1724

@antonwolfy

Description

@antonwolfy

The values of order argument is not validating when strides keyword is passed:

import dpctl, dpctl.tensor as dpt

dpctl.__version__
# Out: '0.18.0dev0+77.g26d34f565d'


# `order` does not pass a validation check:
dpt.usm_ndarray((2, 3), numpy.float32, order='!')
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[7], line 1
----> 1 dpt.usm_ndarray((2, 3), numpy.float32, order='!')

File dpctl/tensor/_usmarray.pyx:264, in dpctl.tensor._usmarray.usm_ndarray.__cinit__()

ValueError: Unsupported order='!' given. Supported values are 'C' or 'F'.


# no validation error for `order` when `strides` keyword used:
dpt.usm_ndarray((2, 3), numpy.float32, strides=(2, 1), order='!')
# Out:
# usm_ndarray([[0., 0., 0.],
#              [0., 0., 0.]], dtype=float32)


# while numpy validates the order values:
numpy.ndarray((2, 3), numpy.float32, strides=(2, 1), order='!')
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[10], line 1
----> 1 numpy.ndarray((2, 3), numpy.float32, strides=(2, 1), order='!')

ValueError: order must be one of 'C', 'F', 'A', or 'K' (got '!')

I guess it might be because the order value isn't used by the constructor of usm_ndarray in that case.
But I guess it would be good to have the validation check for order anyway.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions