| 214 | |
| 215 | template <typename T> |
| 216 | void 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 | |
| 241 | template <typename T> |
| 242 | void print_array(std::ostream& os, const array& a) { |