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

Function get_shape

python/src/convert.cpp:345–361  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

343
344template <typename T>
345void get_shape(T list, mx::Shape& shape) {
346 shape.push_back(check_shape_dim(nb::len(list)));
347 if (shape.back() > 0) {
348 auto l = list.begin();
349 if (nb::isinstance<nb::list>(*l)) {
350 return get_shape(nb::cast<nb::list>(*l), shape);
351 } else if (nb::isinstance<nb::tuple>(*l)) {
352 return get_shape(nb::cast<nb::tuple>(*l), shape);
353 } else if (nb::isinstance<mx::array>(*l)) {
354 auto arr = nb::cast<mx::array>(*l);
355 for (int i = 0; i < arr.ndim(); i++) {
356 shape.push_back(arr.shape(i));
357 }
358 return;
359 }
360 }
361}
362
363template <typename T>
364mx::array array_from_list_impl(

Callers 1

array_from_list_implFunction · 0.70

Calls 3

check_shape_dimFunction · 0.85
push_backMethod · 0.80
beginMethod · 0.45

Tested by

no test coverage detected