Stratax 0.2.0
Loading...
Searching...
No Matches
Reshape.hpp
1#pragma once
2
3#include <stratax/core/containers/Buffer.hpp>
4#include <stratax/core/Concepts.hpp>
5#include <stratax/core/Exceptions.hpp>
6#include <stratax/core/containers/Shape.hpp>
8#include <stratax/core/containers/Tensor.hpp>
9#include <stratax/core/containers/Matrix.hpp>
10#include <stratax/core/containers/Vector.hpp>
11
24template<Array A>
26reshape(const A& arr, const stratax::core::Shape& shape)
27{
28 stratax::core::validation::require_equal_size(
29 arr.size(),
30 shape.elements(),
31 "Shape mismatch.");
32
34
35 for (std::size_t i = 0; i < result.size(); ++i)
36 {
37 result[i] = arr[i];
38 }
39
40 return result;
41}
42
52template<Array A>
54flatten(const A& arr)
55{
57
58 for (std::size_t i = 0; i < arr.size(); ++i)
59 {
60 result[i] = arr[i];
61 }
62
63 return result;
64}
65
Shared runtime validation helpers.
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
Stores a list of dimension lengths for an array shape.
Definition Shape.hpp:22
std::size_t elements() const
Returns the total number of elements described by the shape.
Definition Shape.hpp:157