Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
vtavana committed Aug 21, 2023
1 parent 1bd66be commit ce3d7b7
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 28 deletions.
11 changes: 11 additions & 0 deletions dpnp/dpnp_algo/dpnp_elementwise_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1418,6 +1418,13 @@ def dpnp_multiply(x1, x2, out=None, order="K"):
def dpnp_negative(x, out=None, order="K"):
"""Invokes negative() from dpctl.tensor implementation for negative() function."""

# TODO: discuss with dpctl if the check is needed to be moved there
if not dpnp.isscalar(x) and x.dtype == dpnp.bool:
raise TypeError(
"DPNP boolean negative, the `-` operator, is not supported, "
"use the `~` operator or the logical_not function instead."
)

# dpctl.tensor only works with usm_ndarray
x1_usm = dpnp.get_usm_ndarray(x)
out_usm = None if out is None else dpnp.get_usm_ndarray(out)
Expand Down Expand Up @@ -1594,6 +1601,10 @@ def dpnp_right_shift(x1, x2, out=None, order="K"):
def dpnp_sign(x, out=None, order="K"):
"""Invokes sign() from dpctl.tensor implementation for sign() function."""

# TODO: discuss with dpctl if the check is needed to be moved there
if not dpnp.isscalar(x) and x.dtype == dpnp.bool:
raise TypeError("DPNP boolean sign is not supported.")

