Commit 22a7650
committed
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. 13816bdnumpy.ndarray in binary ops (#2266)1 parent 6c67cc6 commit 22a7650
File tree
695 files changed
+1389
-1387
lines changed- _modules
- dpnp
- fft
- linalg
- random
- _static
- reference
- generated
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
695 files changed
+1389
-1387
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
| 17 | + | |
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
| 24 | + | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| |||
282 | 282 | | |
283 | 283 | | |
284 | 284 | | |
285 | | - | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
286 | 288 | | |
287 | 289 | | |
288 | 290 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
| 17 | + | |
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
| 24 | + | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
| 17 | + | |
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
| 24 | + | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
| 17 | + | |
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
| 24 | + | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
| 17 | + | |
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
| 24 | + | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
| 17 | + | |
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
| 24 | + | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
| 17 | + | |
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
| 24 | + | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
| 17 | + | |
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
| 24 | + | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
| 17 | + | |
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
| 24 | + | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| |||
0 commit comments