|
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] | |
| 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) |
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 >::reg = typename Simd::reg |
| using tensorium::Vector< K >::Simd = simd::SimdTraits<K, DefaultISA> |
|
inline |
Construct from a standard vector.
| vec | The std::vector used to initialize the data. |
Referenced by tensorium::Vector< T >::__attribute__().
|
inline |
|
inline |
Construct from an initializer list.
| init | Initializer list. |
|
inline |
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. |
|
inline |
Compute the 1-norm (sum of absolute values).
|
inline |
Compute the 2-norm (Euclidean norm).
|
inline |
Compute the infinity norm (maximum absolute value).
|
inline |
Add another vector to this one (in-place).
| v | The vector to add. |
|
inline |
Scale this vector by a scalar (in-place).
| a | The scalar value. |
|
inline |
Subtract another vector from this one (in-place).
| v | The vector to subtract. |
| 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. |
| tensorium::Vector< K >::__attribute__ | ( | (always_inline, hot, flatten) | ) | const & |
|
inline |
Compute the linear combination of vectors with coefficients.
| u | List of vectors. |
| coefs | List of coefficients. |
|
inline |
Subtract two vectors.
| other | The vector to subtract. |
| tensorium::Vector< K >::_mm_prefetch | ( | (const char *)&a. | data[0], |
| _MM_HINT_T0 | ) |
|
inline |
|
inline |
|
inlinestatic |
| return tensorium::Vector< K >::dot | ( | norm_u * | norm_v | ) |
|
inline |
|
inline |
|
inline |
| tensorium::Vector< K >::for | ( | ) |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Print the vector to stdout.
| Vector< float > tensorium::Vector< K >::r | ( | 3 | ) |
|
inline |
Referenced by tensorium_RG::Metric< T >::BSSN(), tensorium_RG::TildeGamma< T >::compute(), and tensorium_RG::compute_partial_derivatives_scalar().
| Vector< float > tensorium::Vector< K >::result | ( | n | ) |
|
inline |
Referenced by tensorium::Vector< T >::__attribute__(), tensorium::Vector< T >::__attribute__(), tensorium::Vector< T >::__attribute__(), tensorium::Vector< T >::__attribute__(), tensorium::Vector< T >::__attribute__(), tensorium::Vector< T >::__attribute__(), tensorium::Vector< T >::__attribute__(), tensorium::Vector< T >::__attribute__(), tensorium::SpectralFFT< T >::bit_reverse(), tensorium::Matrix< K, RowMajor >::mul_vec(), tensorium::Matrix< K, RowMajor >::operator*(), tensorium::operator+(), tensorium::operator-(), tensorium::Vector< T >::print(), tensorium_RG::print_vector(), tensorium::solver::Jacobi< K >::solve(), tensorium_RG::spectral_derivative_1D(), and tensorium::SpectralFFT< T >::transform_impl().
| const Vector<float>& tensorium::Vector< K >::b |
| r tensorium::Vector< K >::data[2] = u.data[1] * v.data[2] - u.data[2] * v.data[1] |
| 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().
| const float tensorium::Vector< K >::dot = u.dot(v) |
Referenced by tensorium::dot_vec().
| size_t tensorium::Vector< K >::i = 0 |
| const size_t tensorium::Vector< K >::n = a.size() |
| 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 |
| return tensorium::Vector< K >::result |
Referenced by tensorium::Vector< T >::__attribute__(), and tensorium::Vector< T >::__attribute__().
| const size_t tensorium::Vector< K >::simd_width = Simd::width |
| const Vector<float> float tensorium::Vector< K >::t |
| const Vector< float > & tensorium::Vector< K >::v |
| tensorium::Vector< K >::void |
| const reg tensorium::Vector< K >::vt = Simd::set1(t) |
| const reg tensorium::Vector< K >::vt1 = Simd::sub(Simd::set1(1.0f), vt) |