Stratax 0.2.0
Loading...
Searching...
No Matches
Conversions

Conversions

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_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 a list of dimension lengths for an array shape.
Definition Shape.hpp:22

Container conversions

template<Array A>
template<Array A>
template<Array A>
Stores a rank-2 Stratax array in row-major order.
Definition Matrix.hpp:29
Stores an N-dimensional Stratax array in contiguous memory.
Definition Tensor.hpp:31
Stores a rank-1 Stratax array in contiguous memory.
Definition Vector.hpp:27

Throws

Type casting

template<typename To, typename From>
template<typename To, typename From>
template<typename To, typename From>
Matches all scalar types supported by Stratax numeric containers.
Definition Concepts.hpp:152

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