7#include <stratax/containers/Matrix.hpp>
8#include <stratax/containers/Tensor.hpp>
9#include <stratax/containers/Vector.hpp>
10#include <stratax/core/ArrayTraits.hpp>
11#include <stratax/core/dtypes/Concepts.hpp>
12#include <stratax/core/Shape.hpp>
13#include <stratax/exceptions/Exceptions.hpp>
15namespace stratax::conversion {
31inline bool is_vector_shape(
const stratax::core::Shape& shape)
33 if (shape.
rank() == 1)
38 std::size_t non_singleton = 0;
40 for (std::size_t dim : shape)
48 return non_singleton == 1;
63inline bool is_matrix_shape(
const stratax::core::Shape& shape)
65 if (shape.
rank() == 2)
70 std::size_t non_singleton = 0;
72 for (std::size_t dim : shape)
80 return non_singleton == 2;
97inline stratax::core::Shape matrix_shape(
const stratax::core::Shape& shape)
99 if (shape.
rank() == 2)
104 std::vector<std::size_t> dims;
107 for (std::size_t dim : shape)
115 return stratax::core::Shape(dims);
136stratax::container::Vector<typename A::value_type>
137to_vector(
const A& arr)
139 if (!detail::is_vector_shape(arr.shape()))
141 throw Exceptions::ShapeError(
142 "Array cannot be converted to a Vector.");
145 stratax::container::Vector<typename A::value_type> result(arr.size());
173stratax::container::Matrix<typename A::value_type>
174to_matrix(
const A& arr)
176 if (!detail::is_matrix_shape(arr.shape()))
178 throw Exceptions::ShapeError(
179 "Array cannot be converted to a Matrix.");
182 const stratax::core::Shape shape =
183 detail::matrix_shape(arr.shape());
185 stratax::container::Matrix<typename A::value_type> result(shape);
210stratax::container::Tensor<typename A::value_type>
211to_tensor(
const A& arr)
213 stratax::container::Tensor<typename A::value_type> result(arr.shape());
242template<DType To, Array A>
244stratax::core::rebind_array_t<A, To>
248 stratax::core::rebind_array_t<A, To>;
250 result_type result(arr.shape());
256 [](
const auto& value)
258 return static_cast<To>(value);
size_type rank() const noexcept
Returns the number of dimensions.