Tensorium
Loading...
Searching...
No Matches
tensorium::Tensor< K, Rank > Class Template Reference

Multi-dimensional tensor class with fixed rank and SIMD support. More...

#include <Tensor.hpp>

Collaboration diagram for tensorium::Tensor< K, Rank >:

Public Types

using value_type = K
 

Public Member Functions

 Tensor ()
 Default constructor.
 
 Tensor (const std::array< size_t, Rank > &dims)
 Construct tensor with given dimensions.
 
size_t flatten_index (size_t i, size_t j, size_t k, size_t l) const
 
std::array< size_t, Rank > shape () const
 
void update_strides ()
 
void fill (K value)
 Fill tensor with a constant value.
 
void resize (const std::array< size_t, 2 > &dims)
 Resize 2D tensor.
 
void resize (size_t d0, size_t d1)
 Resize 2D tensor.
 
Element Access
void resize (size_t d0, size_t d1, size_t d2)
 
Koperator() (const std::array< size_t, Rank > &indices)
 
const Koperator() (const std::array< size_t, Rank > &indices) const
 
const Koperator() (size_t i, size_t j, size_t k, size_t l) const
 
Koperator() (size_t i, size_t j)
 
Koperator() (size_t i, size_t j, size_t k, size_t l)
 
const Koperator() (size_t i, size_t j) const
 
Koperator() (size_t i, size_t j, size_t k)
 
const Koperator() (size_t i, size_t j, size_t k) const
 
Debug and Utilities
void print_shape () const
 Print the shape (dimensions) of the tensor.
 
void print () const
 Print a 2D tensor (Rank == 2)
 

Public Attributes

std::array< size_t, Rank > dimensions
 Dimensions of the tensor (e.g., {4,4,4,4})
 
size_t total_size
 
aligned_vector< Kdata
 
size_t block_size
 
std::array< size_t, Rank > strides
 

basic tensor operations (Rank == 2)

using reg = typename Simd::reg
 
const size_t *strides const
 
constexpr size_t W = Simd::width / sizeof(size_t)
 
size_t acc = 0
 
size_t i = 0
 
