Stratax
Scientific computing containers and operations
Toggle main menu visibility
Loading...
Searching...
No Matches
Reshape.hpp
Go to the documentation of this file.
1
#pragma once
2
3
#include <
stratax/core/Buffer.hpp
>
4
#include <
stratax/core/Concepts.hpp
>
5
#include <
stratax/core/Config.hpp
>
6
#include <
stratax/core/Exceptions.hpp
>
7
#include <
stratax/core/Shape.hpp
>
8
#include <
stratax/core/Validation.hpp
>
9
#include <
stratax/containers/Tensor.hpp
>
10
#include <
stratax/containers/Matrix.hpp
>
11
#include <
stratax/containers/Vector.hpp
>
12
25
template
<Array A>
26
stratax::container::Tensor<typename A::value_type>
27
reshape
(
const
A& arr,
const
stratax::core::Shape
& shape)
28
{
29
stratax::core::validation::require_equal_size
(
30
arr.size(),
31
shape.
elements
(),
32
"Shape mismatch."
);
33
34
stratax::container::Tensor<typename A::value_type>
result(shape);
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
53
template
<Array A>
54
stratax::container::Vector<typename A::value_type>
55
flatten
(
const
A& arr)
56
{
57
stratax::container::Vector<typename A::value_type>
result(arr.size());
58
59
for
(std::size_t i = 0; i < arr.size(); ++i)
60
{
61
result[i] = arr[i];
62
}
63
64
return
result;
65
}
Buffer.hpp
Concepts.hpp
Config.hpp
Exceptions.hpp
Matrix.hpp
flatten
stratax::container::Vector< typename A::value_type > flatten(const A &arr)
Flattens an array-like object into a vector.
Definition
Reshape.hpp:55
reshape
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
Shape.hpp
Tensor.hpp
Validation.hpp
Shared runtime validation helpers.
Vector.hpp
stratax::container::Tensor
Definition
Tensor.hpp:30
stratax::container::Tensor::size
std::size_t size() const noexcept
Returns the total number of elements in the tensor.
Definition
Tensor.hpp:114
stratax::container::Vector
Definition
Vector.hpp:27
stratax::core::Shape
Stores a list of dimension lengths for an array shape.
Definition
Shape.hpp:20
stratax::core::Shape::elements
std::size_t elements() const
Returns the total number of elements described by the shape.
Definition
Shape.hpp:138
stratax::core::validation::require_equal_size
void require_equal_size(std::size_t lhs, std::size_t rhs, const char *message)
Requires two sizes to be equal.
Definition
Validation.hpp:332
include
stratax
ops
Reshape.hpp
Generated by
1.17.0