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

Expression template for inserting singleton dimensions into a tensor. More...

#include <views.hpp>

Public Member Functions

template<Integral... Axes>
constexpr Unsqueeze (typename Trait< Source >::Reference source, Axes... axes)
 Construct an unsqueezed 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::Unsqueeze< Source >

Expression template for inserting singleton dimensions into a tensor.

Template Parameters
SourceThe expression or tensor type being unsqueezed.

The Unsqueeze view adds new dimensions of size 1 at specified axes. This changes only the tensor metadata (shape and strides), not the underlying storage.

Example:

Tensor X(float32, {3});
auto Y = unsqueeze(X, 0); // shape becomes (1, 3)
auto Z = unsqueeze(X, -1); // shape becomes (3, 1)
A multidimensional, strided tensor data structure.
Definition: tensor.hpp:105
constexpr auto unsqueeze(Source &&source, Axes... axes)
Inserts singleton dimensions at the specified axes (unsqueeze).
Definition: views.hpp:962

Constructor & Destructor Documentation

◆ Unsqueeze()

template<Expression Source>
template<Integral... Axes>
constexpr tannic::expression::Unsqueeze< Source >::Unsqueeze ( typename Trait< Source >::Reference  source,
Axes...  axes 
)
inlineconstexpr

Construct an unsqueezed view of the source tensor.

Template Parameters
AxesIntegral indices where new dimensions of size 1 should be inserted.
Parameters
sourceReference to the source expression or tensor.
axesOne or more dimension indices (negative indices allowed).

Example:

  • unsqueeze(X, 0) inserts a new axis before the first dimension.
  • unsqueeze(X, -1) inserts a new axis after the last dimension.
Exceptions
Exceptionif any normalized axis index is invalid.

Member Function Documentation

◆ dtype()

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

This is forwarded directly from the source expression. Unsqueezing does not alter the tensor’s dtype.

◆ forward()

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

◆ offset()

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

This is forwarded from the source tensor since unsqueezing does not change the starting position of the data.

◆ shape()

template<Expression Source>
constexpr Shape const & tannic::expression::Unsqueeze< Source >::shape ( ) const
inlineconstexpr
Returns
The shape of the unsqueezed tensor.

Calculation:

  • Copies the source shape.
  • Inserts size-1 dimensions at the specified axes.

Example:

  • Source shape: (3)
  • unsqueeze(X, 0) → shape: (1, 3)

◆ strides()

template<Expression Source>
constexpr Strides const & tannic::expression::Unsqueeze< Source >::strides ( ) const
inlineconstexpr
Returns
The strides of the unsqueezed tensor.

Calculation:

  • Copies the source strides.
  • Inserts strides for new singleton dimensions. These strides are set to repeat the same memory element along the axis.

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