From 43f32df4ff7027928175ef0950a9361cbbb58db1 Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Sat, 28 Aug 2021 13:04:30 -0500 Subject: [PATCH 1/4] Improved coverage of _types.pxi --- dpctl/tests/test_usm_ndarray_ctor.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/dpctl/tests/test_usm_ndarray_ctor.py b/dpctl/tests/test_usm_ndarray_ctor.py index 6d565d8c88..fb26b1b0e9 100644 --- a/dpctl/tests/test_usm_ndarray_ctor.py +++ b/dpctl/tests/test_usm_ndarray_ctor.py @@ -74,6 +74,7 @@ def test_allocate_usm_ndarray(shape, usm_type): "f8", "c8", "c16", + b"float32", np.dtype("d"), np.half, ], @@ -83,6 +84,12 @@ def test_dtypes(dtype): assert Xusm.itemsize == np.dtype(dtype).itemsize +@pytest.mark.parametrize("dtype", ["", ">f4", "invalid", 123]) +def test_dtypes_invalid(dtype): + with pytest.raises((TypeError, ValueError)): + dpt.usm_ndarray((1,), dtype=dtype) + + def test_properties(): """ Test that properties execute From 0ee8e5f02ab54842f492df7c93e1c3697c3eacfa Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Mon, 30 Aug 2021 14:05:49 -0500 Subject: [PATCH 2/4] Improved coverage of _typing.pxi --- dpctl/tests/test_usm_ndarray_ctor.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/dpctl/tests/test_usm_ndarray_ctor.py b/dpctl/tests/test_usm_ndarray_ctor.py index fb26b1b0e9..ddb2b4ea85 100644 --- a/dpctl/tests/test_usm_ndarray_ctor.py +++ b/dpctl/tests/test_usm_ndarray_ctor.py @@ -82,6 +82,9 @@ def test_allocate_usm_ndarray(shape, usm_type): def test_dtypes(dtype): Xusm = dpt.usm_ndarray((1,), dtype=dtype) assert Xusm.itemsize == np.dtype(dtype).itemsize + expected_fmt = (np.dtype(dtype).str)[1:] + actual_fmt = Xusm.__sycl_usm_array_interface__["typestr"][1:] + assert expected_fmt == actual_fmt @pytest.mark.parametrize("dtype", ["", ">f4", "invalid", 123]) From 4530026e9d8a30770d072b5d281a7207d16aa607 Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Tue, 31 Aug 2021 12:43:47 -0500 Subject: [PATCH 3/4] Allow shape to be an integer in the constructor, e.g. `usm_ndarray(10, 'd')` ``` In [1]: import dpctl.tensor as dpt In [2]: dpt.usm_ndarray(10, 'd').shape Out[2]: (10,) ``` --- dpctl/tensor/_usmarray.pyx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/dpctl/tensor/_usmarray.pyx b/dpctl/tensor/_usmarray.pyx index 208975f970..e21b46e820 100644 --- a/dpctl/tensor/_usmarray.pyx +++ b/dpctl/tensor/_usmarray.pyx @@ -130,12 +130,17 @@ cdef class usm_ndarray: cdef Py_ssize_t _offset = offset cdef Py_ssize_t ary_min_displacement = 0 cdef Py_ssize_t ary_max_displacement = 0 + cdef Py_ssize_t tmp = 0 cdef char * data_ptr = NULL self._reset() if (not isinstance(shape, (list, tuple)) and not hasattr(shape, 'tolist')): - raise TypeError("Argument shape must be a list of a tuple.") + try: + tmp = shape + shape = [shape, ] + except Exception: + raise TypeError("Argument shape must be a list or a tuple.") nd = len(shape) typenum = dtype_to_typenum(dtype) itemsize = type_bytesize(typenum) From cd27e226915d1500768cf2a26da31857c67b1855 Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Tue, 31 Aug 2021 12:47:17 -0500 Subject: [PATCH 4/4] Test constructor for shape being an int --- dpctl/tests/test_usm_ndarray_ctor.py | 1 + 1 file changed, 1 insertion(+) diff --git a/dpctl/tests/test_usm_ndarray_ctor.py b/dpctl/tests/test_usm_ndarray_ctor.py index ddb2b4ea85..e1cd9e9795 100644 --- a/dpctl/tests/test_usm_ndarray_ctor.py +++ b/dpctl/tests/test_usm_ndarray_ctor.py @@ -38,6 +38,7 @@ (4, 5), (2, 5, 2), (2, 2, 2, 2, 2, 2, 2, 2), + 5, ], ) @pytest.mark.parametrize("usm_type", ["shared", "host", "device"])