Stratax
0.2.0
Toggle main menu visibility
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>
7
#include <
stratax/core/validation/Validation.hpp
>
8
#include <stratax/core/containers/Tensor.hpp>
9
#include <stratax/core/containers/Matrix.hpp>
10
#include <stratax/core/containers/Vector.hpp>
11
24
template
<Array A>
25
stratax::container::Tensor<typename A::value_type>
26
reshape(
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
33
stratax::container::Tensor<typename A::value_type>
result(shape);
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
52
template
<Array A>
53
stratax::container::Vector<typename A::value_type>
54
flatten(
const
A& arr)
55
{
56
stratax::container::Vector<typename A::value_type>
result(arr.size());
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
Validation.hpp
Shared runtime validation helpers.
stratax::container::Tensor
Stores an N-dimensional Stratax array in contiguous memory.
Definition
Tensor.hpp:31
stratax::container::Vector
Stores a rank-1 Stratax array in contiguous memory.
Definition
Vector.hpp:27
stratax::core::Shape
Stores a list of dimension lengths for an array shape.
Definition
Shape.hpp:22
stratax::core::Shape::elements
std::size_t elements() const
Returns the total number of elements described by the shape.
Definition
Shape.hpp:157
include
stratax
core
algorithms
Reshape.hpp
Generated by
1.17.0