Tensorium
Loading...
Searching...
No Matches
tensorium::Vector< K > Class Template Reference

Aligned, SIMD-optimized mathematical vector class for scientific computing. More...

#include <Vector.hpp>

Collaboration diagram for tensorium::Vector< K >:

Public Member Functions

Constructors
 Vector (const std::vector< K > &vec)
 Construct from a standard vector.
Element Access
K & operator[] (size_t i)
const K & operator[] (size_t i) const
const K & operator() (size_t i) const
K & operator() (size_t i)
 Vector (size_t n)
 Construct an empty vector of size n.
 Vector (std::initializer_list< K > init)
 Construct from an initializer list.
 Vector (size_t n, K value)
 Construct a constant vector.
Iterators
auto begin ()
auto end ()
auto begin () const
auto end () const
Size and Resizing
size_t size () const
void resize (size_t n)
Debug and Utilities
void print () const
 Print the vector to stdout.

Basic Operations

using Simd = simd::SimdTraits<K, DefaultISA>
using reg = typename Simd::reg
const Vector< float > & b
const Vector< float > float t
const size_t simd_width = Simd::width
const size_t n = a.size()
const reg vt = Simd::set1(t)
const reg vt1 = Simd::sub(Simd::set1(1.0f), vt)
size_t i = 0
return result
 __attribute__ ((always_inline, hot, flatten)) Vector< K > operator-(const Vector< K > &other) const
 Subtract two vectors.
 __attribute__ ((always_inline, hot, flatten)) inline void add(const Vector &v)
 Add another vector to this one (in-place).
 __attribute__ ((always_inline, hot, flatten)) inline void sub(const Vector &v)
 Subtract another vector from this one (in-place).
 __attribute__ ((always_inline, hot, flatten)) inline void scl(float a)
 Scale this vector by a scalar (in-place).
 __attribute__ ((always_inline, hot, flatten)) static inline Vector< float > linear_combination(const std
 Compute the linear combination of vectors with coefficients.
 __attribute__ ((always_inline, hot, flatten)) static inline Vector< float > lerp(const Vector< float > &a
 Linearly interpolate between two vectors.
Vector< float > result (n)
 _mm_prefetch ((const char *)&a.data[0], _MM_HINT_T0)
 for (;i+7< n;i+=simd_width)
 for (;i< n;++i) result.data[i]
static Vector< K > canonical (int index, K dx, K dy, K dz)

Advanced Operations

aligned_vector< K > data = u.data[2] * v.data[0] - u.data[0] * v.data[2]
 Underlying aligned data storage (SIMD-friendly).
const Vector< float > & v
const float dot = u.dot(v)
const float norm_u = u.norm_2()
const float norm_v = v.norm_2()
 void
r data [0] = u.data[1] * v.data[2] - u.data[2] * v.data[1]
return r
 __attribute__ ((always_inline, hot, flatten)) inline float dot(const Vector< float > &v) const
 Compute the dot product with another vector.
 __attribute__ ((always_inline, hot, flatten)) inline float norm_1() const
 Compute the 1-norm (sum of absolute values).
 __attribute__ ((always_inline, hot, flatten)) inline float norm_2() const
 Compute the 2-norm (Euclidean norm).
 __attribute__ ((always_inline, hot, flatten)) inline float norm_inf() const
 Compute the infinity norm (maximum absolute value).
 __attribute__ ((always_inline, hot, flatten)) static inline float angle_cos(const Vector< float > &u
 Compute the cosine of the angle between two vectors.
return dot (norm_u *norm_v)
 __attribute__ ((always_inline, hot, flatten)) static inline Vector< float > cross_product(const Vector< float > &u
 Compute the cross product between two 3D vectors.
Vector< float > r (3)
Vector< K > & operator+= (const Vector< K > &m)
Vector< K > & operator-= (const Vector< K > &m)
Vector< K > & operator*= (K alpha)

Detailed Description

template<typename K>
class tensorium::Vector< K >

Aligned, SIMD-optimized mathematical vector class for scientific computing.

This class implements a 1D container with SIMD-accelerated arithmetic operations including addition, subtraction, scalar multiplication, dot product, and various norms. It uses an aligned memory allocator and supports fused-multiply-add instructions via the architecture-dependent SimdTraits specialization.

This class is intended to be used in high-performance numerical computing, physics simulations, and linear algebra backends.

Template Parameters
KScalar type (typically float or double).

Member Typedef Documentation

◆ reg

template<typename K>
using tensorium::Vector< K >::reg = typename Simd::reg

◆ Simd

template<typename K>
using tensorium::Vector< K >::Simd = simd::SimdTraits<K, DefaultISA>

Constructor & Destructor Documentation

◆ Vector() [1/4]

template<typename K>
tensorium::Vector< K >::Vector ( const std::vector< K > & vec)
inline

Construct from a standard vector.

Parameters
vecThe std::vector used to initialize the data.

Referenced by tensorium::Vector< T >::__attribute__().

Here is the caller graph for this function:

◆ Vector() [2/4]

template<typename K>
tensorium::Vector< K >::Vector ( size_t n)
inline

Construct an empty vector of size n.

Parameters
nNumber of elements.

◆ Vector() [3/4]

template<typename K>
tensorium::Vector< K >::Vector ( std::initializer_list< K > init)
inline

Construct from an initializer list.

Parameters
initInitializer list.

◆ Vector() [4/4]

template<typename K>
tensorium::Vector< K >::Vector ( size_t n,
K value )
inline

Construct a constant vector.

Parameters
nNumber of elements.
valueConstant value to fill.

Member Function Documentation

◆ __attribute__() [1/12]

template<typename K>
tensorium::Vector< K >::__attribute__ ( (always_inline, hot, flatten) ) const &
inline

Compute the dot product with another vector.

Parameters
vThe other vector.
Returns
The scalar dot product.

◆ __attribute__() [2/12]

template<typename K>
tensorium::Vector< K >::__attribute__ ( (always_inline, hot, flatten) ) const
inline

Compute the 1-norm (sum of absolute values).

Returns
The L1 norm.

◆ __attribute__() [3/12]

template<typename K>
tensorium::Vector< K >::__attribute__ ( (always_inline, hot, flatten) ) const
inline

Compute the 2-norm (Euclidean norm).

Returns
The L2 norm.

◆ __attribute__() [4/12]

template<typename K>
tensorium::Vector< K >::__attribute__ ( (always_inline, hot, flatten) ) const
inline

Compute the infinity norm (maximum absolute value).

Returns
The L∞ norm.

◆ __attribute__() [5/12]

template<typename K>
tensorium::Vector< K >::__attribute__ ( (always_inline, hot, flatten) ) const &
inline

Add another vector to this one (in-place).

Parameters
vThe vector to add.

◆ __attribute__() [6/12]

template<typename K>
tensorium::Vector< K >::__attribute__ ( (always_inline, hot, flatten) )
inline

Scale this vector by a scalar (in-place).

Parameters
aThe scalar value.

◆ __attribute__() [7/12]

template<typename K>
tensorium::Vector< K >::__attribute__ ( (always_inline, hot, flatten) ) const &
inline

Subtract another vector from this one (in-place).

Parameters
vThe vector to subtract.

◆ __attribute__() [8/12]

template<typename K>
tensorium::Vector< K >::__attribute__ ( (always_inline, hot, flatten) ) const &

Compute the cosine of the angle between two vectors.

Parameters
uFirst vector.
vSecond vector.
Returns
Cosine of the angle between u and v.

◆ __attribute__() [9/12]

template<typename K>
tensorium::Vector< K >::__attribute__ ( (always_inline, hot, flatten) ) const &

Compute the cross product between two 3D vectors.

Parameters
uFirst 3D vector.
vSecond 3D vector.
Returns
Resulting 3D vector.

◆ __attribute__() [10/12]

template<typename K>
tensorium::Vector< K >::__attribute__ ( (always_inline, hot, flatten) ) const &

Linearly interpolate between two vectors.

Parameters
aFirst vector.
bSecond vector.
tInterpolation factor (0 = a, 1 = b).
Returns
Interpolated vector.

◆ __attribute__() [11/12]

template<typename K>
tensorium::Vector< K >::__attribute__ ( (always_inline, hot, flatten) ) const
inline

Compute the linear combination of vectors with coefficients.

Parameters
uList of vectors.
coefsList of coefficients.
Returns
A vector representing the linear combination: sum(c_i * u_i).

◆ __attribute__() [12/12]

template<typename K>
tensorium::Vector< K >::__attribute__ ( (always_inline, hot, flatten) ) const &
inline

Subtract two vectors.

Parameters
otherThe vector to subtract.
Returns
A new Vector containing the difference.

◆ _mm_prefetch()

template<typename K>
tensorium::Vector< K >::_mm_prefetch ( (const char *)&a. data[0],
_MM_HINT_T0  )

◆ begin() [1/2]

template<typename K>
auto tensorium::Vector< K >::begin ( )
inline

◆ begin() [2/2]

template<typename K>
auto tensorium::Vector< K >::begin ( ) const
inline

◆ canonical()

template<typename K>
Vector< K > tensorium::Vector< K >::canonical ( int index,
K dx,
K dy,
K dz )
inlinestatic

◆ dot()

template<typename K>
return tensorium::Vector< K >::dot ( norm_u * norm_v)

◆ end() [1/2]

template<typename K>
auto tensorium::Vector< K >::end ( )
inline

◆ end() [2/2]

template<typename K>
auto tensorium::Vector< K >::end ( ) const
inline

◆ for() [1/2]

template<typename K>
tensorium::Vector< K >::for ( )
inline

◆ for() [2/2]

template<typename K>
tensorium::Vector< K >::for ( )

◆ operator()() [1/2]

template<typename K>
K & tensorium::Vector< K >::operator() ( size_t i)
inline

◆ operator()() [2/2]

template<typename K>
const K & tensorium::Vector< K >::operator() ( size_t i) const
inline

◆ operator*=()

template<typename K>
Vector< K > & tensorium::Vector< K >::operator*= ( K alpha)
inline

◆ operator+=()

template<typename K>
Vector< K > & tensorium::Vector< K >::operator+= ( const Vector< K > & m)
inline

◆ operator-=()

template<typename K>
Vector< K > & tensorium::Vector< K >::operator-= ( const Vector< K > & m)
inline

◆ operator[]() [1/2]

template<typename K>
K & tensorium::Vector< K >::operator[] ( size_t i)
inline

◆ operator[]() [2/2]

template<typename K>
const K & tensorium::Vector< K >::operator[] ( size_t i) const
inline

◆ print()

template<typename K>
void tensorium::Vector< K >::print ( ) const
inline

Print the vector to stdout.

◆ r()

template<typename K>
Vector< float > tensorium::Vector< K >::r ( 3 )

◆ resize()

template<typename K>
void tensorium::Vector< K >::resize ( size_t n)
inline

Referenced by tensorium_RG::Metric< T >::BSSN(), tensorium_RG::TildeGamma< T >::compute(), and tensorium_RG::compute_partial_derivatives_scalar().

Here is the caller graph for this function:

◆ result()

template<typename K>
Vector< float > tensorium::Vector< K >::result ( n )

◆ size()

Member Data Documentation

◆ b

template<typename K>
const Vector<float>& tensorium::Vector< K >::b

◆ data [1/2]

template<typename K>
r tensorium::Vector< K >::data[2] = u.data[1] * v.data[2] - u.data[2] * v.data[1]

◆ data [2/2]

template<typename K>
r tensorium::Vector< K >::data = u.data[2] * v.data[0] - u.data[0] * v.data[2]

Underlying aligned data storage (SIMD-friendly).

Referenced by tensorium::Vector< T >::__attribute__(), and tensorium::Vector< T >::for().

◆ dot

template<typename K>
const float tensorium::Vector< K >::dot = u.dot(v)

Referenced by tensorium::dot_vec().

◆ i

template<typename K>
size_t tensorium::Vector< K >::i = 0

◆ n

template<typename K>
const size_t tensorium::Vector< K >::n = a.size()

◆ norm_u

template<typename K>
const float tensorium::Vector< K >::norm_u = u.norm_2()

◆ norm_v

template<typename K>
const float tensorium::Vector< K >::norm_v = v.norm_2()

◆ r

template<typename K>
return tensorium::Vector< K >::r

◆ result

template<typename K>
return tensorium::Vector< K >::result

◆ simd_width

template<typename K>
const size_t tensorium::Vector< K >::simd_width = Simd::width

◆ t

template<typename K>
const Vector<float> float tensorium::Vector< K >::t
Initial value:
{
if (a.size() != b.size())
throw std::invalid_argument("Vector sizes do not match")
const Vector< float > & b
Definition Vector.hpp:264

◆ v

template<typename K>
const Vector< float > & tensorium::Vector< K >::v
Initial value:
{
if (u.size() != v.size())
throw std::invalid_argument("Vector sizes do not match")
const Vector< float > & v
Definition Vector.hpp:417

◆ void

template<typename K>
tensorium::Vector< K >::void

◆ vt

template<typename K>
const reg tensorium::Vector< K >::vt = Simd::set1(t)

◆ vt1

template<typename K>
const reg tensorium::Vector< K >::vt1 = Simd::sub(Simd::set1(1.0f), vt)

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