Linear algebra¶
The algebra.h
file provides a few functions for linear
algebra operations. Thoese functions include calculating the norm of a vector, computing inner product of vectors, performing matrix vector operations, etc. We provide both naive implementation (under namespace MyAlgebra) and (Sparse) BLAS based implementation (under namespace BLASAlgebra) for these functions. You can specify the namespace through the algebra_namespace_switcher.h
header file.
-
algebra.h
Vector functions
-
double
norm
(Vector &x, int type)¶ Return the norm of a vector of different type:
- type = 0: \(\ell_0\) norm, the number of nonzeros;
- type = 1: \(\ell_1\) norm. Sum of the absolute values;
- type = 2: \(\ell_2\) norm. Euclidean norm;
- type = 3: \(\ell_\infty\) norm. Maximum of the absolute value.
-
void
copy
(Vector &x, Vector &y, int start, int end)¶ Copy part of a vector to another vector, i.e., y = x(start:end)
Matrix functions
-
void
calculate_column_norm
(Matrix &A, Vector &nrm)¶ Calculate the \(\ell_2\) norm for each column of dense matrix A.
-
void
calculate_column_norm
(SpMat &A, Vector &nrm)¶ Calculate the \(\ell_2\) norm for each column of sparse matrix A.
-
void
multiply
(SpMat &A, SpMat &AAt)¶ Multiply A with A’, i.e., AAt = A * A’
-
void
copy
(Matrix &A, Matrix &B, int start, int end)¶ Copy part of a dense matrix to another dense matrix, i.e., B = A(start:end, :)
-
void
copy
(SpMat &A, SpMat &B, int start, int end)¶ Copy part of a sparse matrix to another sparse matrix, i.e., B = A(start:end, :)
Matrix vector functions
-
void
sub
(Vector &a, Matrix &A, int row, double scalar)¶ Subtract a scalar times a row of matrix from a given vector, i.e., a = a - scalar * A(row, :)
-
void
sub
(Vector &a, SpMat &A, int row, double scalar)¶ Subtract a scalar times a row of matrix from a given vector, i.e., a = a - scalar * A(row, :)
-
void
sub
(SpVec &a, SpMat &A, int row, double scalar)¶ Subtract a scalar times a row of matrix from a given vector, i.e., a = a - scalar * A(row, :)
-
void
sub
(SpVec &a, Matrix &A, int row, double scalar)¶ Subtract a scalar times a row of matrix from a given vector, i.e., a = a - scalar * A(row, :)
-
void
multiply
(SpMat &A, Vector &x, Vector &Ax)¶ multiply sparse matrix A with x, i.e., \(Ax = A \cdot x\)
-
void
multiply
(Matrix &A, Vector &x, Vector &Ax)¶ multiply dense matrix A with x, i.e., \(Ax = A \cdot x\)
Print functions
-
void
print
(SpMat &x)¶ Print the sparse matrix.
-
double