Stratax 0.3.1
Loading...
Searching...
No Matches
Conversions

Conversions

Version: v0.2.0

Status: Complete

Header: include/stratax/algorithms/Conversion.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_vector_shape(const stratax::core::Shape& shape);
bool is_matrix_shape(const stratax::core::Shape& shape);
stratax::core::Shape matrix_shape(const stratax::core::Shape& shape);
Stores the dimensions of a multidimensional array.
Definition Shape.hpp:33

Container conversions

template<Array A>
template<Array A>
template<Array A>
Two-dimensional owning array of numeric values.
Definition Matrix.hpp:46
Arbitrary-rank owning array of numeric values.
Definition Tensor.hpp:50
One-dimensional owning array of numeric values.
Definition Vector.hpp:44

Throws

Type casting

template<typename To, typename From>
template<typename To, typename From>
template<typename To, typename From>

Behavior

  • Uses static_cast<To> per element

Complexity Summary

Operation Complexity
is_vector_shape / is_matrix_shape O(r)
matrix_shape O(r)
to_vector / to_matrix / to_tensor O(n + r)
astype overloads O(n)

n is element count and r is rank.


Examples

const auto v = to_vector(tensor_like);
const auto m = to_matrix(tensor_like);
const auto t = to_tensor(matrix_like);
const auto as_double = astype<double>(v);

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