Skip to content
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
19 changes: 10 additions & 9 deletions dpnp/dpnp_iface_arraycreation.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
from dpnp.dpnp_utils import *

import dpnp.dpnp_container as dpnp_container
import dpctl.tensor as dpt


__all__ = [
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand Down
23 changes: 23 additions & 0 deletions tests/test_arraycreation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)