|
Tannic
A C++ Tensor Library
|
Expression template for expanding (broadcasting) singleton dimensions of a tensor. More...
#include <views.hpp>
Public Member Functions | |
| template<Integral... Sizes> | |
| constexpr | Expansion (typename Trait< Source >::Reference source, Sizes... sizes) |
| Construct an expansion view. | |
| 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 expanding (broadcasting) singleton dimensions of a tensor.
| Source | The expression or tensor type being expanded. |
The Expansion view allows a tensor to be broadcast along dimensions where the original size is 1, enabling operations with larger tensors without copying data. Only dimensions with size 1 in the source tensor can be expanded; other dimensions must match the target shape.
Example:
|
inlineconstexpr |
Construct an expansion view.
Stores reference to the source tensor and the requested target sizes.
| Sizes | Integral dimension sizes of the target shape. |
| source | Reference to the source tensor or expression. |
| sizes | Dimension sizes for the expanded view. |
|
inlineconstexpr |
Broadcasting does not change the element type, so the dtype is forwarded from the source tensor.
| Tensor tannic::expression::Expansion< Source >::forward |
|
inline |
The offset is the same as the source tensor, because broadcasting does not change the underlying data location.
|
inlineconstexpr |
Calculation:
| Exception | if a non-singleton dimension in the source does not match the target. |
|
inlineconstexpr |
Calculation: