18namespace stratax::conversion {
36 if (shape.
rank() == 1)
41 std::size_t non_singleton = 0;
43 for (std::size_t dim : shape)
51 return non_singleton == 1;
68 if (shape.
rank() == 2)
73 std::size_t non_singleton = 0;
75 for (std::size_t dim : shape)
83 return non_singleton == 2;
102 if (shape.
rank() == 2)
107 std::vector<std::size_t> dims;
110 for (std::size_t dim : shape)
142 if (!detail::is_vector_shape(arr.shape()))
145 "Array shape cannot be converted to a Vector.");
179 if (!detail::is_matrix_shape(arr.shape()))
182 "Array shape cannot be converted to a Matrix.");
186 detail::matrix_shape(arr.shape());
245template<DType To, Array A>
253 result_type result(arr.shape());
259 [](
const auto& value)
261 return static_cast<To>(value);
Result-container rebinding and promotion for owning arrays.
typename RebindArray< std::remove_cvref_t< A >, std::remove_cvref_t< T > >::type rebind_array_t
Convenience alias for rebinding an array to a new value type.
Dtype and array interface concepts.
bool is_matrix_shape(const stratax::core::Shape &shape)
Determines whether a shape can be represented by a Matrix.
stratax::container::Matrix< typename A::value_type > to_matrix(const A &arr)
Copies a matrix-compatible Stratax array into a Matrix.
stratax::container::Vector< typename A::value_type > to_vector(const A &arr)
Copies a vector-compatible Stratax array into a Vector.
stratax::core::Shape matrix_shape(const stratax::core::Shape &shape)
Produces the rank-two shape used by a matrix conversion.
stratax::container::Tensor< typename A::value_type > to_tensor(const A &arr)
Copies a Stratax array into a Tensor of the same shape.
stratax::core::rebind_array_t< A, To > astype(const A &arr)
Casts every element of a Stratax array to another dtype.
bool is_vector_shape(const stratax::core::Shape &shape)
Determines whether a shape can be represented by a Vector.
Stratax exception types derived from std::runtime_error.
Immutable dimension metadata and checked row-major strides.
Arbitrary-rank owning arrays; rank zero is empty.
Shape incompatible with the requested operation or container.
Two-dimensional owning array of supported dtype values.
Arbitrary-rank owning array of supported dtype values.
One-dimensional owning array of supported dtype values.
iterator begin() noexcept
Returns a mutable iterator to the first element.
Stores the dimensions of a multidimensional array.
size_type rank() const noexcept
Returns the number of dimensions.