|
Tensorium
|
High-performance aligned matrix class with SIMD support. More...
#include <Matrix.hpp>
Public Types | |
| using | Simd = simd::SimdTraits<K, DefaultISA> |
| using | reg = typename Simd::reg |
Public Member Functions | |
| Matrix (size_t r, size_t c) | |
| Construct a matrix of size r × c, initialized with zeros. | |
| size_t | index (size_t i, size_t j) const |
| size_t | size () const |
| Return the total number of elements. | |
| K & | operator() (size_t i, size_t j) |
| Element access (mutable). | |
| const K & | operator() (size_t i, size_t j) const |
| void | print () const |
| Print the matrix to stdout. | |
| void | swap_rows (size_t i, size_t j) |
| Swap two rows of the matrix. | |
| template<typename T> | |
| Vector< T > | operator* (const Vector< T > &v) const |
| Multiply matrix by a vector (naïve fallback). | |
| void | add (const Matrix &m) |
| In-place matrix addition: this += m. | |
| void | sub (const Matrix &m) |
| In-place matrix subtraction: this -= m. | |
| void | scl (K a) |
| In-place scalar multiplication: this *= a. | |
| void | lerp (const Matrix< K > &A, const Matrix< K > &B, K alpha) |
| Linearly interpolate between two matrices: this = (1 - α) * A + α * B. | |
| Matrix | _mul_mat (const Matrix< K > &mat) const |
| Multiply matrix by another matrix using optimized SIMD path. | |
| template<typename T> | |
| Vector< T > | mul_vec (const Vector< T > &x) const |
| Multiply matrix by a vector using SIMD. | |
| Matrix< K > | transpose () const |
| Returns the transpose \( A^T \) of the matrix (column-major layout). | |
| Matrix< K > | trace () const |
| Returns the trace of a square matrix as a 1×1 matrix. | |
| Matrix< K > | inverse () const |
| Compute the inverse of the matrix using Gauss–Jordan elimination. | |
| K | det () const |
| Compute the determinant using Gaussian elimination. | |
| size_t | rank (K eps=K(1e-6)) const |
| Compute the numerical rank of the matrix. | |
| Matrix & | operator+= (const Matrix &m) |
| Matrix & | operator-= (const Matrix &m) |
| Matrix & | operator*= (K alpha) |
Public Attributes | |
| size_t | rows |
| size_t | cols |
| aligned_vector< K > | data |
| size_t | block_size |
| bool | iscolumn |
| size_t | simd_width = Simd::width |
High-performance aligned matrix class with SIMD support.
This class provides a dense matrix container with:
| K | Scalar type (float, double, etc.) |
| using tensorium::Matrix< K, RowMajor >::reg = typename Simd::reg |
| using tensorium::Matrix< K, RowMajor >::Simd = simd::SimdTraits<K, DefaultISA> |
|
inline |
Construct a matrix of size r × c, initialized with zeros.
References block_size, cols, data, detect_optimal_block_size(), and rows.
Referenced by _mul_mat(), add(), det(), inverse(), lerp(), operator*=(), operator+=(), operator-=(), rank(), sub(), trace(), and transpose().
|
inline |
Multiply matrix by another matrix using optimized SIMD path.
Uses blocking and micro-kernels to avoid cache bottleneck with FMA/AVX units repartition. Fast-paths exist for 4×4, 8×8, and 16×16.
References cols, data, Matrix(), and rows.
Referenced by tensorium::mul_mat(), and tensorium::operator*().
|
inline |
In-place matrix addition: this += m.
References _MM_HINT_T0, _mm_prefetch, cols, data, Matrix(), rows, simd_width, and size().
Referenced by tensorium::add_mat(), tensorium::operator+(), and operator+=().
|
inline |
Compute the determinant using Gaussian elimination.
\[\det A = \prod_{i=1}^n U_{ii} \quad \text{with } A = LU \]
References MathsUtils::_abs(), cols, det(), Matrix(), operator()(), rows, simd_width, and swap_rows().
Referenced by det(), and tensorium::det_mat().
|
inline |
|
inline |
Compute the inverse of the matrix using Gauss–Jordan elimination.
Throws if the matrix is singular or not square. need to add a fallback for unsquare matrix if possible
References MathsUtils::_abs(), cols, Matrix(), operator()(), rows, and swap_rows().
Referenced by tensorium_RG::__attribute__(), tensorium::inv_mat_tensor(), tensorium::inverse_mat(), tensorium_RG::Metric< T >::invert_metric_tensor(), and tensorium_RG::Metric< T >::invert_spatial_metric().
|
inline |
Linearly interpolate between two matrices: this = (1 - α) * A + α * B.
References cols, data, Matrix(), rows, simd_width, and size().
Referenced by tensorium::lerp_mat().
|
inline |
Multiply matrix by a vector using SIMD.
This is a faster alternative to operator* when available.
References cols, rows, and tensorium::Vector< K >::size().
Referenced by tensorium::mul_vec().
|
inline |
|
inline |
|
inline |
Multiply matrix by a vector (naïve fallback).
\[(Ax)_i = \sum_j A_{ij} x_j \]
References cols, rows, and tensorium::Vector< K >::size().
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Compute the numerical rank of the matrix.
Performs row echelon reduction and counts non-zero pivots.
References MathsUtils::_abs(), cols, Matrix(), rows, and swap_rows().
Referenced by tensorium::rank_mat().
|
inline |
In-place scalar multiplication: this *= a.
References _MM_HINT_T0, _mm_prefetch, data, simd_width, and size().
Referenced by tensorium::operator*(), operator*=(), and tensorium::scl_mat().
|
inline |
|
inline |
In-place matrix subtraction: this -= m.
References _MM_HINT_T0, _mm_prefetch, cols, data, Matrix(), rows, simd_width, and size().
Referenced by tensorium::operator-(), operator-=(), and tensorium::sub_mat().
|
inline |
Swap two rows of the matrix.
References MathsUtils::_swap(), cols, and rows.
Referenced by det(), inverse(), rank(), and tensorium::solver::Gauss< K >::raw_row_echelon().
|
inline |
Returns the trace of a square matrix as a 1×1 matrix.
References cols, Matrix(), operator()(), and rows.
Referenced by tensorium::trace_mat().
|
inline |
Returns the transpose \( A^T \) of the matrix (column-major layout).
References cols, Matrix(), and rows.
Referenced by tensorium::transpose_mat().
| size_t tensorium::Matrix< K, RowMajor >::block_size |
Referenced by Matrix().
| size_t tensorium::Matrix< K, RowMajor >::cols |
Referenced by _mul_mat(), add(), det(), index(), inverse(), lerp(), tensorium::lerp_mat(), Matrix(), tensorium::matrix_to_tensor(), tensorium::MatrixKernel< K >::MatrixKernel(), tensorium::mul_mat(), mul_vec(), operator*(), print(), rank(), tensorium::solver::Gauss< K >::raw_row_echelon(), size(), tensorium::solver::Jacobi< K >::solve(), sub(), swap_rows(), trace(), and transpose().
| aligned_vector<K> tensorium::Matrix< K, RowMajor >::data |
Referenced by _mul_mat(), add(), lerp(), Matrix(), tensorium::MatrixKernel< K >::mul_mat16x16(), tensorium::MatrixKernel< K >::mul_mat2x2(), tensorium::MatrixKernel< K >::mul_mat32x32(), tensorium::MatrixKernel< K >::mul_mat4x4(), tensorium::MatrixKernel< K >::mul_mat64x64(), tensorium::MatrixKernel< K >::mul_mat8x8(), operator()(), operator()(), scl(), and sub().
| bool tensorium::Matrix< K, RowMajor >::iscolumn |
| size_t tensorium::Matrix< K, RowMajor >::rows |
Referenced by _mul_mat(), add(), det(), index(), inverse(), lerp(), tensorium::lerp_mat(), Matrix(), tensorium::matrix_to_tensor(), tensorium::MatrixKernel< K >::MatrixKernel(), tensorium::mul_mat(), mul_vec(), operator*(), print(), rank(), tensorium::solver::Gauss< K >::raw_row_echelon(), size(), tensorium::solver::Jacobi< K >::solve(), sub(), swap_rows(), trace(), and transpose().
| size_t tensorium::Matrix< K, RowMajor >::simd_width = Simd::width |