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

Function print_subarray

mlx/utils.cpp:216–239  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

214
215template <typename T>
216void print_subarray(std::ostream& os, const array& a, size_t index, int dim) {
217 int num_print = 3;
218 int n = a.shape(dim);
219 size_t s = a.strides()[dim];
220 bool is_last = dim == a.ndim() - 1;
221 auto prefix = is_last ? "" : std::string(7 + dim, ' ');
222 auto postfix = is_last ? ", " : ",\n";
223 os << "[";
224 for (int i = 0; i < n; ++i) {
225 os << (i == 0 ? "" : prefix);
226 if (i == num_print && n > 2 * num_print) {
227 os << "...";
228 i = n - num_print - 1;
229 index += s * (n - 2 * num_print - 1);
230 } else if (is_last) {
231 get_global_formatter().print(os, a.data<T>()[index]);
232 } else {
233 print_subarray<T>(os, a, index, dim + 1);
234 }
235 os << (i == n - 1 ? "" : postfix);
236 index += s;
237 }
238 os << "]";
239}
240
241template <typename T>
242void print_array(std::ostream& os, const array& a) {

Callers

nothing calls this directly

Calls 1

printMethod · 0.80

Tested by

no test coverage detected