Repository navigation
Commit eec0aeb
authored
This PR fixes two kept-dimension shape bugs in
`dpnp.median`/`dpnp.nanmedian`.
**Empty kept dimension.** `dpnp.median` and `dpnp.nanmedian` raised
`ValueError` when called with a tuple (or list) `axis` and one of the
kept, non-reduced dimensions has size 0, e.g.
```
dpnp.median(dpnp.empty((0, 3, 4)), axis=(1, 2))
```
The sequence-axis path flattens the reduced axes in
`_flatten_array_along_axes` with `a.reshape(kept_shape + (-1,))`. The
`-1` cannot be inferred once the array has size 0 and a kept axis is
also 0 (every merged length yields a size-0 array, so the dimension is
ambiguous), which makes `reshape` raise. The merged length is now
computed explicitly with `math.prod(...)`, so the tuple-axis path
returns the same empty result as the single-axis path.
**Size-1 kept dimension.** `dpnp.nanmedian` dropped kept dimensions of
size 1 and returned the wrong shape, e.g. a `(1, 5)` array reduced over
`axis=1` returned shape `()` instead of `(1,)`. `_calc_nanmedian` ended
with an unconditional `dpnp.squeeze(res)`, which also removed
non-reduced size-1 axes; it now squeezes only the reduced trailing axis
with `dpnp.squeeze(res, axis=-1)`.
1 parent 6c3fca4 commit eec0aeb
4 files changed
Lines changed: 51 additions & 2 deletions
File tree
- dpnp
- dpnp_utils
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
110 | 110 | | |
111 | 111 | | |
112 | 112 | | |
| 113 | + | |
113 | 114 | | |
| 115 | + | |
114 | 116 | | |
115 | 117 | | |
116 | 118 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
| |||
88 | 89 | | |
89 | 90 | | |
90 | 91 | | |
91 | | - | |
| 92 | + | |
| 93 | + | |
92 | 94 | | |
93 | 95 | | |
94 | 96 | | |
| |||
102 | 104 | | |
103 | 105 | | |
104 | 106 | | |
105 | | - | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
106 | 111 | | |
107 | 112 | | |
108 | 113 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
413 | 413 | | |
414 | 414 | | |
415 | 415 | | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
416 | 444 | | |
417 | 445 | | |
418 | 446 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
944 | 944 | | |
945 | 945 | | |
946 | 946 | | |
| 947 | + | |
| 948 | + | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
947 | 961 | | |
948 | 962 | | |
949 | 963 | | |
| |||
0 commit comments