Stratax 0.4.0rc1
Loading...
Searching...
No Matches
Reshape.hpp
Go to the documentation of this file.
1
4// TODO: Consider zero-copy reshape/flatten views once view support is implemented.
5
6#pragma once
7
8#include <algorithm>
9
15
16namespace stratax::manipulation {
17
36template<Array A>
37[[nodiscard]]
39reshape(const A& arr, const stratax::core::Shape& shape)
40{
41 const auto target_size = shape.elements();
42 if (arr.size() != target_size)
43 {
45 "Reshape must preserve the number of elements.");
46 }
47
49 std::copy(arr.begin(), arr.end(), result.begin());
50
51 return result;
52}
53
66template<Array A>
67[[nodiscard]]
69flatten(const A& arr)
70{
72 std::copy(arr.begin(), arr.end(), result.begin());
73
74 return result;
75}
76
77} // namespace stratax::manipulation
Dtype and array interface concepts.
Stratax exception types derived from std::runtime_error.
stratax::container::Tensor< typename A::value_type > reshape(const A &arr, const stratax::core::Shape &shape)
Copies a Stratax array or view into a tensor with a new shape.
Definition Reshape.hpp:39
stratax::container::Vector< typename A::value_type > flatten(const A &arr)
Copies a Stratax array or view into a rank-one vector.
Definition Reshape.hpp:69
Immutable dimension metadata and checked row-major strides.
Arbitrary-rank owning arrays; rank zero is empty.
Rank-one owning arrays.
Shape incompatible with the requested operation or container.
Arbitrary-rank owning array of supported dtype values.
Definition Tensor.hpp:54
One-dimensional owning array of supported dtype values.
Definition Vector.hpp:47
iterator begin() noexcept
Returns a mutable iterator to the first element.
Stores the dimensions of a multidimensional array.
Definition Shape.hpp:36
size_type elements() const
Computes the total number of elements described by the shape.
Definition Shape.hpp:94