Skip to content

Commit 62fa3ab

Browse files
authored
Add property flags to dpnp_array (#1265)
* Add property flags to dpnp_array * Added more tests for dpnp_array.flags * Added more dtype for dpnp_flags test.
1 parent f125604 commit 62fa3ab

File tree

5 files changed

+44
-14
lines changed

5 files changed

+44
-14
lines changed

dpnp/dpnp_array.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,14 @@ def fill(self, value):
578578
for i in range(self.size):
579579
self.flat[i] = value
580580

581-
# 'flags',
581+
@property
582+
def flags(self):
583+
"""
584+
Return information about the memory layout of the array.
585+
586+
"""
587+
588+
return self._array_obj.flags
582589

583590
@property
584591
def flat(self):

tests/skipped_tests.tbl

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -282,12 +282,6 @@ tests/third_party/cupy/core_tests/test_ndarray_reduction.py::TestCubReduction_pa
282282
tests/third_party/cupy/core_tests/test_ndarray_reduction.py::TestCubReduction_param_6_{order='F', shape=(10, 20, 30)}::test_cub_min
283283
tests/third_party/cupy/core_tests/test_ndarray_reduction.py::TestCubReduction_param_7_{order='F', shape=(10, 20, 30, 40)}::test_cub_max
284284
tests/third_party/cupy/core_tests/test_ndarray_reduction.py::TestCubReduction_param_7_{order='F', shape=(10, 20, 30, 40)}::test_cub_min
285-
tests/third_party/cupy/creation_tests/test_basic.py::TestBasic::test_empty_like_contiguity
286-
tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_0_{shape=4}::test_empty_like_reshape_contiguity
287-
tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_1_{shape=(4,)}::test_empty_like_reshape_contiguity
288-
tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_2_{shape=(4, 2)}::test_empty_like_reshape_contiguity
289-
tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_3_{shape=(4, 2, 3)}::test_empty_like_reshape_contiguity
290-
tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_4_{shape=(5, 4, 2, 3)}::test_empty_like_reshape_contiguity
291285
tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_0_{shape=4}::test_empty_like_K_strides_reshape
292286
tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_0_{shape=4}::test_empty_like_reshape_contiguity2
293287
tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_0_{shape=4}::test_empty_like_reshape_contiguity2_cupy_only

tests/skipped_tests_gpu.tbl

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -458,12 +458,6 @@ tests/third_party/cupy/core_tests/test_ndarray_reduction.py::TestCubReduction_pa
458458
tests/third_party/cupy/core_tests/test_ndarray_reduction.py::TestCubReduction_param_6_{order='F', shape=(10, 20, 30)}::test_cub_min
459459
tests/third_party/cupy/core_tests/test_ndarray_reduction.py::TestCubReduction_param_7_{order='F', shape=(10, 20, 30, 40)}::test_cub_max
460460
tests/third_party/cupy/core_tests/test_ndarray_reduction.py::TestCubReduction_param_7_{order='F', shape=(10, 20, 30, 40)}::test_cub_min
461-
tests/third_party/cupy/creation_tests/test_basic.py::TestBasic::test_empty_like_contiguity
462-
tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_0_{shape=4}::test_empty_like_reshape_contiguity
463-
tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_1_{shape=(4,)}::test_empty_like_reshape_contiguity
464-
tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_2_{shape=(4, 2)}::test_empty_like_reshape_contiguity
465-
tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_3_{shape=(4, 2, 3)}::test_empty_like_reshape_contiguity
466-
tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_4_{shape=(5, 4, 2, 3)}::test_empty_like_reshape_contiguity
467461
tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_0_{shape=4}::test_empty_like_K_strides_reshape
468462
tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_0_{shape=4}::test_empty_like_reshape_contiguity2
469463
tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_0_{shape=4}::test_empty_like_reshape_contiguity2_cupy_only

tests/test_arraycreation.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,6 @@ def test_full_like(array, fill_value, dtype, order):
506506
assert_array_equal(func(numpy, a), func(dpnp, ia))
507507

508508

509-
@pytest.mark.skip(reason="dpnp.ndarray.flags are not implemented")
510509
@pytest.mark.parametrize("order1",
511510
["F", "C"],
512511
ids=['F', 'C'])

tests/test_dparray.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import dpnp
22
import numpy
33
import pytest
4+
import dpctl.tensor as dpt
45

56

67
@pytest.mark.parametrize("res_dtype",
@@ -32,3 +33,38 @@ def test_flatten(arr, arr_dtype):
3233
expected = numpy_array.flatten()
3334
result = dpnp_array.flatten()
3435
numpy.testing.assert_array_equal(expected, result)
36+
37+
38+
@pytest.mark.parametrize("shape",
39+
[(), 0, (0,), (2), (5, 2), (5, 0, 2), (5, 3, 2)],
40+
ids=['()', '0', '(0,)', '(2)', '(5, 2)', '(5, 0, 2)', '(5, 3, 2)'])
41+
@pytest.mark.parametrize("order",
42+
["C", "F"],
43+
ids=['C', 'F'])
44+
def test_flags(shape, order):
45+
usm_array = dpt.usm_ndarray(shape, order=order)
46+
numpy_array = numpy.ndarray(shape, order=order)
47+
dpnp_array = dpnp.ndarray(shape, order=order)
48+
assert usm_array.flags == dpnp_array.flags
49+
assert numpy_array.flags.c_contiguous == dpnp_array.flags.c_contiguous
50+
assert numpy_array.flags.f_contiguous == dpnp_array.flags.f_contiguous
51+
52+
53+
@pytest.mark.parametrize("dtype",
54+
[numpy.complex64, numpy.float32, numpy.int64, numpy.int32, numpy.bool],
55+
ids=['complex64', 'float32', 'int64', 'int32', 'bool'])
56+
@pytest.mark.parametrize("strides",
57+
[(1, 4) , (4, 1)],
58+
ids=['(1, 4)', '(4, 1)'])
59+
@pytest.mark.parametrize("order",
60+
["C", "F"],
61+
ids=['C', 'F'])
62+
def test_flags_strides(dtype, order, strides):
63+
itemsize = numpy.dtype(dtype).itemsize
64+
numpy_strides = tuple([el * itemsize for el in strides])
65+
usm_array = dpt.usm_ndarray((4, 4), dtype=dtype, order=order, strides=strides)
66+
numpy_array = numpy.ndarray((4, 4), dtype=dtype, order=order, strides=numpy_strides)
67+
dpnp_array = dpnp.ndarray((4, 4), dtype=dtype, order=order, strides=strides)
68+
assert usm_array.flags == dpnp_array.flags
69+
assert numpy_array.flags.c_contiguous == dpnp_array.flags.c_contiguous
70+
assert numpy_array.flags.f_contiguous == dpnp_array.flags.f_contiguous

0 commit comments

Comments
 (0)