5#include <stratax/core/containers/Matrix.hpp>
6#include <stratax/core/containers/Tensor.hpp>
7#include <stratax/core/containers/Vector.hpp>
8#include <stratax/core/Concepts.hpp>
9#include <stratax/core/Exceptions.hpp>
10#include <stratax/core/containers/Shape.hpp>
16 if (shape.
rank() == 1)
21 std::size_t non_singleton = 0;
23 for (std::size_t dim : shape)
31 return non_singleton == 1;
36 if (shape.
rank() == 2)
41 std::size_t non_singleton = 0;
43 for (std::size_t dim : shape)
51 return non_singleton == 2;
56 if (shape.
rank() == 2)
61 std::vector<std::size_t> dims;
62 dims.reserve(shape.
rank());
64 for (std::size_t dim : shape)
87to_vector(
const A& arr)
89 if (!is_vector_shape(arr.shape()))
92 "Array cannot be converted to a Vector."
98 for (std::size_t i = 0; i < arr.size(); ++i)
118to_matrix(
const A& arr)
120 if (!is_matrix_shape(arr.shape()))
123 "Array cannot be converted to a Matrix.");
126 const auto shape = matrix_shape(arr.shape());
129 for (std::size_t i = 0; i < arr.size(); ++i)
147to_tensor(
const A& arr)
151 for (std::size_t i = 0; i < arr.size(); ++i)
168template<
typename To,
typename From>
175 for (std::size_t i = 0; i < vec.
size(); ++i)
177 result[i] =
static_cast<To
>(vec[i]);
192template<
typename To,
typename From>
199 for (std::size_t i = 0; i < mat.
size(); ++i)
201 result[i] =
static_cast<To
>(mat[i]);
216template<
typename To,
typename From>
223 for (std::size_t i = 0; i < tensor.
size(); ++i)
225 result[i] =
static_cast<To
>(tensor[i]);
Shared runtime validation helpers.
Signals an invalid or incompatible shape.
Stores a rank-2 Stratax array in row-major order.
const stratax::core::Shape & shape() const noexcept
Returns the matrix shape.
std::size_t size() const noexcept
Returns the total number of elements in the matrix.
Stores an N-dimensional Stratax array in contiguous memory.
const core::Shape & shape() const noexcept
Returns the tensor shape.
std::size_t size() const noexcept
Returns the total number of elements in the tensor.
Stores a rank-1 Stratax array in contiguous memory.
const stratax::core::Shape & shape() const noexcept
Returns the vector shape.
std::size_t size() const noexcept
Returns the number of stored elements.
Stores a list of dimension lengths for an array shape.
std::size_t rank() const
Returns the number of stored dimensions.
Matches all scalar types supported by Stratax numeric containers.