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. | |
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.
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 tensorium::Matrix< K, RowMajor >::cols, tensorium::Matrix< K, RowMajor >::data, tensorium::GemmKernelBigger< T >::matmul(), and tensorium::Matrix< K, RowMajor >::rows.
In-place matrix addition: this += m.
References tensorium::Matrix< K, RowMajor >::cols, tensorium::Matrix< K, RowMajor >::data, tensorium::Matrix< K, RowMajor >::rows, tensorium::Matrix< K, RowMajor >::simd_width, and tensorium::Matrix< K, RowMajor >::size().
|
inline |
Compute the determinant using Gaussian elimination.
\[ \det A = \prod_{i=1}^n U_{ii} \quad \text{with } A = LU \]
References MathsUtils::_abs(), tensorium::Matrix< K, RowMajor >::cols, tensorium::Matrix< K, RowMajor >::det(), f(), tensorium::Matrix< K, RowMajor >::operator()(), tensorium::Matrix< K, RowMajor >::rows, tensorium::Matrix< K, RowMajor >::simd_width, and tensorium::Matrix< K, RowMajor >::swap_rows().
Referenced by tensorium::Matrix< K, RowMajor >::det().
References tensorium::Matrix< K, RowMajor >::cols, and tensorium::Matrix< K, RowMajor >::rows.
Referenced by tensorium::Matrix< K, RowMajor >::operator()(), and tensorium::Matrix< K, RowMajor >::operator()().
|
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(), tensorium::Matrix< K, RowMajor >::cols, f(), tensorium::Matrix< K, RowMajor >::operator()(), tensorium::Matrix< K, RowMajor >::rows, and tensorium::Matrix< K, RowMajor >::swap_rows().
|
inline |
Linearly interpolate between two matrices: this = (1 - α) * A + α * B.
References alpha, tensorium::Matrix< K, RowMajor >::cols, tensorium::Matrix< K, RowMajor >::data, tensorium::Matrix< K, RowMajor >::rows, tensorium::Matrix< K, RowMajor >::simd_width, and tensorium::Matrix< K, RowMajor >::size().
Multiply matrix by a vector using SIMD.
This is a faster alternative to operator* when available.
References tensorium::Matrix< K, RowMajor >::cols, tensorium::Matrix< K, RowMajor >::rows, and tensorium::Vector< K >::size().
Element access (mutable)
References tensorium::Matrix< K, RowMajor >::data, and tensorium::Matrix< K, RowMajor >::index().
Referenced by tensorium::Matrix< K, RowMajor >::det(), tensorium::Matrix< K, RowMajor >::inverse(), and tensorium::Matrix< K, RowMajor >::trace().
References tensorium::Matrix< K, RowMajor >::data, and tensorium::Matrix< K, RowMajor >::index().
Multiply matrix by a vector (naïve fallback)
\[ (Ax)_i = \sum_j A_{ij} x_j \]
References tensorium::Matrix< K, RowMajor >::cols, tensorium::Matrix< K, RowMajor >::rows, and tensorium::Vector< K >::size().
|
inline |
Print the matrix to stdout.
References tensorium::Matrix< K, RowMajor >::cols, and tensorium::Matrix< K, RowMajor >::rows.
Compute the numerical rank of the matrix.
Performs row echelon reduction and counts non-zero pivots.
References MathsUtils::_abs(), tensorium::Matrix< K, RowMajor >::cols, f(), tensorium::Matrix< K, RowMajor >::rows, and tensorium::Matrix< K, RowMajor >::swap_rows().
|
inline |
In-place scalar multiplication: this *= a.
References tensorium::Matrix< K, RowMajor >::data, tensorium::Matrix< K, RowMajor >::simd_width, and tensorium::Matrix< K, RowMajor >::size().
|
inline |
Return the total number of elements.
References tensorium::Matrix< K, RowMajor >::cols, and tensorium::Matrix< K, RowMajor >::rows.
Referenced by tensorium::Matrix< K, RowMajor >::add(), tensorium::Matrix< K, RowMajor >::lerp(), tensorium::Matrix< K, RowMajor >::scl(), and tensorium::Matrix< K, RowMajor >::sub().
In-place matrix subtraction: this -= m.
References tensorium::Matrix< K, RowMajor >::cols, tensorium::Matrix< K, RowMajor >::data, tensorium::Matrix< K, RowMajor >::rows, tensorium::Matrix< K, RowMajor >::simd_width, and tensorium::Matrix< K, RowMajor >::size().
Swap two rows of the matrix.
References MathsUtils::_swap(), tensorium::Matrix< K, RowMajor >::cols, and tensorium::Matrix< K, RowMajor >::rows.
Referenced by tensorium::Matrix< K, RowMajor >::det(), tensorium::Matrix< K, RowMajor >::inverse(), tensorium::Matrix< K, RowMajor >::rank(), and tensorium::solver::Gauss< K >::raw_row_echelon().
|
inline |
Returns the trace of a square matrix as a 1×1 matrix.
References tensorium::Matrix< K, RowMajor >::cols, tensorium::Matrix< K, RowMajor >::operator()(), and tensorium::Matrix< K, RowMajor >::rows.
|
inline |
Returns the transpose \( A^T \) of the matrix (column-major layout)
References tensorium::Matrix< K, RowMajor >::cols, and tensorium::Matrix< K, RowMajor >::rows.
Referenced by tensorium::Matrix< K, RowMajor >::_mul_mat(), tensorium::Matrix< K, RowMajor >::add(), tensorium::Matrix< K, RowMajor >::det(), tensorium::Matrix< K, RowMajor >::index(), tensorium::Matrix< K, RowMajor >::inverse(), tensorium::Matrix< K, RowMajor >::lerp(), tensorium::MatrixKernel< K >::MatrixKernel(), tensorium::Matrix< K, RowMajor >::mul_vec(), tensorium::Matrix< K, RowMajor >::operator*(), tensorium::Matrix< K, RowMajor >::print(), tensorium::Matrix< K, RowMajor >::rank(), tensorium::solver::Gauss< K >::raw_row_echelon(), tensorium::Matrix< K, RowMajor >::size(), tensorium::solver::Jacobi< K >::solve(), tensorium::Matrix< K, RowMajor >::sub(), tensorium::Matrix< K, RowMajor >::swap_rows(), tensorium::Matrix< K, RowMajor >::trace(), and tensorium::Matrix< K, RowMajor >::transpose().
aligned_vector<K> tensorium::Matrix< K, RowMajor >::data |
Referenced by tensorium::Matrix< K, RowMajor >::_mul_mat(), tensorium::Matrix< K, RowMajor >::add(), tensorium::Matrix< K, RowMajor >::lerp(), 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(), tensorium::Matrix< K, RowMajor >::operator()(), tensorium::Matrix< K, RowMajor >::operator()(), tensorium::Matrix< K, RowMajor >::scl(), and tensorium::Matrix< K, RowMajor >::sub().
Referenced by tensorium::Matrix< K, RowMajor >::_mul_mat(), tensorium::Matrix< K, RowMajor >::add(), tensorium::Matrix< K, RowMajor >::det(), tensorium::Matrix< K, RowMajor >::index(), tensorium::Matrix< K, RowMajor >::inverse(), tensorium::Matrix< K, RowMajor >::lerp(), tensorium::MatrixKernel< K >::MatrixKernel(), tensorium::Matrix< K, RowMajor >::mul_vec(), tensorium::Matrix< K, RowMajor >::operator*(), tensorium::Matrix< K, RowMajor >::print(), tensorium::Matrix< K, RowMajor >::rank(), tensorium::solver::Gauss< K >::raw_row_echelon(), tensorium::Matrix< K, RowMajor >::size(), tensorium::solver::Jacobi< K >::solve(), tensorium::Matrix< K, RowMajor >::sub(), tensorium::Matrix< K, RowMajor >::swap_rows(), tensorium::Matrix< K, RowMajor >::trace(), and tensorium::Matrix< K, RowMajor >::transpose().
size_t tensorium::Matrix< K, RowMajor >::simd_width = Simd::width |