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

Function to_list

python/src/convert.cpp:205–217  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

203
204template <typename T, typename U = T>
205nb::list to_list(mx::array& a, size_t index, int dim) {
206 nb::list pl;
207 auto stride = a.strides()[dim];
208 for (int i = 0; i < a.shape(dim); ++i) {
209 if (dim == a.ndim() - 1) {
210 pl.append(static_cast<U>(a.data<T>()[index]));
211 } else {
212 pl.append(to_list<T, U>(a, index, dim + 1));
213 }
214 index += stride;
215 }
216 return pl;
217}
218
219nb::object tolist(mx::array& a) {
220 if (a.ndim() == 0) {

Callers

nothing calls this directly

Calls 1

appendMethod · 0.80

Tested by

no test coverage detected