Tensorium
|
Multi-dimensional tensor class with fixed rank and SIMD support. More...
#include <Tensor.hpp>
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) |
K & | operator() (const std::array< size_t, Rank > &indices) |
const K & | operator() (const std::array< size_t, Rank > &indices) const |
const K & | operator() (size_t i, size_t j, size_t k, size_t l) const |
K & | operator() (size_t i, size_t j) |
K & | operator() (size_t i, size_t j, size_t k, size_t l) |
const K & | operator() (size_t i, size_t j) const |
K & | operator() (size_t i, size_t j, size_t k) |
const K & | operator() (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< K > | data |
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+R2 > | tensor_product (const Tensor< K, R1 > &A, const Tensor< K, R2 > &B) |
Compute the tensor (outer) product of two tensors. | |
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.
K | Scalar type (e.g., float or double) |
Rank | Number of tensor dimensions |
using tensorium::Tensor< K, Rank >::reg = typename Simd::reg |
|
inline |
Default constructor.
Referenced by tensorium::Tensor< K, Rank >::tensor_product(), and tensorium::Tensor< K, Rank >::transpose_simd().
|
inline |
Construct tensor with given dimensions.
dims | Dimension sizes |
References tensorium::Tensor< K, Rank >::data, tensorium::Tensor< K, Rank >::dimensions, tensorium::Tensor< K, Rank >::i, tensorium::Tensor< K, Rank >::strides, and tensorium::Tensor< K, Rank >::total_size.
tensorium::Tensor< K, Rank >::__attribute__ | ( | (always_inline, hot, flatten) | ) | const |
Convert a multi-index into a flattened linear index using SIMD.
indices | Array of indices |
strides | Array of strides |
__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.
indices | Array of indices |
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} \)
t | Input tensor |
i | First index to contract |
j | Second index to contract |
Transpose a 2D tensor using SIMD
Only valid for tensors of rank 2.
Fill tensor with a constant value.
References tensorium::Tensor< K, Rank >::data.
Referenced by tensorium_RG::RiemannTensor< T >::compute(), tensorium::SpectalChebyshev< T >::compute(), tensorium_RG::Metric< T >::compute_flrw(), tensorium_RG::Metric< T >::compute_kerr(), tensorium_RG::Metric< T >::compute_kerr_schild(), tensorium_RG::Metric< T >::compute_minkowski(), tensorium_RG::Metric< T >::compute_schwarzschild(), and tensorium_RG::RicciTensor< T >::contract_to_ricci().
|
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()().
|
inline |
tensorium::Tensor< K, Rank >::for | ( | ) |
|
inline |
References tensorium::Tensor< K, Rank >::data, tensorium::Tensor< K, Rank >::flatten_index(), and tensorium::Tensor< K, Rank >::total_size.
|
inline |
References tensorium::Tensor< K, Rank >::data, tensorium::Tensor< K, Rank >::flatten_index(), and tensorium::Tensor< K, Rank >::total_size.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
References tensorium::Tensor< K, Rank >::data, tensorium::Tensor< K, Rank >::flatten_index(), and tensorium::Tensor< K, Rank >::i.
|
inline |
References tensorium::Tensor< K, Rank >::data, tensorium::Tensor< K, Rank >::flatten_index(), and tensorium::Tensor< K, Rank >::i.
|
inline |
Print a 2D tensor (Rank == 2)
References tensorium::Tensor< K, Rank >::dimensions, and tensorium::Tensor< K, Rank >::i.
|
inline |
Print the shape (dimensions) of the tensor.
References tensorium::Tensor< K, Rank >::dimensions, and tensorium::Tensor< K, Rank >::i.
|
inline |
Resize 2D tensor.
References tensorium::Tensor< K, Rank >::data, tensorium::Tensor< K, Rank >::dimensions, tensorium::Tensor< K, Rank >::total_size, and tensorium::Tensor< K, Rank >::update_strides().
Referenced by tensorium_RG::BSSNChristoffel< T >::compute(), tensorium_RG::TildeGamma< T >::compute(), tensorium::SpectalChebyshev< T >::compute(), tensorium_RG::Metric< T >::compute_conformal_metric(), tensorium_RG::Metric< T >::compute_flrw(), tensorium_RG::Metric< T >::compute_kerr(), tensorium_RG::Metric< T >::compute_kerr_schild(), tensorium_RG::Metric< T >::compute_minkowski(), tensorium_RG::compute_partial_derivatives_3D(), tensorium_RG::compute_partial_derivatives_tensor2D(), tensorium_RG::compute_partial_derivatives_vector(), tensorium_RG::Metric< T >::compute_schwarzschild(), tensorium::Tensor< K, Rank >::resize(), and tensorium::Vector< K >::resize().
|
inline |
Resize 2D tensor.
References tensorium::Tensor< K, Rank >::resize().
|
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().
|
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} \]
R1 | Rank of tensor A |
R2 | Rank of tensor 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.
|
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().
|
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().
size_t tensorium::Tensor< K, Rank >::acc = 0 |
Referenced by tensorium::Tensor< K, Rank >::for().
return tensorium::Tensor< K, Rank >::acc |
size_t tensorium::Tensor< K, Rank >::block_size |
aligned_vector<K> tensorium::Tensor< K, Rank >::data |
Referenced by tensorium::Vector< K >::__attribute__(), tensorium::Vector< K >::__attribute__(), tensorium::Vector< K >::__attribute__(), tensorium::Vector< K >::__attribute__(), tensorium::Vector< K >::__attribute__(), tensorium::Tensor< K, Rank >::fill(), tensorium::Vector< K >::for(), tensorium::Tensor< K, Rank >::operator()(), tensorium::Tensor< K, Rank >::operator()(), tensorium::Tensor< K, Rank >::operator()(), tensorium::Tensor< K, Rank >::operator()(), tensorium::Tensor< K, Rank >::operator()(), tensorium::Tensor< K, Rank >::operator()(), tensorium::Tensor< K, Rank >::operator()(), tensorium::Tensor< K, Rank >::operator()(), tensorium::Tensor< K, Rank >::resize(), tensorium::Tensor< K, Rank >::resize(), tensorium::Tensor< K, Rank >::Tensor(), and tensorium::Tensor< K, Rank >::tensor_product().
std::array<size_t, Rank> tensorium::Tensor< K, Rank >::dimensions |
Dimensions of the tensor (e.g., {4,4,4,4})
Referenced by tensorium_RG::__attribute__(), tensorium::Tensor< K, Rank >::operator()(), tensorium::Tensor< K, Rank >::operator()(), tensorium::Tensor< K, Rank >::operator()(), tensorium::Tensor< K, Rank >::operator()(), tensorium::Tensor< K, Rank >::print(), tensorium::Tensor< K, Rank >::print_shape(), tensorium::Tensor< K, Rank >::resize(), tensorium::Tensor< K, Rank >::resize(), tensorium::Tensor< K, Rank >::shape(), tensorium::Tensor< K, Rank >::Tensor(), tensorium::Tensor< K, Rank >::tensor_product(), tensorium::tensor_to_matrix(), tensorium::Tensor< K, Rank >::transpose_simd(), and tensorium::Tensor< K, Rank >::update_strides().
size_t tensorium::Tensor< K, Rank >::i = 0 |
Referenced by tensorium::Tensor< K, Rank >::flatten_index(), tensorium::Tensor< K, Rank >::for(), tensorium::Tensor< K, Rank >::operator()(), tensorium::Tensor< K, Rank >::operator()(), tensorium::Tensor< K, Rank >::operator()(), tensorium::Tensor< K, Rank >::operator()(), tensorium::Tensor< K, Rank >::operator()(), tensorium::Tensor< K, Rank >::operator()(), tensorium::Tensor< K, Rank >::print(), tensorium::Tensor< K, Rank >::print_shape(), tensorium::Tensor< K, Rank >::Tensor(), tensorium::Tensor< K, Rank >::tensor_product(), tensorium::Tensor< K, Rank >::transpose_simd(), and tensorium::Tensor< K, Rank >::update_strides().
std::array<size_t, Rank> tensorium::Tensor< K, Rank >::strides |
size_t tensorium::Tensor< K, Rank >::total_size |