|
Stratax 0.4.0rc1
|
Header: include/stratax/algorithms/Conversion.hpp. Functions live under stratax::conversion.
| Function | Accepted shape | Result |
|---|---|---|
to_vector(arr) | Rank one, or exactly one extent different from one | Vector with source element count |
to_matrix(arr) | Rank two, or exactly two extents different from one | Matrix with original rank-two shape or the two retained extents |
to_tensor(arr) | Any valid source shape | Tensor with identical shape |
Each conversion copies values in logical row-major order into independent storage, including for strided C++ views. Only singleton extents are removed: {1, 0, 3} converts to Matrix {0, 3}. A higher-rank shape containing only ones is not vector- or matrix-compatible under these rules. Rank-zero arrays cannot convert to Vector/Matrix through these helpers; flatten provides a Vector copy. Invalid conversion shapes raise Exceptions::ShapeError. Shape arithmetic and allocation errors propagate.
astype<To>(arr) preserves the owning container family and shape and converts each element with static_cast<To>. Both dtypes must be supported and the cast must be valid. Narrowing and precision loss are not checked. The supplied RebindArray specializations cover owning containers, not ArrayView. Python does not currently bind astype.
Owning inputs take O(n + r) time; view inputs take O((n + 1)r), because logical access computes strided offsets. Output storage is O(n + r). Shape compatibility helpers in conversion::detail are implementation details. Python conversion functions accept the owning double Vector, Matrix, and Tensor classes; see Python API Reference.