Skip to content

Commit 6c2ad26

Browse files
committed
address comments
1 parent ff2dd42 commit 6c2ad26

File tree

6 files changed

+68
-25
lines changed

6 files changed

+68
-25
lines changed

dpnp/dpnp_algo/dpnp_elementwise_common.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,6 +1418,13 @@ def dpnp_multiply(x1, x2, out=None, order="K"):
14181418
def dpnp_negative(x, out=None, order="K"):
14191419
"""Invokes negative() from dpctl.tensor implementation for negative() function."""
14201420

1421+
# TODO: discuss with dpctl if the check is needed to be moved there
1422+
if not dpnp.isscalar(x) and x.dtype == dpnp.bool:
1423+
raise TypeError(
1424+
"DPNP boolean negative, the `-` operator, is not supported, "
1425+
"use the `~` operator or the logical_not function instead."
1426+
)
1427+
14211428
# dpctl.tensor only works with usm_ndarray
14221429
x1_usm = dpnp.get_usm_ndarray(x)
14231430
out_usm = None if out is None else dpnp.get_usm_ndarray(out)
@@ -1594,6 +1601,10 @@ def dpnp_right_shift(x1, x2, out=None, order="K"):
15941601
def dpnp_sign(x, out=None, order="K"):
15951602
"""Invokes sign() from dpctl.tensor implementation for sign() function."""
15961603

1604+
# TODO: discuss with dpctl if the check is needed to be moved there
1605+
if not dpnp.isscalar(x) and x.dtype == dpnp.bool:
1606+
raise TypeError("DPNP boolean sign is not supported.")
1607+
15971608
# dpctl.tensor only works with usm_ndarray
15981609
x1_usm = dpnp.get_usm_ndarray(x)
15991610
out_usm = None if out is None else dpnp.get_usm_ndarray(out)

