Tannic
A C++ Tensor Library
|
Expression template for viewing a tensor with a new shape. More...
#include <views.hpp>
Public Member Functions | |
template<Integral... Sizes> | |
constexpr | View (typename Trait< Source >::Reference source, Sizes... sizes) |
Construct a reshaped view of the source tensor. | |
constexpr type | dtype () const |
constexpr Shape const & | shape () const |
constexpr Strides const & | strides () const |
std::ptrdiff_t | offset () const |
Tensor | forward () const |
Expression template for viewing a tensor with a new shape.
Source | The expression or tensor type being reshaped. |
The View
view changes how the elements of a tensor are indexed by updating its shape and recomputing its strides without moving data.
This operation requires that the total number of elements in the new shape matches the original tensor's total number of elements.
Example:
|
inlineconstexpr |
Construct a reshaped view of the source tensor.
Indexes | Integral dimension sizes of the new shape. |
source | Reference to the source expression or tensor. |
sizes | Dimension sizes for the reshaped view. |
Assertion | failure if the number of elements in the new shape does not match the number of elements in the source. |
|
inlineconstexpr |
This simply forwards the call to the underlying source expression’s dtype
. Since a view (reshape or transpose) does not alter the actual stored values.
Tensor tannic::expression::View< Source >::forward |
|
inline |
This value is forwarded from the source expression’s offset()
method. The offset represents the memory position (in bytes) where the first element of the view begins relative to the start of the underlying storage buffer. Since reshape do not move elements in memory, the offset is unchanged from the source tensor.
|
inlineconstexpr |
In a reshape, this value is explicitly provided in the constructor through indexes...
and stored in shape_
.
|
inlineconstexpr |
For a reshape, strides are recomputed from the new shape_
so that the element layout in memory matches the original data ordering.