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

Implements tensor slicing for expression templates in the Tannic Tensor Library. More...

#include <tuple>
#include <utility>
#include <cstddef>
#include <vector>
#include "types.hpp"
#include "traits.hpp"
#include "shape.hpp"
#include "strides.hpp"
#include "indexing.hpp"
Include dependency graph for slices.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  tannic::expression::Slice< Source, Indexes >
 Expression template representing a tensor slice or subview. More...
 

Namespaces

namespace  tannic
 
namespace  tannic::expression
 

Functions

template<typename T >
std::byte const * tannic::expression::tobytes (T const &reference)
 

Detailed Description

Implements tensor slicing for expression templates in the Tannic Tensor Library.

Author
Eric Hermosis
Date
2025

This header defines the Slice class template, which represents a view or subrange of a tensor without copying its data. It supports chained indexing, assignment, and comparison operations while preserving the underlying expression structure.

Key features:

  • Zero-copy view into a tensor or tensor expression.
  • Supports integer indexing and range slicing.
  • Preserves shape, strides, and data type information.
  • Works as part of the Tannic expression template framework.

Example usage:

Tensor X(float32, {2,2,2}); X.initialize();
X[0] = 1; //arbitrary types assignment support.
X[1] = 2.f;
std::cout << X << std::endl; // Tensor([[[1, 1], [1, 1]],
// [[2, 2], [2, 2]]] dtype=float32, shape=(2, 2, 2))
Tensor Y = X[1];
std::cout << Y << std::endl; // Tensor([[2, 2],
// [2, 2]] dtype=float32, shape=(2, 2))
std::cout << Y[0] << std::endl; // Tensor([2, 2] dtype=float32, shape=(2))