Tensorium
|
Aligned, SIMD-optimized mathematical vector class for scientific computing. More...
#include <Vector.hpp>
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] | |
Advanced Operations | |
aligned_vector< K > | data = 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< float > | r (3) |
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.
K | Scalar type (typically float or double). |
using tensorium::Vector< K >::Simd = simd::SimdTraits<K, DefaultISA> |
|
inline |
Construct from a standard vector.
vec | The std::vector used to initialize the data. |
|
inline |
Construct an empty vector of size n
.
n | Number of elements. |
|
inline |
Construct from an initializer list.
init | Initializer list. |
Construct a constant vector.
n | Number of elements. |
value | Constant value to fill. |
|
inline |
Compute the dot product with another vector.
v | The other vector. |
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.
|
inline |
Compute the 1-norm (sum of absolute values).
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.
|
inline |
Compute the 2-norm (Euclidean 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.
|
inline |
Compute the infinity norm (maximum absolute value).
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.
|
inline |
Add another vector to this one (in-place).
v | The 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.
|
inline |
Scale this vector by a scalar (in-place).
a | The 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().
|
inline |
Subtract another vector from this one (in-place).
v | The 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.
tensorium::Vector< K >::__attribute__ | ( | (always_inline, hot, flatten) | ) | const & |
Compute the cosine of the angle between two vectors.
u | First vector. |
v | Second vector. |
tensorium::Vector< K >::__attribute__ | ( | (always_inline, hot, flatten) | ) | const & |
Compute the cross product between two 3D vectors.
u | First 3D vector. |
v | Second 3D vector. |
References tensorium::Vector< K >::v.
tensorium::Vector< K >::__attribute__ | ( | (always_inline, hot, flatten) | ) | const & |
Linearly interpolate between two vectors.
a | First vector. |
b | Second vector. |
t | Interpolation factor (0 = a, 1 = b). |
|
inline |
Compute the linear combination of vectors with coefficients.
u | List of vectors. |
coefs | List of coefficients. |
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.
|
inline |
Subtract two vectors.
other | The vector to subtract. |
References tensorium::Tensor< K, Rank >::data, tensorium::Vector< K >::data, tensorium::Vector< K >::i, and tensorium::Vector< K >::result.
tensorium::Vector< K >::_mm_prefetch | ( | (const char *)&a. | data[0], |
_MM_HINT_T0 | ) |
Referenced by tensorium::Vector< K >::__attribute__(), tensorium::Vector< K >::__attribute__(), tensorium::Vector< K >::__attribute__(), tensorium::Vector< K >::__attribute__(), tensorium::Vector< K >::__attribute__(), tensorium::Vector< K >::__attribute__(), and tensorium::Vector< K >::__attribute__().
|
inline |
References tensorium::Vector< K >::data.
|
inline |
References tensorium::Vector< K >::data.
|
inline |
References tensorium::Vector< K >::data.
|
inline |
References tensorium::Vector< K >::data.
|
inline |
tensorium::Vector< K >::for | ( | ) |
References tensorium::Vector< K >::data, and tensorium::Vector< K >::i.
References tensorium::Vector< K >::data, and tensorium::Vector< K >::i.
References tensorium::Vector< K >::data, and tensorium::Vector< K >::i.
References tensorium::Vector< K >::data, and tensorium::Vector< K >::i.
|
inline |
Print the vector to stdout.
References tensorium::Vector< K >::data, f(), and tensorium::Vector< K >::size().
References tensorium::Vector< K >::data, tensorium::Vector< K >::n, and tensorium::Tensor< K, Rank >::resize().
|
inline |
References tensorium::Vector< K >::data.
Referenced by tensorium::Vector< K >::__attribute__(), tensorium::Vector< K >::__attribute__(), tensorium::Vector< K >::__attribute__(), tensorium::Vector< K >::__attribute__(), tensorium::Vector< K >::__attribute__(), tensorium::Vector< K >::__attribute__(), tensorium::Vector< K >::__attribute__(), tensorium::SpectralFFT< T >::bit_reverse(), tensorium::Matrix< K, RowMajor >::mul_vec(), tensorium::Matrix< K, RowMajor >::operator*(), tensorium::Vector< K >::print(), tensorium::solver::Jacobi< K >::solve(), and tensorium::SpectralFFT< T >::transform_impl().
Referenced by tensorium::Vector< K >::__attribute__(), and tensorium::Vector< K >::for().
r tensorium::Vector< K >::data = std::fma(u.data[2], v.data[0], -u.data[0] * v.data[2]) |
Underlying aligned data storage (SIMD-friendly).
Referenced by tensorium::Vector< K >::__attribute__(), tensorium::Vector< K >::__attribute__(), tensorium::Vector< K >::__attribute__(), tensorium::Vector< K >::__attribute__(), tensorium::Vector< K >::__attribute__(), tensorium::Vector< K >::__attribute__(), tensorium::Vector< K >::__attribute__(), tensorium::Vector< K >::__attribute__(), tensorium::Vector< K >::__attribute__(), tensorium::Vector< K >::begin(), tensorium::Vector< K >::begin(), tensorium::Vector< K >::end(), tensorium::Vector< K >::end(), tensorium::Vector< K >::operator()(), tensorium::Vector< K >::operator()(), tensorium::Vector< K >::operator[](), tensorium::Vector< K >::operator[](), tensorium::Vector< K >::print(), tensorium::Vector< K >::resize(), and tensorium::Vector< K >::size().
r tensorium::Vector< K >::data[2] = std::fma(u.data[1], v.data[2], -u.data[2] * v.data[1]) |
size_t tensorium::Vector< K >::i = 0 |
Referenced by tensorium::Vector< K >::__attribute__(), tensorium::Vector< K >::__attribute__(), tensorium::Vector< K >::__attribute__(), tensorium::Vector< K >::__attribute__(), tensorium::Vector< K >::__attribute__(), tensorium::Vector< K >::__attribute__(), tensorium::Vector< K >::__attribute__(), tensorium::Vector< K >::__attribute__(), tensorium::Vector< K >::__attribute__(), tensorium::Vector< K >::for(), tensorium::Vector< K >::operator()(), tensorium::Vector< K >::operator()(), tensorium::Vector< K >::operator[](), and tensorium::Vector< K >::operator[]().
const size_t tensorium::Vector< K >::n = a.size() |
Referenced by tensorium::Vector< K >::__attribute__(), tensorium::Vector< K >::__attribute__(), tensorium::Vector< K >::__attribute__(), tensorium::Vector< K >::__attribute__(), tensorium::Vector< K >::__attribute__(), tensorium::Vector< K >::__attribute__(), tensorium::Vector< K >::__attribute__(), tensorium::Vector< K >::__attribute__(), and tensorium::Vector< K >::resize().
const float tensorium::Vector< K >::norm_u = u.norm_2() |
const float tensorium::Vector< K >::norm_v = v.norm_2() |
return tensorium::Vector< K >::r |
Referenced by tensorium::Vector< K >::for().
return tensorium::Vector< K >::result |
const size_t tensorium::Vector< K >::simd_width = Simd::width |
Referenced by tensorium::Vector< K >::__attribute__(), tensorium::Vector< K >::__attribute__(), tensorium::Vector< K >::__attribute__(), tensorium::Vector< K >::__attribute__(), tensorium::Vector< K >::__attribute__(), tensorium::Vector< K >::__attribute__(), tensorium::Vector< K >::__attribute__(), and tensorium::Vector< K >::__attribute__().
__m128 tensorium::Vector< K >::uxy = _mm_set_ps(0.0f, u.data[0], u.data[2], u.data[1]) |
Referenced by tensorium::Vector< K >::__attribute__(), tensorium::Vector< K >::__attribute__(), tensorium::Vector< K >::__attribute__(), tensorium::Vector< K >::__attribute__(), tensorium::Vector< K >::__attribute__(), tensorium::Vector< K >::__attribute__(), tensorium::Vector< K >::__attribute__(), and tensorium::Vector< K >::__attribute__().
Referenced by tensorium::Vector< K >::for().
Referenced by tensorium::Vector< K >::for().
__m128 tensorium::Vector< K >::vxy = _mm_set_ps(0.0f, v.data[0], v.data[2], v.data[1]) |