Tannic
A C++ Tensor Library
Loading...
Searching...
No Matches
tannic::expression::Transpose< Source > Class Template Reference

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
 

Detailed Description

template<Expression Source>
class tannic::expression::Transpose< Source >

Expression template for transposing two dimensions of a tensor.

Template Parameters
SourceThe 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:

Tensor X(float32, {2, 3});
auto Y = transpose(X, 0, 1); // shape becomes (3, 2)
auto Z = X.transpose(0, 1); // oop syntax.
A multidimensional, strided tensor data structure.
Definition: tensor.hpp:105
constexpr auto transpose(Source &&source, int first, int second)
Creates a transposed view of a tensor or expression by swapping two dimensions.
Definition: views.hpp:857

Constructor & Destructor Documentation

◆ Transpose()

template<Expression Source>
constexpr tannic::expression::Transpose< Source >::Transpose ( typename Trait< Source >::Reference  source,
std::pair< int, int >  dimensions 
)
inlineconstexpr

Construct a transposed view of the source tensor.

Parameters
sourceReference to the source expression or tensor.
dimensionsA pair of dimension indices to swap.

Member Function Documentation

◆ dtype()

template<Expression Source>
constexpr type tannic::expression::Transpose< Source >::dtype ( ) const
inlineconstexpr
Returns
The data type of the tensor elements.

Transposing does not change the element type. This value is returned from the source expression's dtype().

◆ forward()

template<Expression Source>
Tensor tannic::expression::Transpose< Source >::forward

◆ offset()

template<Expression Source>
std::ptrdiff_t tannic::expression::Transpose< Source >::offset ( ) const
inline
Returns
The byte offset of the transposed view from the start of the storage.

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.

◆ shape()

template<Expression Source>
constexpr Shape const & tannic::expression::Transpose< Source >::shape ( ) const
inlineconstexpr
Returns
The shape of the transposed view.

The shape is initially copied from the source tensor, then in the constructor the two specified dimensions are swapped.

◆ strides()

template<Expression Source>
constexpr Strides const & tannic::expression::Transpose< Source >::strides ( ) const
inlineconstexpr
Returns
The strides of the transposed view.

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.


The documentation for this class was generated from the following files: