7#include <stratax/core/containers/Matrix.hpp>
8#include <stratax/core/containers/Tensor.hpp>
9#include <stratax/core/containers/Vector.hpp>
10#include <stratax/core/algorithms/Conversions.hpp>
11#include <stratax/core/containers/Shape.hpp>
13namespace stratax::container {
28void print_tensor_recursive(
30 const Tensor<T>& tensor,
34 const char* sibling_separator)
36 const auto& shape = tensor.shape();
37 const auto& strides = tensor.strides();
41 if (dim == shape.rank() - 1)
43 for (std::size_t i = 0; i < shape(dim); ++i)
45 os << tensor(offset + i * strides(dim));
47 if (i + 1 != shape(dim))
55 for (std::size_t i = 0; i < shape(dim); ++i)
57 os << std::string((depth + 1) * 4,
' ');
58 print_tensor_recursive(
62 offset + i * strides(dim),
66 if (i + 1 != shape(dim))
68 os << sibling_separator;
73 os << std::string(depth * 4,
' ');
80std::ostream& print_tensor_like(std::ostream& os,
const Tensor<T>& tensor)
82 if (tensor.shape().elements() == 0)
88 print_tensor_recursive(os, tensor, 0, 0, 0,
",\n");
93std::ostream& print_matrix_like(std::ostream& os,
const Tensor<T>& tensor)
95 print_tensor_recursive(os, tensor, 0, 0, 0,
"\n");
110std::ostream& operator<<(std::ostream& os,
const Vector<T>& vector)
112 const auto tensor = to_tensor(vector);
113 return detail::print_tensor_like(os, tensor);
125std::ostream& operator<<(std::ostream& os,
const Matrix<T>& matrix)
127 const auto tensor = to_tensor(matrix);
128 return detail::print_matrix_like(os, tensor);
143std::ostream& operator<<(std::ostream& os,
const Tensor<T>& tensor)
145 return detail::print_tensor_like(os, tensor);
Stores a rank-2 Stratax array in row-major order.
Stores an N-dimensional Stratax array in contiguous memory.
Stores a rank-1 Stratax array in contiguous memory.