6#include <stratax/containers/Matrix.hpp>
7#include <stratax/containers/Tensor.hpp>
8#include <stratax/containers/Vector.hpp>
10namespace stratax::container {
15void print_value(std::ostream& os,
const T& value)
17 using type = std::remove_cvref_t<T>;
19 if constexpr (std::same_as<type, dtype::bool_>)
21 os << (value ?
"true" :
"false");
24 std::same_as<type, dtype::int8> ||
25 std::same_as<type, dtype::uint8>)
27 os << static_cast<int>(value);
43 const char* sibling_separator)
45 const auto& shape = array.shape();
46 const auto& strides = array.strides();
50 if (dim == shape.rank() - 1)
52 for (std::size_t i = 0; i < shape[dim]; ++i)
56 array[offset + i * strides[dim]]);
58 if (i + 1 != shape[dim])
66 for (std::size_t i = 0; i < shape[dim]; ++i)
68 os << std::string((depth + 1) * 4,
' ');
73 offset + i * strides[dim],
77 if (i + 1 != shape[dim])
79 os << sibling_separator;
84 os << std::string(depth * 4,
' ');
91std::ostream& print_tensor_like(
101 print_recursive(os, array, 0, 0, 0,
",\n");
106std::ostream& print_matrix_like(
116 print_recursive(os, array, 0, 0, 0,
"\n");
123std::ostream& operator<<(std::ostream& os,
const Vector<T>& vector)
125 return detail::print_tensor_like(os, vector);
129std::ostream& operator<<(std::ostream& os,
const Matrix<T>& matrix)
131 return detail::print_matrix_like(os, matrix);
135std::ostream& operator<<(std::ostream& os,
const Tensor<T>& tensor)
137 return detail::print_tensor_like(os, tensor);
Two-dimensional owning array of numeric values.
Arbitrary-rank owning array of numeric values.
One-dimensional owning array of numeric values.