# dpctl.tensor only works with usm_ndarray
x1_usm = dpnp.get_usm_ndarray(x)
out_usm = None if out is None else dpnp.get_usm_ndarray(out)
Expand Down
38 changes: 19 additions & 19 deletions dpnp/dpnp_iface_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ def all(x, /, axis=None, out=None, keepdims=False, *, where=True):
Returns
-------
dpnp.ndarray
An array with a data type of `bool`
containing the results of the logical AND reduction.
An array with a data type of `bool`
containing the results of the logical AND reduction.
Limitations
-----------
Expand Down Expand Up @@ -160,8 +160,8 @@ def allclose(x1, x2, rtol=1.0e-5, atol=1.0e-8, **kwargs):
Limitations
-----------
Parameters ``x1`` and ``x2`` are supported as either :obj:`dpnp.ndarray` or scalar.
Keyword arguments ``kwargs`` are currently unsupported.
Parameters `x1` and `x2` are supported as either :class:`dpnp.ndarray` or scalar.
Keyword argument `kwargs` is currently unsupported.
Otherwise the functions will be executed sequentially on CPU.
Input array data types are limited by supported DPNP :ref:`Data types`.
Expand Down Expand Up @@ -276,7 +276,7 @@ def equal(
Returns
-------
out : dpnp.ndarray
Output array of bool type, element-wise comparison of `x1` and `x2`.
Output array of bool type, element-wise comparison of `x1` and `x2`.
Limitations
-----------
Expand Down Expand Up @@ -352,7 +352,7 @@ def greater(
Returns
-------
out : dpnp.ndarray
Output array of bool type, element-wise comparison of `x1` and `x2`.
Output array of bool type, element-wise comparison of `x1` and `x2`.
Limitations
-----------
Expand Down Expand Up @@ -422,7 +422,7 @@ def greater_equal(
Returns
-------
out : dpnp.ndarray
Output array of bool type, element-wise comparison of `x1` and `x2`.
Output array of bool type, element-wise comparison of `x1` and `x2`.
Limitations
-----------
Expand Down Expand Up @@ -480,8 +480,8 @@ def isclose(x1, x2, rtol=1e-05, atol=1e-08, equal_nan=False):
Limitations
-----------
``x2`` is supported to be integer if ``x1`` is :obj:`dpnp.ndarray` or
at least either ``x1`` or ``x2`` should be as :obj:`dpnp.ndarray`.
`x2` is supported to be integer if `x1` is :class:`dpnp.ndarray` or
at least either `x1` or `x2` should be as :class:`dpnp.ndarray`.
Otherwise the function will be executed sequentially on CPU.
Input array data types are limited by supported DPNP :ref:`Data types`.
Expand Down Expand Up @@ -678,7 +678,7 @@ def less(
Returns
-------
out : dpnp.ndarray
Output array of bool type, element-wise comparison of `x1` and `x2`.
Output array of bool type, element-wise comparison of `x1` and `x2`.
Limitations
-----------
Expand Down Expand Up @@ -748,7 +748,7 @@ def less_equal(
Returns
-------
out : dpnp.ndarray
Output array of bool type, element-wise comparison of `x1` and `x2`.
Output array of bool type, element-wise comparison of `x1` and `x2`.
Limitations
-----------
Expand Down Expand Up @@ -818,8 +818,8 @@ def logical_and(
Returns
-------
out : dpnp.ndarray
Boolean result of the logical AND operation applied to the elements
of `x1` and `x2`; the shape is determined by broadcasting.
Boolean result of the logical AND operation applied to the elements
of `x1` and `x2`; the shape is determined by broadcasting.
Limitations
-----------
Expand Down Expand Up @@ -891,8 +891,8 @@ def logical_not(
Returns
-------
out : dpnp.ndarray
Boolean result with the same shape as `x` of the NOT operation
on elements of `x`.
Boolean result with the same shape as `x` of the NOT operation
on elements of `x`.
Limitations
-----------
Expand Down Expand Up @@ -953,8 +953,8 @@ def logical_or(
Returns
-------
out : dpnp.ndarray
Boolean result of the logical OR operation applied to the elements
of `x1` and `x2`; the shape is determined by broadcasting.
Boolean result of the logical OR operation applied to the elements
of `x1` and `x2`; the shape is determined by broadcasting.
Limitations
-----------
Expand Down Expand Up @@ -1027,8 +1027,8 @@ def logical_xor(
Returns
-------
out : dpnp.ndarray
Boolean result of the logical XOR operation applied to the elements
of `x1` and `x2`; the shape is determined by broadcasting.
Boolean result of the logical XOR operation applied to the elements
of `x1` and `x2`; the shape is determined by broadcasting.
Limitations
-----------
Expand Down
5 changes: 3 additions & 2 deletions dpnp/dpnp_iface_mathematical.py
Original file line number Diff line number Diff line change
Expand Up @@ -1507,7 +1507,7 @@ def negative(
Returns
-------
out : dpnp.ndarray
The numerical negative of each element of `x`.
The numerical negative of each element of `x`.
Limitations
-----------
Expand Down Expand Up @@ -1805,7 +1805,7 @@ def sign(
Returns
-------
out : dpnp.ndarray
The indication of the sign of each element of `x`.
The indication of the sign of each element of `x`.
Limitations
-----------
Expand All @@ -1814,6 +1814,7 @@ def sign(
Keyword argument `kwargs` is currently unsupported.
Otherwise the function will be executed sequentially on CPU.
Input array data types are limited by supported DPNP :ref:`Data types`.
However, if the input array data type is complex, the function will be executed sequentially on CPU.
Examples
--------
Expand Down
4 changes: 2 additions & 2 deletions dpnp/dpnp_utils/dpnp_algo_utils.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ def call_origin(function, *args, **kwargs):
if not allow_fallback and config.__DPNP_RAISE_EXCEPION_ON_NUMPY_FALLBACK__ == 1:
raise NotImplementedError(f"Requested funtion={function.__name__} with args={args} and kwargs={kwargs} "
"isn't currently supported and would fall back on NumPy implementation. "
"Define enviroment variable `DPNP_RAISE_EXCEPION_ON_NUMPY_FALLBACK` to `0` "
"if the fall back is required to be supported without rasing an exception.")
"Define environment variable `DPNP_RAISE_EXCEPION_ON_NUMPY_FALLBACK` to `0` "
"if the fall back is required to be supported without raising an exception.")

dpnp_inplace = kwargs.pop("dpnp_inplace", False)
sycl_queue = kwargs.pop("sycl_queue", None)
Expand Down
31 changes: 27 additions & 4 deletions tests/test_mathematical.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,14 +392,37 @@ def test_nancumsum(array):
[[[1.0, -1.0], [0.1, -0.1]], [-2, -1, 0, 1, 2]],
ids=["[[1., -1.], [0.1, -0.1]]", "[-2, -1, 0, 1, 2]"],
)
@pytest.mark.parametrize("dtype", get_all_dtypes(no_bool=True, no_complex=True))
@pytest.mark.parametrize("dtype", get_all_dtypes())
def test_negative(data, dtype):
np_a = numpy.array(data, dtype=dtype)
dpnp_a = dpnp.array(data, dtype=dtype)

result = dpnp.negative(dpnp_a)
expected = numpy.negative(np_a)
assert_allclose(result, expected)
if dtype == dpnp.bool:
with pytest.raises(TypeError):
dpnp.negative(dpnp_a)
else:
result = dpnp.negative(dpnp_a)
expected = numpy.negative(np_a)
assert_allclose(result, expected)


@pytest.mark.parametrize(
"data",
[[2, 0, -2], [1.1, -1.1]],
ids=["[2, 0, -2]", "[1.1, -1.1]"],
)
@pytest.mark.parametrize("dtype", get_all_dtypes(no_complex=True))
def test_sign(data, dtype):
np_a = numpy.array(data, dtype=dtype)
dpnp_a = dpnp.array(data, dtype=dtype)

if dtype == dpnp.bool:
with pytest.raises(TypeError):
dpnp.sign(dpnp_a)
else:
result = dpnp.sign(dpnp_a)
expected = numpy.sign(np_a)
assert_allclose(result, expected)


@pytest.mark.parametrize("val_type", get_all_dtypes(no_none=True))
Expand Down
4 changes: 3 additions & 1 deletion tests/test_usm_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,10 @@ def test_meshgrid(usm_type_x, usm_type_y):
"func,data",
[
pytest.param("ceil", [-1.7, -1.5, -0.2, 0.2, 1.5, 1.7, 2.0]),
pytest.param("floor", [-1.7, -1.5, -0.2, 0.2, 1.5, 1.7, 2.0]),
pytest.param("conjugate", [[1.0 + 1.0j, 0.0], [0.0, 1.0 + 1.0j]]),
pytest.param("floor", [-1.7, -1.5, -0.2, 0.2, 1.5, 1.7, 2.0]),
pytest.param("negative", [1.0, -1.0]),
pytest.param("sign", [-5.0, 4.5]),
pytest.param("sqrt", [1.0, 3.0, 9.0]),
pytest.param("trunc", [-1.7, -1.5, -0.2, 0.2, 1.5, 1.7, 2.0]),
],
Expand Down

0 comments on commit ce3d7b7

Please sign in to comment.