Stratax 0.4.0rc1
Loading...
Searching...
No Matches
Reshape.hpp File Reference

Copying reshape and flatten operations. More...

Include dependency graph for Reshape.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

template<Array A>
stratax::container::Tensor< typename A::value_type > stratax::manipulation::reshape (const A &arr, const stratax::core::Shape &shape)
 Copies a Stratax array or view into a tensor with a new shape.
 
template<Array A>
stratax::container::Vector< typename A::value_type > stratax::manipulation::flatten (const A &arr)
 Copies a Stratax array or view into a rank-one vector.
 

Detailed Description

Copying reshape and flatten operations.

Definition in file Reshape.hpp.

Function Documentation

◆ flatten()

template<Array A>
stratax::container::Vector< typename A::value_type > stratax::manipulation::flatten ( const A &  arr)

Copies a Stratax array or view into a rank-one vector.

Values retain the source array's flat row-major iterator order. The returned vector has shape {arr.size()} and owns storage independent of arr.

Template Parameters
AArray or view type satisfying Array.
Parameters
arrSource array to flatten.
Returns
Owning Vector with A::value_type and copied values.
Exceptions
std::bad_allocIf output allocation fails.
Complexity
O(arr.size()) for owning input; O(arr.size() * arr.rank()) for strided views.

Definition at line 69 of file Reshape.hpp.

◆ reshape()

template<Array A>
stratax::container::Tensor< typename A::value_type > stratax::manipulation::reshape ( const A &  arr,
const stratax::core::Shape &  shape 
)

Copies a Stratax array or view into a tensor with a new shape.

The target shape must describe exactly the same number of elements as the source. Values are copied in flat iterator order, so only the logical shape and row-major strides change. The returned tensor owns independent storage.

Template Parameters
AArray or view type satisfying Array.
Parameters
arrSource array whose flat element order is preserved.
shapeRequested shape of the returned tensor.
Returns
Owning Tensor with A::value_type, shape, and copied values.
Exceptions
Exceptions::DimensionErrorIf shape.elements() or a target stride cannot be represented.
Exceptions::ShapeErrorIf shape.elements() != arr.size().
std::bad_allocIf output storage or metadata allocation fails.
Complexity
O(arr.size() + shape.rank()) for owning input; O(arr.size() * arr.rank() + shape.rank()) for strided views.

Definition at line 39 of file Reshape.hpp.