Version: v0.2.0
Status: Complete
Header: include/stratax/core/algorithms/Conversions.hpp
Overview
Conversions.hpp provides shape conversion and value-type casting helpers for Stratax array containers.
Helpers preserve flat storage order and return new owning containers.
Responsibilities
The conversions module is responsible for:
- Converting array-like containers to vector, matrix, or tensor forms
- Supporting shape compatibility checks for vector/matrix conversion
- Casting element types across vector/matrix/tensor containers
The conversions module is not responsible for:
- View-based conversion
- Implicit numeric safety checks beyond static_cast
- Runtime dtype-policy configuration
Relationships
to_vector / to_matrix / to_tensor
└── flat index copy loop
astype<To>(...)
└── per-element static_cast<To>
Depends on:
Invariants
The following conditions are always true:
- Conversions return new owning containers.
- Element order is preserved in flat storage order.
- to_vector accepts shapes that are rank-1 or have exactly one non-singleton dimension.
- to_matrix accepts shapes that are rank-2 or have exactly two non-singleton dimensions.
- to_tensor preserves original shape exactly.
- astype preserves shape and element count.
Public Interface
Shape helpers
bool is_matrix_shape(const stratax::core::Shape &shape)
bool is_vector_shape(const stratax::core::Shape &shape)
stratax::core::Shape matrix_shape(const stratax::core::Shape &shape)
Stores a list of dimension lengths for an array shape.
Container conversions
template<Array A>
template<Array A>
template<Array A>
stratax::container::Tensor< typename A::value_type > to_tensor(const A &arr)
Converts an array-like object to a tensor.
stratax::container::Matrix< typename A::value_type > to_matrix(const A &arr)
Converts an array-like object to a matrix.
stratax::container::Vector< typename A::value_type > to_vector(const A &arr)
Converts an array-like object to a vector.
Throws
Type casting
template<typename To, typename From>
template<typename To, typename From>
template<typename To, typename From>
stratax::container::Vector< To > astype(const stratax::container::Vector< From > &vec)
Casts a vector to a different numeric value type.
Matches all scalar types supported by Stratax numeric containers.
Behavior
- Uses static_cast<To> per element
Complexity Summary
n is element count and r is rank.
Examples
Design Notes
Vector/matrix conversion is intentionally permissive for singleton dimensions, which simplifies interoperability with tensor-shaped data that carries redundant axes.
Future Improvements
- Add explicit policy helpers for strict rank-only conversion
- Add optional checked-cast helpers for narrowing conversions
See Also