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

Expression template for reordering tensor dimensions according to a specified permutation. More...

#include <views.hpp>

Public Member Functions

constexpr Permutation (typename Trait< Source >::Reference source, std::tuple< Indexes... > indexes)
 Constructs a permuted 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, Integral ... Indexes>
class tannic::expression::Permutation< Source, Indexes >

Expression template for reordering tensor dimensions according to a specified permutation.

Template Parameters
SourceThe expression or tensor type being permuted.
IndexesA parameter pack of integral indices defining the permutation order.

The Permutation view reorders the dimensions of a tensor according to a user-specified sequence of indices. This changes how elements are accessed along each axis, but does not move the underlying data in memory.

Example:

Tensor X(float32, {2, 3, 4});
auto Y = permute(X, 2, 0, 1); // shape becomes (4, 2, 3)
A multidimensional, strided tensor data structure.
Definition: tensor.hpp:105
constexpr auto permute(Source &&source, Indexes... indexes)
Creates a permuted view of a tensor or expression.
Definition: views.hpp:880
Note
The number of indices in the permutation must match the rank of the tensor. Otherwise, an exception is thrown.

Constructor & Destructor Documentation

◆ Permutation()

template<Expression Source, Integral ... Indexes>
constexpr tannic::expression::Permutation< Source, Indexes >::Permutation ( typename Trait< Source >::Reference  source,
std::tuple< Indexes... >  indexes 
)
inlineconstexpr

Constructs a permuted view of the source tensor.

Parameters
sourceReference to the source expression or tensor.
indexesA tuple of dimension indices specifying the new order.
Exceptions
Exceptionif the number of indices does not match the source tensor's rank.

This constructor normalizes the indices to ensure they are valid for the tensor's rank, and then expands the shape_ and strides_ of the permuted view accordingly.

Member Function Documentation

◆ dtype()

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

The element type remains the same as the source tensor.

◆ forward()

template<Expression Source, Integral... Indexes>
Tensor tannic::expression::Permutation< Source, Indexes >::forward

◆ offset()

template<Expression Source, Integral ... Indexes>
std::ptrdiff_t tannic::expression::Permutation< Source, Indexes >::offset ( ) const
inline
Returns
The byte offset of the permuted view from the start of the storage.

This forwards directly from the source tensor. The data buffer is not moved, so the offset remains the same.

◆ shape()

template<Expression Source, Integral ... Indexes>
constexpr Shape const & tannic::expression::Permutation< Source, Indexes >::shape ( ) const
inlineconstexpr
Returns
The shape of the permuted view.

The shape is reordered according to the permutation indices provided in the constructor.

◆ strides()

template<Expression Source, Integral ... Indexes>
constexpr Strides const & tannic::expression::Permutation< Source, Indexes >::strides ( ) const
inlineconstexpr
Returns
The strides of the permuted view.

Strides are reordered to match the permuted axes, ensuring that element access corresponds to the new dimension order.


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