diff --git a/dpnp/dpnp_algo/dpnp_elementwise_common.py b/dpnp/dpnp_algo/dpnp_elementwise_common.py index 188bfe7d2a4..dd3a34369e3 100644 --- a/dpnp/dpnp_algo/dpnp_elementwise_common.py +++ b/dpnp/dpnp_algo/dpnp_elementwise_common.py @@ -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) @@ -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) diff --git a/dpnp/dpnp_iface_logic.py b/dpnp/dpnp_iface_logic.py index a560b71a1a6..d867bbbd660 100644 --- a/dpnp/dpnp_iface_logic.py +++ b/dpnp/dpnp_iface_logic.py @@ -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 ----------- @@ -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`. @@ -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 ----------- @@ -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 ----------- @@ -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 ----------- @@ -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`. @@ -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 ----------- @@ -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 ----------- @@ -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 ----------- @@ -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 ----------- @@ -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 ----------- @@ -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 ----------- diff --git a/dpnp/dpnp_iface_mathematical.py b/dpnp/dpnp_iface_mathematical.py index def99c6adbd..7552bcd2130 100644 --- a/dpnp/dpnp_iface_mathematical.py +++ b/dpnp/dpnp_iface_mathematical.py @@ -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 ----------- @@ -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 ----------- @@ -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 -------- diff --git a/dpnp/dpnp_utils/dpnp_algo_utils.pyx b/dpnp/dpnp_utils/dpnp_algo_utils.pyx index f88b42bde7f..9ec9174d400 100644 --- a/dpnp/dpnp_utils/dpnp_algo_utils.pyx +++ b/dpnp/dpnp_utils/dpnp_algo_utils.pyx @@ -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) diff --git a/tests/test_mathematical.py b/tests/test_mathematical.py index 5c8ca88088e..87d9610861a 100644 --- a/tests/test_mathematical.py +++ b/tests/test_mathematical.py @@ -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)) diff --git a/tests/test_usm_type.py b/tests/test_usm_type.py index d61331ffa08..4bf16022ba9 100644 --- a/tests/test_usm_type.py +++ b/tests/test_usm_type.py @@ -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]), ],