MCPcopy Create free account
hub / github.com/ml-explore/mlx / mlx_get_item_slice

Function mlx_get_item_slice

python/src/indexing.cpp:87–106  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

85}
86
87mx::array mlx_get_item_slice(const mx::array& src, const nb::slice& in_slice) {
88 // Check input and raise error if 0 dim for parity with np
89 if (src.ndim() == 0) {
90 throw std::invalid_argument(
91 "too many indices for array: array is 0-dimensional");
92 }
93
94 // Return a copy of the array if none slice is request
95 if (is_none_slice(in_slice)) {
96 return src;
97 }
98
99 mx::Shape starts(src.ndim(), 0);
100 auto ends = src.shape();
101 mx::Shape strides(src.ndim(), 1);
102
103 // Check and update slice params
104 get_slice_params(starts[0], ends[0], strides[0], in_slice, ends[0]);
105 return slice(src, starts, ends, strides);
106}
107
108mx::array mlx_get_item_array(const mx::array& src, const mx::array& indices) {
109 // Check input and raise error if 0 dim for parity with np

Callers 1

mlx_get_itemFunction · 0.85

Calls 3

is_none_sliceFunction · 0.85
get_slice_paramsFunction · 0.85
sliceFunction · 0.50

Tested by

no test coverage detected