Skip to content

Commit 09f3d47

Browse files
authored
Boolean subtract to raise TypeError exception (#1723)
* Boolean substruct raises TypeError exception in numpy, but ValueError in dpctl * Removed trailing whitespaces
1 parent 3324da4 commit 09f3d47

File tree

4 files changed

+26
-19
lines changed

4 files changed

+26
-19
lines changed

.github/workflows/build-sphinx.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ jobs:
107107
108108
- name: Install dpnp dependencies
109109
run: |
110-
conda install numpy"<1.24" dpctl">=0.16.0*" mkl-devel-dpcpp onedpl-devel tbb-devel dpcpp_linux-64"<2024.0.1" \
110+
conda install numpy"<1.24" dpctl">=0.17.0dev0" mkl-devel-dpcpp onedpl-devel tbb-devel dpcpp_linux-64"<2024.0.1" \
111111
cmake cython pytest ninja scikit-build sysroot_linux-64">=2.28" ${{ env.CHANNELS }}
112112
113113
- name: Install cuPy dependencies

.github/workflows/generate_coverage.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ jobs:
5050
run: |
5151
# use DPC++ compiler 2023.2 to work around an issue with crash
5252
conda install cython llvm cmake">=3.21" scikit-build ninja pytest pytest-cov coverage[toml] \
53-
dpctl">=0.16.0*" dpcpp_linux-64"=2023.2" sysroot_linux-64">=2.28" mkl-devel-dpcpp tbb-devel"=2021.10" \
53+
dpctl">=0.17.0dev0" dpcpp_linux-64"=2023.2" sysroot_linux-64">=2.28" mkl-devel-dpcpp tbb-devel"=2021.10" \
5454
onedpl-devel ${{ env.CHANNELS }}
5555
5656
- name: Conda info

conda-recipe/meta.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{% set required_compiler_and_mkl_version = "2024.0" %}
22
{% set excluded_compiler_version1 = "2024.0.1" %}
33
{% set excluded_compiler_version2 = "2024.0.2" %}
4-
{% set required_dpctl_version = "0.16.0*" %}
4+
{% set required_dpctl_version = "0.16.0" %}
55

66
package:
77
name: dpnp

dpnp/dpnp_algo/dpnp_elementwise_common.py

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2284,17 +2284,17 @@ def dpnp_multiply(x1, x2, out=None, order="K"):
22842284
def dpnp_negative(x, out=None, order="K"):
22852285
"""Invokes negative() from dpctl.tensor implementation for negative() function."""
22862286

2287-
# TODO: discuss with dpctl if the check is needed to be moved there
2287+
# dpctl.tensor only works with usm_ndarray
2288+
x1_usm = dpnp.get_usm_ndarray(x)
2289+
out_usm = None if out is None else dpnp.get_usm_ndarray(out)
2290+
2291+
# TODO: discuss with dpctl if the check is needed to be moved out of there
22882292
if not dpnp.isscalar(x) and x.dtype == dpnp.bool:
22892293
raise TypeError(
22902294
"DPNP boolean negative, the `-` operator, is not supported, "
22912295
"use the `~` operator or the logical_not function instead."
22922296
)
22932297

2294-
# dpctl.tensor only works with usm_ndarray
2295-
x1_usm = dpnp.get_usm_ndarray(x)
2296-
out_usm = None if out is None else dpnp.get_usm_ndarray(out)
2297-
22982298
res_usm = negative_func(x1_usm, out=out_usm, order=order)
22992299
return _get_result(res_usm, out=out)
23002300

@@ -2966,24 +2966,31 @@ def dpnp_subtract(x1, x2, out=None, order="K"):
29662966
Invokes sub() function from pybind11 extension of OneMKL VM if possible.
29672967
29682968
Otherwise fully relies on dpctl.tensor implementation for subtract() function.
2969-
"""
29702969
2971-
# TODO: discuss with dpctl if the check is needed to be moved there
2972-
if (
2973-
not dpnp.isscalar(x1)
2974-
and not dpnp.isscalar(x2)
2975-
and x1.dtype == x2.dtype == dpnp.bool
2976-
):
2977-
raise TypeError(
2978-
"DPNP boolean subtract, the `-` operator, is not supported, "
2979-
"use the bitwise_xor, the `^` operator, or the logical_xor function instead."
2980-
)
2970+
"""
29812971

29822972
# dpctl.tensor only works with usm_ndarray or scalar
29832973
x1_usm_or_scalar = dpnp.get_usm_ndarray_or_scalar(x1)
29842974
x2_usm_or_scalar = dpnp.get_usm_ndarray_or_scalar(x2)
29852975
out_usm = None if out is None else dpnp.get_usm_ndarray(out)
29862976

2977+
# TODO: discuss with dpctl if the check is needed to be moved out of there
2978+
boolean_subtract = False
2979+
if dpnp.isscalar(x1):
2980+
if isinstance(x1, bool) and x2.dtype == dpnp.bool:
2981+
boolean_subtract = True
2982+
elif dpnp.isscalar(x2):
2983+
if isinstance(x2, bool) and x1.dtype == dpnp.bool:
2984+
boolean_subtract = True
2985+
elif x1.dtype == x2.dtype == dpnp.bool:
2986+
boolean_subtract = True
2987+
2988+
if boolean_subtract:
2989+
raise TypeError(
2990+
"DPNP boolean subtract, the `-` operator, is not supported, "
2991+
"use the bitwise_xor, the `^` operator, or the logical_xor function instead."
2992+
)
2993+
29872994
res_usm = subtract_func(
29882995
x1_usm_or_scalar, x2_usm_or_scalar, out=out_usm, order=order
29892996
)

0 commit comments

Comments
 (0)