CorrSolver 1.2.7; VERSION ${PROJECT_VERSION}
Loading...
Searching...
No Matches
Functions
linalg.hpp File Reference

Minimal linear algebra helpers for Arr (transpose, matmul, Cholesky, inverse, etc.). More...

#include <ellalgo/arr.hpp>
#include <random>
Include dependency graph for linalg.hpp:

Go to the source code of this file.

Functions

Arr transpose (const Arr &a)
 Transpose a 2D matrix.
 
Arr flatten (const Arr &a)
 Flatten a matrix or vector into a 1D array.
 
Arr diagonal (const Arr &a)
 Extract the diagonal of a square matrix.
 
double trace (const Arr &a)
 Compute the trace of a square matrix (sum of diagonal elements).
 
double norm (const Arr &a)
 Compute the Frobenius norm of an array.
 
Arr matmul (const Arr &A, const Arr &B)
 Multiply two matrices: A * B.
 
Arr cholesky (const Arr &A)
 Cholesky decomposition: A = L * L^T for SPD matrices.
 
Arr inv (const Arr &A)
 Compute the inverse of a symmetric positive definite matrix via Cholesky.
 
std::mt19937_64 & global_rng ()
 Get the global Mersenne Twister random number generator.
 
void random_seed (unsigned seed)
 Seed the global random number generator.
 
Arr randn (size_t n)
 Generate a vector of standard normal random numbers.
 
std::pair< Arr, Arr > meshgrid (const Arr &x, const Arr &y)
 Create 2D meshgrid arrays from 1D coordinate vectors.
 
Arr stack (const Arr &a, const Arr &b, int=0)
 Stack two 1D arrays as rows into a 2D matrix.
 

Detailed Description

Minimal linear algebra helpers for Arr (transpose, matmul, Cholesky, inverse, etc.).

Function Documentation

◆ cholesky()

Arr cholesky ( const Arr &  A)
inline

Cholesky decomposition: A = L * L^T for SPD matrices.

\[ A = LL^T, \quad L_{jj} = \sqrt{A_{jj} - \sum_{k=1}^{j-1} L_{jk}^2}, \quad L_{ij} = \frac{1}{L_{jj}}\Bigl(A_{ij} - \sum_{k=1}^{j-1} L_{ik} L_{jk}\Bigr) \]

Parameters
ASymmetric positive definite matrix
Returns
Lower-triangular Cholesky factor L

◆ diagonal()

Arr diagonal ( const Arr &  a)
inline

Extract the diagonal of a square matrix.

Parameters
aInput square matrix
Returns
1D array containing diagonal elements

◆ flatten()

Arr flatten ( const Arr &  a)
inline

Flatten a matrix or vector into a 1D array.

Parameters
aInput array
Returns
Flattened 1D array

◆ global_rng()

std::mt19937_64 & global_rng ( )
inline

Get the global Mersenne Twister random number generator.

Returns
Reference to the global RNG

◆ inv()

Arr inv ( const Arr &  A)
inline

Compute the inverse of a symmetric positive definite matrix via Cholesky.

Computes \(A^{-1}\) by solving \(LY = I\) (forward substitution) then \(L^T X = Y\) (back substitution).

Parameters
ASPD matrix
Returns
Inverse matrix

◆ matmul()

Arr matmul ( const Arr &  A,
const Arr &  B 
)
inline

Multiply two matrices: A * B.

\[ (AB)_{ij} = \sum_{k=1}^{p} A_{ik} B_{kj} \]

Parameters
ALeft matrix (m x k)
BRight matrix (k x n)
Returns
Result matrix (m x n)

◆ meshgrid()

std::pair< Arr, Arr > meshgrid ( const Arr &  x,
const Arr &  y 
)
inline

Create 2D meshgrid arrays from 1D coordinate vectors.

Parameters
x1D x-coordinates
y1D y-coordinates
Returns
Pair of 2D arrays (XX, YY)

◆ norm()

double norm ( const Arr &  a)
inline

Compute the Frobenius norm of an array.

\( \|A\|_F = \sqrt{\sum_{i}\sum_{j} A_{ij}^2} \)

Parameters
aInput array
Returns
Frobenius norm

◆ randn()

Arr randn ( size_t  n)
inline

Generate a vector of standard normal random numbers.

Parameters
nNumber of elements
Returns
1D array of i.i.d. N(0,1) samples

◆ random_seed()

void random_seed ( unsigned  seed)
inline

Seed the global random number generator.

Parameters
seedThe seed value

◆ stack()

Arr stack ( const Arr &  a,
const Arr &  b,
int  = 0 
)
inline

Stack two 1D arrays as rows into a 2D matrix.

Parameters
aFirst row
bSecond row
Returns
2D matrix with two rows

◆ trace()

double trace ( const Arr &  a)
inline

Compute the trace of a square matrix (sum of diagonal elements).

\( \operatorname{tr}(A) = \sum_{i=1}^{n} A_{ii} \)

Parameters
aInput square matrix
Returns
Trace value

◆ transpose()

Arr transpose ( const Arr &  a)
inline

Transpose a 2D matrix.

Minimal linear algebra helpers for Arr, replacing xtensor-blas operations. For small FIR/correlation problems, naive O(n^3) is sufficient.

\[ (A^T)_{ij} = A_{ji} \]

Parameters
aInput matrix
Returns
Transposed matrix