|
3 | 3 | from hypothesis.control import assume
|
4 | 4 |
|
5 | 5 | from . import _array_module as xp
|
6 |
| -from . import array_helpers as ah |
7 | 6 | from . import dtype_helpers as dh
|
8 | 7 | from . import hypothesis_helpers as hh
|
9 | 8 | from . import pytest_helpers as ph
|
10 | 9 | from . import xps
|
11 |
| -from .test_manipulation_functions import assert_equals, axis_ndindex |
| 10 | +from .test_manipulation_functions import assert_equals |
| 11 | +from .test_statistical_functions import axes_ndindex, normalise_axis |
12 | 12 |
|
13 | 13 |
|
14 | 14 | # TODO: generate kwargs
|
@@ -45,25 +45,21 @@ def test_sort(x, data):
|
45 | 45 | ph.assert_dtype("sort", out.dtype, x.dtype)
|
46 | 46 | ph.assert_shape("sort", out.shape, x.shape, **kw)
|
47 | 47 | axis = kw.get("axis", -1)
|
48 |
| - _axis = axis if axis >= 0 else x.ndim + axis |
| 48 | + axes = normalise_axis(axis, x.ndim) |
49 | 49 | descending = kw.get("descending", False)
|
50 | 50 | scalar_type = dh.get_scalar_type(x.dtype)
|
51 |
| - for idx in axis_ndindex(x.shape, _axis): |
52 |
| - f_idx = ", ".join(str(i) if isinstance(i, int) else ":" for i in idx) |
53 |
| - indexed_x = x[idx] |
54 |
| - indexed_out = out[idx] |
55 |
| - out_indices = list(ah.ndindex(indexed_x.shape)) |
56 |
| - elements = [scalar_type(indexed_x[idx2]) for idx2 in out_indices] |
| 51 | + for indices in axes_ndindex(x.shape, axes): |
| 52 | + elements = [scalar_type(x[idx]) for idx in indices] |
57 | 53 | indices_order = sorted(
|
58 |
| - range(len(out_indices)), key=elements.__getitem__, reverse=descending |
| 54 | + range(len(indices)), key=elements.__getitem__, reverse=descending |
59 | 55 | )
|
60 |
| - x_indices = [out_indices[o] for o in indices_order] |
61 |
| - for out_idx, x_idx in zip(out_indices, x_indices): |
| 56 | + x_indices = [indices[o] for o in indices_order] |
| 57 | + for out_idx, x_idx in zip(indices, x_indices): |
62 | 58 | assert_equals(
|
63 | 59 | "sort",
|
64 |
| - f"x[{f_idx}][{x_idx}]", |
65 |
| - indexed_x[x_idx], |
66 |
| - f"out[{f_idx}][{out_idx}]", |
67 |
| - indexed_out[out_idx], |
| 60 | + f"x[{x_idx}]", |
| 61 | + x[x_idx], |
| 62 | + f"out[{out_idx}]", |
| 63 | + out[out_idx], |
68 | 64 | **kw,
|
69 | 65 | )
|
0 commit comments