Tannic
A C++ Tensor Library
|
Expression template for transposing two dimensions of a tensor. More...
#include <views.hpp>
Public Member Functions | |
constexpr | Transpose (typename Trait< Source >::Reference source, std::pair< int, int > dimensions) |
Construct a transposed 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 transposing two dimensions of a tensor.
Source | The expression or tensor type being transposed. |
The Transpose
view swaps the shape and strides of two dimensions without moving data. This is useful for reordering axes for operations like matrix multiplication.
Example:
|
inlineconstexpr |
Construct a transposed view of the source tensor.
source | Reference to the source expression or tensor. |
dimensions | A pair of dimension indices to swap. |
|
inlineconstexpr |
Transposing does not change the element type. This value is returned from the source expression's dtype()
.
Tensor tannic::expression::Transpose< Source >::forward |
|
inline |
This is taken directly from the source expression’s offset()
because transposing only changes how dimensions are indexed, not where the first element is stored.
|
inlineconstexpr |
The shape is initially copied from the source tensor, then in the constructor the two specified dimensions are swapped.
|
inlineconstexpr |
Strides are copied from the source tensor in the constructor, and then the strides for the two swapped dimensions are exchanged to match the new layout in memory.