Tannic
A C++ Tensor Library
Loading...
Searching...
No Matches
views.hpp File Reference

Implements views for tensors in the Tannic Tensor Library. More...

#include <utility>
#include <algorithm>
#include <numeric>
#include <vector>
#include "types.hpp"
#include "traits.hpp"
#include "shape.hpp"
#include "strides.hpp"
#include "concepts.hpp"
#include "exceptions.hpp"
Include dependency graph for views.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  tannic::expression::View< Source >
 Expression template for viewing a tensor with a new shape. More...
 
class  tannic::expression::Transpose< Source >
 Expression template for transposing two dimensions of a tensor. More...
 
class  tannic::expression::Permutation< Source, Indexes >
 Expression template for reordering tensor dimensions according to a specified permutation. More...
 
class  tannic::expression::Expansion< Source >
 Expression template for expanding (broadcasting) singleton dimensions of a tensor. More...
 
class  tannic::expression::Squeeze< Source >
 Expression template for removing singleton dimensions from a tensor. More...
 
class  tannic::expression::Unsqueeze< Source >
 Expression template for inserting singleton dimensions into a tensor. More...
 
class  tannic::expression::Flatten< Source >
 Expression template for flattening a contiguous range of dimensions. More...
 

Namespaces

namespace  tannic
 
namespace  tannic::expression
 

Functions

template<Expression Source, Integral ... Indexes>
constexpr auto tannic::expression::view (Source &&source, Indexes ... indexes)
 Creates a reshaped view of a tensor or expression.
 
template<Expression Source>
constexpr auto tannic::expression::transpose (Source &&source, int first, int second)
 Creates a transposed view of a tensor or expression by swapping two dimensions.
 
template<Expression Source, Integral ... Indexes>
constexpr auto tannic::expression::permute (Source &&source, Indexes... indexes)
 Creates a permuted view of a tensor or expression.
 
template<Expression Source, Integral... Sizes>
constexpr auto tannic::expression::expand (Source &&source, Sizes... sizes)
 Creates an expanded view of a tensor, broadcasting singleton dimensions.
 
template<Expression Source>
constexpr auto tannic::expression::squeeze (Source &&source)
 Removes all singleton dimensions from a tensor (squeeze).
 
template<Expression Source, Integral... Axes>
constexpr auto tannic::expression::unsqueeze (Source &&source, Axes... axes)
 Inserts singleton dimensions at the specified axes (unsqueeze).
 
template<Expression Source>
constexpr auto tannic::expression::flatten (Source &&source, int start=0, int end=-1)
 Flattens dimensions of a tensor into a single dimension.
 

Detailed Description

Implements views for tensors in the Tannic Tensor Library.

Author
Eric Hermosis
Date
2025

This header defines expression templates for tensors views without copying data. These views operate on the underlying tensor metadata (shape, strides, and offset) to reinterpret how elements are accessed while preserving the original storage.

Example usage:

Tensor X(float32, {2, 3}); X.initialize();
// View from (2, 3) to (3, 2)
auto Y = view(X, 3, 2);
std::cout << Y.shape() << std::endl; // (3, 2)
// Swap the first and second dimensions
auto Z = transpose(X, 0, 1);
std::cout << Z.shape() << std::endl; // (3, 2)