| 53 | } |
| 54 | |
| 55 | void get_slice_params( |
| 56 | mx::ShapeElem& starts, |
| 57 | mx::ShapeElem& ends, |
| 58 | mx::ShapeElem& strides, |
| 59 | const nb::slice& in_slice, |
| 60 | int axis_size) { |
| 61 | // Following numpy's convention |
| 62 | // Assume n is the number of elements in the dimension being sliced. |
| 63 | // Then, if i is not given it defaults to 0 for k > 0 and n - 1 for |
| 64 | // k < 0 . If j is not given it defaults to n for k > 0 and -n-1 for |
| 65 | // k < 0 . If k is not given it defaults to 1 |
| 66 | |
| 67 | strides = get_slice_int(nb::getattr(in_slice, "step"), 1); |
| 68 | starts = get_slice_int( |
| 69 | nb::getattr(in_slice, "start"), strides < 0 ? axis_size - 1 : 0); |
| 70 | ends = get_slice_int( |
| 71 | nb::getattr(in_slice, "stop"), strides < 0 ? -axis_size - 1 : axis_size); |
| 72 | } |
| 73 | |
| 74 | mx::array get_int_index(nb::object idx, int axis_size) { |
| 75 | int idx_ = safe_to_int32(idx); |
no test coverage detected