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
Koperator[] (size_t i)
 
const Koperator[] (size_t i) const
 
const Koperator() (size_t i) const
 
Koperator() (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< floatresult (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]
 

Advanced Operations

aligned_vector< Kdata = std::fma(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()
 
__m128 uxy = _mm_set_ps(0.0f, u.data[0], u.data[2], u.data[1])
 
__m128 vxy = _mm_set_ps(0.0f, v.data[0], v.data[2], v.data[1])
 
r data [0] = std::fma(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< floatr (3)
 

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

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.

◆ 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.

References tensorium::Vector< K >::_mm_prefetch(), tensorium::Vector< K >::b, tensorium::Tensor< K, Rank >::data, tensorium::Vector< K >::data, tensorium::Vector< K >::i, tensorium::Vector< K >::n, tensorium::Vector< K >::result, tensorium::Vector< K >::simd_width, tensorium::Vector< K >::size(), and tensorium::Vector< K >::v.

Here is the call graph for this function:

◆ __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.

References MathsUtils::_fabs(), tensorium::Vector< K >::_mm_prefetch(), tensorium::Vector< K >::data, tensorium::Vector< K >::i, tensorium::Vector< K >::n, tensorium::Vector< K >::result, tensorium::Vector< K >::simd_width, tensorium::Vector< K >::size(), and tensorium::Vector< K >::v.

Here is the call graph for this function:

◆ __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.

References tensorium::Vector< K >::_mm_prefetch(), tensorium::Vector< K >::data, tensorium::Vector< K >::i, tensorium::Vector< K >::n, tensorium::Vector< K >::result, tensorium::Vector< K >::simd_width, tensorium::Vector< K >::size(), and tensorium::Vector< K >::v.

Here is the call graph for this function:

◆ __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.

References MathsUtils::_fabs(), MathsUtils::_max(), tensorium::Vector< K >::_mm_prefetch(), tensorium::Vector< K >::data, tensorium::Vector< K >::i, tensorium::Vector< K >::n, tensorium::Vector< K >::result, tensorium::Vector< K >::simd_width, tensorium::Vector< K >::size(), and tensorium::Vector< K >::v.

Here is the call graph for this function:

◆ __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.

References tensorium::Vector< K >::_mm_prefetch(), tensorium::Tensor< K, Rank >::data, tensorium::Vector< K >::data, tensorium::Vector< K >::i, tensorium::Vector< K >::n, tensorium::Vector< K >::simd_width, tensorium::Vector< K >::size(), and tensorium::Vector< K >::v.

Here is the call graph for this function:

◆ __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.

References tensorium::Vector< K >::_mm_prefetch(), tensorium::Vector< K >::data, tensorium::Vector< K >::i, tensorium::Vector< K >::n, tensorium::Vector< K >::simd_width, and tensorium::Vector< K >::size().

Here is the call graph for this function:

◆ __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.

References tensorium::Vector< K >::_mm_prefetch(), tensorium::Tensor< K, Rank >::data, tensorium::Vector< K >::data, tensorium::Vector< K >::i, tensorium::Vector< K >::n, tensorium::Vector< K >::simd_width, tensorium::Vector< K >::size(), and tensorium::Vector< K >::v.

Here is the call graph for this function:

◆ __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.

References tensorium::Vector< K >::v.

◆ __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).

References tensorium::Tensor< K, Rank >::data, tensorium::Vector< K >::data, tensorium::Vector< K >::i, tensorium::Vector< K >::n, tensorium::Vector< K >::result, tensorium::Vector< K >::simd_width, and tensorium::Vector< K >::v.

◆ __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.

References tensorium::Tensor< K, Rank >::data, tensorium::Vector< K >::data, tensorium::Vector< K >::i, and tensorium::Vector< K >::result.

◆ _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

◆ 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]

◆ 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[]() [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.

References tensorium::Vector< K >::data, f(), and tensorium::Vector< K >::size().

Here is the call graph for this function:

◆ r()

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

◆ resize()

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

References tensorium::Vector< K >::data, tensorium::Vector< K >::n, and tensorium::Tensor< K, Rank >::resize().

Here is the call graph for this function:

◆ result()

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

◆ size()

Member Data Documentation

◆ b

◆ data [1/2]

◆ data [2/2]

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

◆ dot

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

◆ i

◆ n

◆ 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

◆ result

◆ 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:263

◆ uxy

template<typename K >
__m128 tensorium::Vector< K >::uxy = _mm_set_ps(0.0f, u.data[0], u.data[2], u.data[1])

◆ v

◆ 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)

◆ vxy

template<typename K >
__m128 tensorium::Vector< K >::vxy = _mm_set_ps(0.0f, v.data[0], v.data[2], v.data[1])

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