Stratax
Scientific computing containers and operations
Loading...
Searching...
No Matches
Reshape.hpp
Go to the documentation of this file.
1#pragma once
2
12
25template<Array A>
27reshape(const A& arr, const stratax::core::Shape& shape)
28{
30 arr.size(),
31 shape.elements(),
32 "Shape mismatch.");
33
35
36 for (std::size_t i = 0; i < result.size(); ++i)
37 {
38 result[i] = arr[i];
39 }
40
41 return result;
42}
43
53template<Array A>
55flatten(const A& arr)
56{
58
59 for (std::size_t i = 0; i < arr.size(); ++i)
60 {
61 result[i] = arr[i];
62 }
63
64 return result;
65}
stratax::container::Vector< typename A::value_type > flatten(const A &arr)
Flattens an array-like object into a vector.
Definition Reshape.hpp:55
stratax::container::Tensor< typename A::value_type > reshape(const A &arr, const stratax::core::Shape &shape)
Reshapes an array-like object into a tensor with the requested shape.
Definition Reshape.hpp:27
Shared runtime validation helpers.
std::size_t size() const noexcept
Returns the total number of elements in the tensor.
Definition Tensor.hpp:114
Stores a list of dimension lengths for an array shape.
Definition Shape.hpp:20
std::size_t elements() const
Returns the total number of elements described by the shape.
Definition Shape.hpp:138
void require_equal_size(std::size_t lhs, std::size_t rhs, const char *message)
Requires two sizes to be equal.