Skip to content

Add property flags to dpnp_array #1265

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

Merged
merged 4 commits into from
Dec 24, 2022
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
9 changes: 8 additions & 1 deletion dpnp/dpnp_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,14 @@ def fill(self, value):
for i in range(self.size):
self.flat[i] = value

# 'flags',
@property
def flags(self):
"""
Return information about the memory layout of the array.

"""

return self._array_obj.flags

@property
def flat(self):
Expand Down
6 changes: 0 additions & 6 deletions tests/skipped_tests.tbl
Original file line number Diff line number Diff line change
Expand Up @@ -282,12 +282,6 @@ tests/third_party/cupy/core_tests/test_ndarray_reduction.py::TestCubReduction_pa
tests/third_party/cupy/core_tests/test_ndarray_reduction.py::TestCubReduction_param_6_{order='F', shape=(10, 20, 30)}::test_cub_min
tests/third_party/cupy/core_tests/test_ndarray_reduction.py::TestCubReduction_param_7_{order='F', shape=(10, 20, 30, 40)}::test_cub_max
tests/third_party/cupy/core_tests/test_ndarray_reduction.py::TestCubReduction_param_7_{order='F', shape=(10, 20, 30, 40)}::test_cub_min
tests/third_party/cupy/creation_tests/test_basic.py::TestBasic::test_empty_like_contiguity
tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_0_{shape=4}::test_empty_like_reshape_contiguity
tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_1_{shape=(4,)}::test_empty_like_reshape_contiguity
tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_2_{shape=(4, 2)}::test_empty_like_reshape_contiguity
tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_3_{shape=(4, 2, 3)}::test_empty_like_reshape_contiguity
tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_4_{shape=(5, 4, 2, 3)}::test_empty_like_reshape_contiguity
tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_0_{shape=4}::test_empty_like_K_strides_reshape
tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_0_{shape=4}::test_empty_like_reshape_contiguity2
tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_0_{shape=4}::test_empty_like_reshape_contiguity2_cupy_only
Expand Down
6 changes: 0 additions & 6 deletions tests/skipped_tests_gpu.tbl
Original file line number Diff line number Diff line change
Expand Up @@ -458,12 +458,6 @@ tests/third_party/cupy/core_tests/test_ndarray_reduction.py::TestCubReduction_pa
tests/third_party/cupy/core_tests/test_ndarray_reduction.py::TestCubReduction_param_6_{order='F', shape=(10, 20, 30)}::test_cub_min
tests/third_party/cupy/core_tests/test_ndarray_reduction.py::TestCubReduction_param_7_{order='F', shape=(10, 20, 30, 40)}::test_cub_max
tests/third_party/cupy/core_tests/test_ndarray_reduction.py::TestCubReduction_param_7_{order='F', shape=(10, 20, 30, 40)}::test_cub_min
tests/third_party/cupy/creation_tests/test_basic.py::TestBasic::test_empty_like_contiguity
tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_0_{shape=4}::test_empty_like_reshape_contiguity
tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_1_{shape=(4,)}::test_empty_like_reshape_contiguity
tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_2_{shape=(4, 2)}::test_empty_like_reshape_contiguity
tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_3_{shape=(4, 2, 3)}::test_empty_like_reshape_contiguity
tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_4_{shape=(5, 4, 2, 3)}::test_empty_like_reshape_contiguity
tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_0_{shape=4}::test_empty_like_K_strides_reshape
tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_0_{shape=4}::test_empty_like_reshape_contiguity2
tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_0_{shape=4}::test_empty_like_reshape_contiguity2_cupy_only
Expand Down
1 change: 0 additions & 1 deletion tests/test_arraycreation.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,6 @@ def test_full_like(array, fill_value, dtype, order):
assert_array_equal(func(numpy, a), func(dpnp, ia))


@pytest.mark.skip(reason="dpnp.ndarray.flags are not implemented")
@pytest.mark.parametrize("order1",
["F", "C"],
ids=['F', 'C'])
Expand Down
36 changes: 36 additions & 0 deletions tests/test_dparray.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import dpnp
import numpy
import pytest
import dpctl.tensor as dpt


@pytest.mark.parametrize("res_dtype",
Expand Down Expand Up @@ -32,3 +33,38 @@ def test_flatten(arr, arr_dtype):
expected = numpy_array.flatten()
result = dpnp_array.flatten()
numpy.testing.assert_array_equal(expected, result)


@pytest.mark.parametrize("shape",
[(), 0, (0,), (2), (5, 2), (5, 0, 2), (5, 3, 2)],
ids=['()', '0', '(0,)', '(2)', '(5, 2)', '(5, 0, 2)', '(5, 3, 2)'])
@pytest.mark.parametrize("order",
["C", "F"],
ids=['C', 'F'])
def test_flags(shape, order):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess, also it would be good to add a test of flags with different strides.

usm_array = dpt.usm_ndarray(shape, order=order)
numpy_array = numpy.ndarray(shape, order=order)
dpnp_array = dpnp.ndarray(shape, order=order)
assert usm_array.flags == dpnp_array.flags
assert numpy_array.flags.c_contiguous == dpnp_array.flags.c_contiguous
assert numpy_array.flags.f_contiguous == dpnp_array.flags.f_contiguous


@pytest.mark.parametrize("dtype",
[numpy.complex64, numpy.float32, numpy.int64, numpy.int32, numpy.bool],
ids=['complex64', 'float32', 'int64', 'int32', 'bool'])
@pytest.mark.parametrize("strides",
[(1, 4) , (4, 1)],
ids=['(1, 4)', '(4, 1)'])
@pytest.mark.parametrize("order",
["C", "F"],
ids=['C', 'F'])
def test_flags_strides(dtype, order, strides):
itemsize = numpy.dtype(dtype).itemsize
numpy_strides = tuple([el * itemsize for el in strides])
usm_array = dpt.usm_ndarray((4, 4), dtype=dtype, order=order, strides=strides)
numpy_array = numpy.ndarray((4, 4), dtype=dtype, order=order, strides=numpy_strides)
dpnp_array = dpnp.ndarray((4, 4), dtype=dtype, order=order, strides=strides)
assert usm_array.flags == dpnp_array.flags
assert numpy_array.flags.c_contiguous == dpnp_array.flags.c_contiguous
assert numpy_array.flags.f_contiguous == dpnp_array.flags.f_contiguous