Stratax 0.2.0
Loading...
Searching...
No Matches
Reshape

Reshape

Version: v0.2.0

Status: Complete

Header: include/stratax/core/algorithms/Reshape.hpp


Overview

Reshape.hpp provides shape-changing copy helpers that preserve flat storage order.

reshape returns a tensor with a requested shape, while flatten returns a rank-1 vector.


Responsibilities

The reshape module is responsible for:

  • Validating element-count compatibility for reshape operations
  • Copying values in flat storage order
  • Producing owning containers for reshaped/flattened output

The reshape module is not responsible for:

  • View-based reshape semantics
  • Inferred-dimension syntax (-1 style placeholders)
  • In-place shape mutation

Relationships

reshape(arr, shape)
├── validation::require_equal_size(arr.size(), shape.elements(), ...)
└── flat copy into Tensor
flatten(arr)
└── flat copy into Vector

Depends on:


Invariants

The following conditions are always true:

  • Reshape and flatten preserve flat element order.
  • reshape returns Tensor<value_type>.
  • flatten returns Vector<value_type>.
  • Output size equals source size.
  • Both operations return owning containers.

Public Interface

reshape

template<Array A>
reshape(const A& arr, const stratax::core::Shape& shape);
Stores an N-dimensional Stratax array in contiguous memory.
Definition Tensor.hpp:31
Stores a list of dimension lengths for an array shape.
Definition Shape.hpp:22

Throws

  • Exceptions::ShapeError when target shape element count differs from source size
  • Possible propagated shape/overflow exceptions from shape.elements()

Complexity

  • O(n + r)

flatten

template<Array A>
flatten(const A& arr);
Stores a rank-1 Stratax array in contiguous memory.
Definition Vector.hpp:27

Complexity

  • O(n)

Complexity Summary

Operation Complexity
reshape O(n + r)
flatten O(n)

n is element count and r is rank.


Examples

const auto t = reshape(vec, stratax::core::Shape(2, 3));
const auto v = flatten(t);

Design Notes

The module keeps behavior explicit and safe: reshape validates total size first and always performs a full copy.


Future Improvements

  • Add non-owning view reshape when view types exist
  • Add optional strict reshaping helpers with additional layout checks

See Also