return acc
 
 __attribute__ ((always_inline, hot, flatten)) inline size_t flatten_index_simd(const size_t *indices
 Convert a multi-index into a flattened linear index using SIMD.
 
 for (;i+W - 1< Rank;i+=W)
 
 for (;i< Rank;++i) acc+
 
__attribute__((always_inline, hot, flatten)) inline size_t flatten_index(const std __attribute__ ((always_inline, hot, flatten)) Tensor< K
 Convert multi-index to flat index.
 
__attribute__((always_inline, hot, flatten)) inline size_t flatten_index(const std transpose_simd () const
 
template<size_t R1, size_t R2>
static Tensor< K, R1+R2tensor_product (const Tensor< K, R1 > &A, const Tensor< K, R2 > &B)
 Compute the tensor (outer) product of two tensors.
 

Detailed Description

template<typename K, std::size_t Rank>
class tensorium::Tensor< K, Rank >

Multi-dimensional tensor class with fixed rank and SIMD support.

This class provides high-performance operations on tensors of arbitrary rank, supporting element-wise access, contraction, transposition, and tensor product, all implemented with SIMD optimization and aligned memory.

Template Parameters
KScalar type (e.g., float or double)
RankNumber of tensor dimensions

Member Typedef Documentation

◆ reg

template<typename K , std::size_t Rank>
using tensorium::Tensor< K, Rank >::reg = typename Simd::reg

◆ value_type

template<typename K , std::size_t Rank>
using tensorium::Tensor< K, Rank >::value_type = K

Constructor & Destructor Documentation

◆ Tensor() [1/2]

template<typename K , std::size_t Rank>
tensorium::Tensor< K, Rank >::Tensor ( )
inline

Default constructor.

Referenced by tensorium::Tensor< K, Rank >::tensor_product(), and tensorium::Tensor< K, Rank >::transpose_simd().

Here is the caller graph for this function:

◆ Tensor() [2/2]

template<typename K , std::size_t Rank>
tensorium::Tensor< K, Rank >::Tensor ( const std::array< size_t, Rank > & dims)
inline

Member Function Documentation

◆ __attribute__() [1/2]

template<typename K , std::size_t Rank>
tensorium::Tensor< K, Rank >::__attribute__ ( (always_inline, hot, flatten) ) const

Convert a multi-index into a flattened linear index using SIMD.

Parameters
indicesArray of indices
stridesArray of strides
Returns
Flattened index

◆ __attribute__() [2/2]

template<typename K , std::size_t Rank>
__attribute__((always_inline, hot, flatten)) inline size_t flatten_index(const std tensorium::Tensor< K, Rank >::__attribute__ ( (always_inline, hot, flatten) )

Convert multi-index to flat index.

Parameters
indicesArray of indices
Returns
Flattened index

Perform contraction over two indices using SIMD

Contracts a tensor \( T_{i_1 \dots i_k i j i_{k+1} \dots i_n} \) to \( T'_{i_1 \dots i_k i_{k+1} \dots i_n} \)

Parameters
tInput tensor
iFirst index to contract
jSecond index to contract
Returns
Contracted tensor of rank (Rank - 2)

Transpose a 2D tensor using SIMD

Only valid for tensors of rank 2.

Returns
Transposed tensor

◆ fill()

template<typename K , std::size_t Rank>
void tensorium::Tensor< K, Rank >::fill ( K value)
inline

◆ flatten_index()

template<typename K , std::size_t Rank>
size_t tensorium::Tensor< K, Rank >::flatten_index ( size_t i,
size_t j,
size_t k,
size_t l ) const
inline

References tensorium::Tensor< K, Rank >::flatten_index(), and tensorium::Tensor< K, Rank >::i.

Referenced by tensorium::Tensor< K, Rank >::flatten_index(), tensorium::Tensor< K, Rank >::operator()(), tensorium::Tensor< K, Rank >::operator()(), tensorium::Tensor< K, Rank >::operator()(), and tensorium::Tensor< K, Rank >::operator()().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ for() [1/2]

◆ for() [2/2]

template<typename K , std::size_t Rank>
tensorium::Tensor< K, Rank >::for ( )

◆ operator()() [1/8]

template<typename K , std::size_t Rank>
K & tensorium::Tensor< K, Rank >::operator() ( const std::array< size_t, Rank > & indices)
inline

References tensorium::Tensor< K, Rank >::data, tensorium::Tensor< K, Rank >::flatten_index(), and tensorium::Tensor< K, Rank >::total_size.

Here is the call graph for this function:

◆ operator()() [2/8]

template<typename K , std::size_t Rank>
const K & tensorium::Tensor< K, Rank >::operator() ( const std::array< size_t, Rank > & indices) const
inline

References tensorium::Tensor< K, Rank >::data, tensorium::Tensor< K, Rank >::flatten_index(), and tensorium::Tensor< K, Rank >::total_size.

Here is the call graph for this function:

◆ operator()() [3/8]

◆ operator()() [4/8]

◆ operator()() [5/8]

◆ operator()() [6/8]

◆ operator()() [7/8]

template<typename K , std::size_t Rank>
K & tensorium::Tensor< K, Rank >::operator() ( size_t i,
size_t j,
size_t k,
size_t l )
inline

References tensorium::Tensor< K, Rank >::data, tensorium::Tensor< K, Rank >::flatten_index(), and tensorium::Tensor< K, Rank >::i.

Here is the call graph for this function:

◆ operator()() [8/8]

template<typename K , std::size_t Rank>
const K & tensorium::Tensor< K, Rank >::operator() ( size_t i,
size_t j,
size_t k,
size_t l ) const
inline

References tensorium::Tensor< K, Rank >::data, tensorium::Tensor< K, Rank >::flatten_index(), and tensorium::Tensor< K, Rank >::i.

Here is the call graph for this function:

◆ print()

template<typename K , std::size_t Rank>
void tensorium::Tensor< K, Rank >::print ( ) const
inline

Print a 2D tensor (Rank == 2)

References tensorium::Tensor< K, Rank >::dimensions, and tensorium::Tensor< K, Rank >::i.

◆ print_shape()

template<typename K , std::size_t Rank>
void tensorium::Tensor< K, Rank >::print_shape ( ) const
inline

Print the shape (dimensions) of the tensor.

References tensorium::Tensor< K, Rank >::dimensions, and tensorium::Tensor< K, Rank >::i.

◆ resize() [1/3]

◆ resize() [2/3]

template<typename K , std::size_t Rank>
void tensorium::Tensor< K, Rank >::resize ( size_t d0,
size_t d1 )
inline

Resize 2D tensor.

References tensorium::Tensor< K, Rank >::resize().

Here is the call graph for this function:

◆ resize() [3/3]

template<typename K , std::size_t Rank>
void tensorium::Tensor< K, Rank >::resize ( size_t d0,
size_t d1,
size_t d2 )
inline

◆ shape()

template<typename K , std::size_t Rank>
std::array< size_t, Rank > tensorium::Tensor< K, Rank >::shape ( ) const
inline

References tensorium::Tensor< K, Rank >::dimensions.

Referenced by tensorium_RG::BSSNChristoffel< T >::compute(), tensorium_RG::TildeGamma< T >::compute(), tensorium_RG::compute_partial_derivatives_3D(), and tensorium::Tensor< K, Rank >::tensor_product().

Here is the caller graph for this function:

◆ tensor_product()

template<typename K , std::size_t Rank>
template<size_t R1, size_t R2>
static Tensor< K, R1+R2 > tensorium::Tensor< K, Rank >::tensor_product ( const Tensor< K, R1 > & A,
const Tensor< K, R2 > & B )
inlinestatic

Compute the tensor (outer) product of two tensors.

Resulting tensor has rank = R1 + R2.

\[ (A \otimes B)_{i_1 \dots i_R} = A_{i_1 \dots i_{R_1}} \cdot B_{i_{R_1 + 1} \dots i_R} \]

Template Parameters
R1Rank of tensor A
R2Rank of tensor B
Parameters
ATensor A
BTensor B
Returns
Tensor product \( A \otimes B \)

References tensorium::Tensor< K, Rank >::data, tensorium::Tensor< K, Rank >::dimensions, tensorium::Tensor< K, Rank >::i, tensorium::Tensor< K, Rank >::shape(), tensorium::Tensor< K, Rank >::Tensor(), tensorium::Tensor< K, Rank >::total_size, and tensorium::Tensor< K, Rank >::W.

Here is the call graph for this function:

◆ transpose_simd()

template<typename K , std::size_t Rank>
__attribute__((always_inline, hot, flatten)) inline size_t flatten_index(const std tensorium::Tensor< K, Rank >::transpose_simd ( ) const
inline

References tensorium::Tensor< K, Rank >::dimensions, tensorium::Tensor< K, Rank >::i, tensorium::Tensor< K, Rank >::Tensor(), and tensorium::Tensor< K, Rank >::W.

Referenced by tensorium::transpose_tensor().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ update_strides()

template<typename K , std::size_t Rank>
void tensorium::Tensor< K, Rank >::update_strides ( )
inline

References tensorium::Tensor< K, Rank >::dimensions, tensorium::Tensor< K, Rank >::i, and tensorium::Tensor< K, Rank >::strides.

Referenced by tensorium::Tensor< K, Rank >::resize().

Here is the caller graph for this function:

Member Data Documentation

◆ acc [1/2]

template<typename K , std::size_t Rank>
size_t tensorium::Tensor< K, Rank >::acc = 0

◆ acc [2/2]

template<typename K , std::size_t Rank>
return tensorium::Tensor< K, Rank >::acc

◆ block_size

template<typename K , std::size_t Rank>
size_t tensorium::Tensor< K, Rank >::block_size

◆ const

template<typename K , std::size_t Rank>
const size_t* strides tensorium::Tensor< K, Rank >::const
Initial value:
{
Definition SIMD.hpp:177

◆ data

◆ dimensions

◆ i

◆ strides

◆ total_size

◆ W

template<typename K , std::size_t Rank>
constexpr size_t tensorium::Tensor< K, Rank >::W = Simd::width / sizeof(size_t)
constexpr

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