Commit 13816bd
authored
Follow recommendation on the interaction with
The PR proposes to follow NEP-13
[recommendations](https://numpy.org/neps/nep-0013-ufunc-overrides.html#behavior-in-combination-with-python-s-binary-operations)
on how to interact with `numpy.ndarray` in binary the operations.
It will set `__array_ufunc__ = None` which means that dpnp implements
Python binary operations freely and so `numpy.ufuncs` called on this
argument will raise `TypeError`:
```python
a = numpy.ones(10)
b = dpnp.ones(10)
a += b
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[9], line 1
----> 1 a += b
TypeError: operand 'dpnp_array' does not support ufuncs (__array_ufunc__=None)
```
And an elementwise operation with `numpy.ndarray` will cause an explicit
exception in dpnp:
```python
a + b
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[4], line 1
----> 1 a + b
File ~/code/dpnp/dpnp/dpnp_array.py:518, in dpnp_array.__radd__(self, other)
516 def __radd__(self, other):
517 """Return ``value+self``."""
--> 518 return dpnp.add(other, self)
File ~/code/dpnp/dpnp/dpnp_algo/dpnp_elementwise_common.py:314, in DPNPBinaryFunc.__call__(self, x1, x2, out, where, order, dtype, subok, **kwargs)
303 def __call__(
304 self,
305 x1,
(...)
312 **kwargs,
313 ):
--> 314 dpnp.check_supported_arrays_type(
315 x1, x2, scalar_type=True, all_scalars=False
316 )
317 if kwargs:
318 raise NotImplementedError(
319 f"Requested function={self.name_} with kwargs={kwargs} "
320 "isn't currently supported."
321 )
File ~/code/dpnp/dpnp/dpnp_iface.py:400, in check_supported_arrays_type(scalar_type, all_scalars, *arrays)
397 if scalar_type and dpnp.isscalar(a):
398 continue
--> 400 raise TypeError(
401 f"An array must be any of supported type, but got {type(a)}"
402 )
404 if len(arrays) > 0 and not (all_scalars or any_is_array):
405 raise TypeError(
406 "At least one input must be of supported array type, "
407 "but got all scalars."
408 )
TypeError: An array must be any of supported type, but got <class 'numpy.ndarray'>
```
Previously it works as in a way:
```python
a = numpy.ones(10)
b = dpnp.ones(10)
a + b
# Out:
# array([array(2.), array(2.), array(2.), array(2.), array(2.), array(2.),
# array(2.), array(2.), array(2.), array(2.)], dtype=object)
```
Note, some updates in tests from #2260 have been mapped to that PR.numpy.ndarray in binary ops (#2266)1 parent 7ce5219 commit 13816bd
File tree
6 files changed
+52
-11
lines changed- dpnp
- tests
6 files changed
+52
-11
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
192 | 192 | | |
193 | 193 | | |
194 | 194 | | |
195 | | - | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
196 | 198 | | |
197 | 199 | | |
198 | 200 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
161 | 161 | | |
162 | 162 | | |
163 | 163 | | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
164 | 178 | | |
165 | 179 | | |
166 | 180 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| |||
768 | 769 | | |
769 | 770 | | |
770 | 771 | | |
771 | | - | |
| 772 | + | |
772 | 773 | | |
773 | 774 | | |
774 | 775 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1935 | 1935 | | |
1936 | 1936 | | |
1937 | 1937 | | |
1938 | | - | |
| 1938 | + | |
1939 | 1939 | | |
1940 | 1940 | | |
1941 | 1941 | | |
| |||
1953 | 1953 | | |
1954 | 1954 | | |
1955 | 1955 | | |
1956 | | - | |
| 1956 | + | |
1957 | 1957 | | |
1958 | 1958 | | |
1959 | 1959 | | |
| |||
1986 | 1986 | | |
1987 | 1987 | | |
1988 | 1988 | | |
1989 | | - | |
| 1989 | + | |
1990 | 1990 | | |
1991 | 1991 | | |
1992 | 1992 | | |
1993 | 1993 | | |
1994 | 1994 | | |
1995 | 1995 | | |
1996 | 1996 | | |
1997 | | - | |
| 1997 | + | |
1998 | 1998 | | |
1999 | 1999 | | |
2000 | 2000 | | |
| |||
2807 | 2807 | | |
2808 | 2808 | | |
2809 | 2809 | | |
2810 | | - | |
2811 | | - | |
2812 | | - | |
| 2810 | + | |
| 2811 | + | |
2813 | 2812 | | |
2814 | 2813 | | |
2815 | 2814 | | |
2816 | 2815 | | |
2817 | 2816 | | |
2818 | | - | |
| 2817 | + | |
2819 | 2818 | | |
2820 | 2819 | | |
2821 | 2820 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| |||
1232 | 1233 | | |
1233 | 1234 | | |
1234 | 1235 | | |
1235 | | - | |
| 1236 | + | |
| 1237 | + | |
| 1238 | + | |
| 1239 | + | |
1236 | 1240 | | |
1237 | 1241 | | |
1238 | 1242 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
150 | 150 | | |
151 | 151 | | |
152 | 152 | | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
153 | 174 | | |
154 | 175 | | |
155 | 176 | | |
| |||
0 commit comments