From 6f52954cbb5e154ee4dc1c426887a0d4642c5bb3 Mon Sep 17 00:00:00 2001 From: Natalia Polina Date: Thu, 2 Feb 2023 02:46:08 -0600 Subject: [PATCH] Fixed gh-1272 --- dpnp/dpnp_iface_arraycreation.py | 19 ++++++++++--------- tests/test_arraycreation.py | 23 +++++++++++++++++++++++ 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/dpnp/dpnp_iface_arraycreation.py b/dpnp/dpnp_iface_arraycreation.py index 01b9ac6b792f..1740b1d6001a 100644 --- a/dpnp/dpnp_iface_arraycreation.py +++ b/dpnp/dpnp_iface_arraycreation.py @@ -48,6 +48,7 @@ from dpnp.dpnp_utils import * import dpnp.dpnp_container as dpnp_container +import dpctl.tensor as dpt __all__ = [ @@ -530,7 +531,7 @@ def empty_like(x1, Limitations ----------- - Parameters ``x1`` is supported only as :class:`dpnp.dpnp_array`. + Parameter ``x1`` is supported as :class:`dpnp.dpnp_array` or :class:`dpctl.tensor.usm_ndarray` Parameter ``order`` is supported with values ``"C"`` or ``"F"``. Parameter ``subok`` is supported only with default value ``False``. Otherwise the function will be executed sequentially on CPU. @@ -552,7 +553,7 @@ def empty_like(x1, """ - if not isinstance(x1, dpnp.ndarray): + if not isinstance(x1, (dpnp.ndarray, dpt.usm_ndarray)): pass elif order not in ('C', 'c', 'F', 'f', None): pass @@ -762,7 +763,7 @@ def full_like(x1, Limitations ----------- - Parameters ``x1`` is supported only as :class:`dpnp.dpnp_array`. + Parameter ``x1`` is supported as :class:`dpnp.dpnp_array` or :class:`dpctl.tensor.usm_ndarray` Parameter ``order`` is supported only with values ``"C"`` and ``"F"``. Parameter ``subok`` is supported only with default value ``False``. Otherwise the function will be executed sequentially on CPU. @@ -783,7 +784,7 @@ def full_like(x1, [1.0, 1.0, 1.0, 1.0, 1.0, 1.0] """ - if not isinstance(x1, dpnp.ndarray): + if not isinstance(x1, (dpnp.ndarray, dpt.usm_ndarray)): pass elif order not in ('C', 'c', 'F', 'f', None): pass @@ -1189,7 +1190,7 @@ def ones_like(x1, Limitations ----------- - Parameters ``x1`` is supported only as :class:`dpnp.dpnp_array`. + Parameter ``x1`` is supported as :class:`dpnp.dpnp_array` or :class:`dpctl.tensor.usm_ndarray` Parameter ``order`` is supported with values ``"C"`` or ``"F"``. Parameter ``subok`` is supported only with default value ``False``. Otherwise the function will be executed sequentially on CPU. @@ -1211,7 +1212,7 @@ def ones_like(x1, [1.0, 1.0, 1.0, 1.0, 1.0, 1.0] """ - if not isinstance(x1, dpnp.ndarray): + if not isinstance(x1, (dpnp.ndarray, dpt.usm_ndarray)): pass elif order not in ('C', 'c', 'F', 'f', None): pass @@ -1502,7 +1503,7 @@ def zeros_like(x1, Limitations ----------- - Parameters ``x1`` is supported only as :class:`dpnp.dpnp_array`. + Parameter ``x1`` is supported as :class:`dpnp.dpnp_array` or :class:`dpctl.tensor.usm_ndarray` Parameter ``order`` is supported with values ``"C"`` or ``"F"``. Parameter ``subok`` is supported only with default value ``False``. Otherwise the function will be executed sequentially on CPU. @@ -1523,8 +1524,8 @@ def zeros_like(x1, >>> [i for i in np.zeros_like(x)] [0.0, 0.0, 0.0, 0.0, 0.0, 0.0] -""" - if not isinstance(x1, dpnp.ndarray): + """ + if not isinstance(x1, (dpnp.ndarray, dpt.usm_ndarray)): pass elif order not in ('C', 'c', 'F', 'f', None): pass diff --git a/tests/test_arraycreation.py b/tests/test_arraycreation.py index d428b1ab7260..833ea6109c3c 100644 --- a/tests/test_arraycreation.py +++ b/tests/test_arraycreation.py @@ -485,3 +485,26 @@ def test_ones_like(array, dtype, order): a = numpy.array(array) ia = dpnp.array(array) assert_array_equal(func(numpy, a), func(dpnp, ia)) + + +@pytest.mark.parametrize( + "func, args", + [ + pytest.param("full_like", + ['x0', '4']), + pytest.param("zeros_like", + ['x0']), + pytest.param("ones_like", + ['x0']), + pytest.param("empty_like", + ['x0']), + ]) +def test_dpctl_tensor_input(func, args): + x0 = dpt.reshape(dpt.arange(9), (3,3)) + new_args = [eval(val, {'x0' : x0}) for val in args] + X = getattr(dpt, func)(*new_args) + Y = getattr(dpnp, func)(*new_args) + if func is 'empty_like': + assert X.shape == Y.shape + else: + assert_array_equal(X, Y)