dpnp/dpnp_iface_logic.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ def all(x, /, axis=None, out=None, keepdims=False, *, where=True):
9595
Returns
9696
-------
9797
dpnp.ndarray
98-
An array with a data type of `bool`
99-
containing the results of the logical AND reduction.
98+
An array with a data type of `bool`
99+
containing the results of the logical AND reduction.
100100
101101
Limitations
102102
-----------
@@ -160,8 +160,8 @@ def allclose(x1, x2, rtol=1.0e-5, atol=1.0e-8, **kwargs):
160160
161161
Limitations
162162
-----------
163-
Parameters ``x1`` and ``x2`` are supported as either :obj:`dpnp.ndarray` or scalar.
164-
Keyword arguments ``kwargs`` are currently unsupported.
163+
Parameters `x1` and `x2` are supported as either :class:`dpnp.ndarray` or scalar.
164+
Keyword argument `kwargs` is currently unsupported.
165165
Otherwise the functions will be executed sequentially on CPU.
166166
Input array data types are limited by supported DPNP :ref:`Data types`.
167167
@@ -276,7 +276,7 @@ def equal(
276276
Returns
277277
-------
278278
out : dpnp.ndarray
279-
Output array of bool type, element-wise comparison of `x1` and `x2`.
279+
Output array of bool type, element-wise comparison of `x1` and `x2`.
280280
281281
Limitations
282282
-----------
@@ -352,7 +352,7 @@ def greater(
352352
Returns
353353
-------
354354
out : dpnp.ndarray
355-
Output array of bool type, element-wise comparison of `x1` and `x2`.
355+
Output array of bool type, element-wise comparison of `x1` and `x2`.
356356
357357
Limitations
358358
-----------
@@ -422,7 +422,7 @@ def greater_equal(
422422
Returns
423423
-------
424424
out : dpnp.ndarray
425-
Output array of bool type, element-wise comparison of `x1` and `x2`.
425+
Output array of bool type, element-wise comparison of `x1` and `x2`.
426426
427427
Limitations
428428
-----------
@@ -480,8 +480,8 @@ def isclose(x1, x2, rtol=1e-05, atol=1e-08, equal_nan=False):
480480
481481
Limitations
482482
-----------
483-
``x2`` is supported to be integer if ``x1`` is :obj:`dpnp.ndarray` or
484-
at least either ``x1`` or ``x2`` should be as :obj:`dpnp.ndarray`.
483+
`x2` is supported to be integer if `x1` is :class:`dpnp.ndarray` or
484+
at least either `x1` or `x2` should be as :class:`dpnp.ndarray`.
485485
Otherwise the function will be executed sequentially on CPU.
486486
Input array data types are limited by supported DPNP :ref:`Data types`.
487487
@@ -678,7 +678,7 @@ def less(
678678
Returns
679679
-------
680680
out : dpnp.ndarray
681-
Output array of bool type, element-wise comparison of `x1` and `x2`.
681+
Output array of bool type, element-wise comparison of `x1` and `x2`.
682682
683683
Limitations
684684
-----------
@@ -748,7 +748,7 @@ def less_equal(
748748
Returns
749749
-------
750750
out : dpnp.ndarray
751-
Output array of bool type, element-wise comparison of `x1` and `x2`.
751+
Output array of bool type, element-wise comparison of `x1` and `x2`.
752752
753753
Limitations
754754
-----------
@@ -818,8 +818,8 @@ def logical_and(
818818
Returns
819819
-------
820820
out : dpnp.ndarray
821-
Boolean result of the logical AND operation applied to the elements
822-
of `x1` and `x2`; the shape is determined by broadcasting.
821+
Boolean result of the logical AND operation applied to the elements
822+
of `x1` and `x2`; the shape is determined by broadcasting.
823823
824824
Limitations
825825
-----------
@@ -891,8 +891,8 @@ def logical_not(
891891
Returns
892892
-------
893893
out : dpnp.ndarray
894-
Boolean result with the same shape as `x` of the NOT operation
895-
on elements of `x`.
894+
Boolean result with the same shape as `x` of the NOT operation
895+
on elements of `x`.
896896
897897
Limitations
898898
-----------
@@ -953,8 +953,8 @@ def logical_or(
953953
Returns
954954
-------
955955
out : dpnp.ndarray
956-
Boolean result of the logical OR operation applied to the elements
957-
of `x1` and `x2`; the shape is determined by broadcasting.
956+
Boolean result of the logical OR operation applied to the elements
957+
of `x1` and `x2`; the shape is determined by broadcasting.
958958
959959
Limitations
960960
-----------
@@ -1027,8 +1027,8 @@ def logical_xor(
10271027
Returns
10281028
-------
10291029
out : dpnp.ndarray
1030-
Boolean result of the logical XOR operation applied to the elements
1031-
of `x1` and `x2`; the shape is determined by broadcasting.
1030+
Boolean result of the logical XOR operation applied to the elements
1031+
of `x1` and `x2`; the shape is determined by broadcasting.
10321032
10331033
Limitations
10341034
-----------

dpnp/dpnp_iface_mathematical.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1507,7 +1507,7 @@ def negative(
15071507
Returns
15081508
-------
15091509
out : dpnp.ndarray
1510-
The numerical negative of each element of `x`.
1510+
The numerical negative of each element of `x`.
15111511
15121512
Limitations
15131513
-----------
@@ -1805,7 +1805,7 @@ def sign(
18051805
Returns
18061806
-------
18071807
out : dpnp.ndarray
1808-
The indication of the sign of each element of `x`.
1808+
The indication of the sign of each element of `x`.
18091809
18101810
Limitations
18111811
-----------
@@ -1814,6 +1814,7 @@ def sign(
18141814
Keyword argument `kwargs` is currently unsupported.
18151815
Otherwise the function will be executed sequentially on CPU.
18161816
Input array data types are limited by supported DPNP :ref:`Data types`.
1817+
However, if the input array data type is complex, the function will be executed sequentially on CPU.
18171818
18181819
Examples
18191820
--------

dpnp/dpnp_utils/dpnp_algo_utils.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ def call_origin(function, *args, **kwargs):
131131
if not allow_fallback and config.__DPNP_RAISE_EXCEPION_ON_NUMPY_FALLBACK__ == 1:
132132
raise NotImplementedError(f"Requested funtion={function.__name__} with args={args} and kwargs={kwargs} "
133133
"isn't currently supported and would fall back on NumPy implementation. "
134-
"Define enviroment variable `DPNP_RAISE_EXCEPION_ON_NUMPY_FALLBACK` to `0` "
135-
"if the fall back is required to be supported without rasing an exception.")
134+
"Define environment variable `DPNP_RAISE_EXCEPION_ON_NUMPY_FALLBACK` to `0` "
135+
"if the fall back is required to be supported without raising an exception.")
136136

137137
dpnp_inplace = kwargs.pop("dpnp_inplace", False)
138138
sycl_queue = kwargs.pop("sycl_queue", None)

tests/test_mathematical.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ def test_nancumsum(array):
392392
[[[1.0, -1.0], [0.1, -0.1]], [-2, -1, 0, 1, 2]],
393393
ids=["[[1., -1.], [0.1, -0.1]]", "[-2, -1, 0, 1, 2]"],
394394
)
395-
@pytest.mark.parametrize("dtype", get_all_dtypes(no_bool=True, no_complex=True))
395+
@pytest.mark.parametrize("dtype", get_all_dtypes(no_bool=True))
396396
def test_negative(data, dtype):
397397
np_a = numpy.array(data, dtype=dtype)
398398
dpnp_a = dpnp.array(data, dtype=dtype)
@@ -402,6 +402,35 @@ def test_negative(data, dtype):
402402
assert_allclose(result, expected)
403403

404404

405+
def test_negative_boolean():
406+
dpnp_a = dpnp.array([True, False])
407+
408+
with pytest.raises(TypeError):
409+
dpnp.negative(dpnp_a)
410+
411+
412+
@pytest.mark.parametrize(
413+
"data",
414+
[[2, 0, -2], [1.1, -1.1]],
415+
ids=["[2, 0, -2]", "[1.1, -1.1]"],
416+
)
417+
@pytest.mark.parametrize("dtype", get_all_dtypes(no_bool=True, no_complex=True))
418+
def test_sign(data, dtype):
419+
np_a = numpy.array(data, dtype=dtype)
420+
dpnp_a = dpnp.array(data, dtype=dtype)
421+
422+
result = dpnp.sign(dpnp_a)
423+
expected = numpy.sign(np_a)
424+
assert_allclose(result, expected)
425+
426+
427+
def test_sign_boolean():
428+
dpnp_a = dpnp.array([True, False])
429+
430+
with pytest.raises(TypeError):
431+
dpnp.sign(dpnp_a)
432+
433+
405434
@pytest.mark.parametrize("val_type", get_all_dtypes(no_none=True))
406435
@pytest.mark.parametrize("data_type", get_all_dtypes())
407436
@pytest.mark.parametrize("val", [1.5, 1, 5], ids=["1.5", "1", "5"])

tests/test_usm_type.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,10 @@ def test_meshgrid(usm_type_x, usm_type_y):
249249
"func,data",
250250
[
251251
pytest.param("ceil", [-1.7, -1.5, -0.2, 0.2, 1.5, 1.7, 2.0]),
252-
pytest.param("floor", [-1.7, -1.5, -0.2, 0.2, 1.5, 1.7, 2.0]),
253252
pytest.param("conjugate", [[1.0 + 1.0j, 0.0], [0.0, 1.0 + 1.0j]]),
253+
pytest.param("floor", [-1.7, -1.5, -0.2, 0.2, 1.5, 1.7, 2.0]),
254+
pytest.param("negative", [1.0, -1.0]),
255+
pytest.param("sign", [-5.0, 4.5]),
254256
pytest.param("sqrt", [1.0, 3.0, 9.0]),
255257
pytest.param("trunc", [-1.7, -1.5, -0.2, 0.2, 1.5, 1.7, 2.0]),
256258
],

0 commit comments

Comments
 (0)