H2Lib
3.0
|
Representation of a matrix as an array in column-major order. More...
Data Structures | |
struct | _amatrix |
Representation of a matrix as an array in column-major order. More... | |
Typedefs | |
typedef struct _amatrix | amatrix |
Representation of a matrix as a column-order array. | |
typedef amatrix * | pamatrix |
Pointer to amatrix object. | |
typedef const amatrix * | pcamatrix |
Pointer to constant amatrix object. | |
Functions | |
pamatrix | init_amatrix (pamatrix a, uint rows, uint cols) |
Initialize an amatrix object. More... | |
pamatrix | init_sub_amatrix (pamatrix a, pamatrix src, uint rows, uint roff, uint cols, uint coff) |
Initialize an amatrix object to represent a submatrix. More... | |
pamatrix | init_vec_amatrix (pamatrix a, pavector src, uint rows, uint cols) |
Initialize an amatrix object by a vector. More... | |
pamatrix | init_pointer_amatrix (pamatrix a, pfield src, uint rows, uint cols) |
Initialize an amatrix object using a given array for the coefficients. More... | |
pamatrix | init_zero_amatrix (pamatrix a, uint rows, uint cols) |
Initialize an amatrix object and set it to zero. More... | |
pamatrix | init_identity_amatrix (pamatrix a, uint rows, uint cols) |
Initialize an amatrix object and set it to identity. More... | |
void | uninit_amatrix (pamatrix a) |
Uninitialize an amatrix object. More... | |
pamatrix | new_amatrix (uint rows, uint cols) |
Create a new amatrix object. More... | |
pamatrix | new_sub_amatrix (pamatrix src, uint rows, uint roff, uint cols, uint coff) |
Create a new amatrix object representing a submatrix. More... | |
pamatrix | new_pointer_amatrix (field *src, uint rows, uint cols) |
Create a new amatrix object using a given array for the coefficients. More... | |
pamatrix | new_zero_amatrix (uint rows, uint cols) |
Create a new amatrix object representing a zero matrix. More... | |
pamatrix | new_identity_amatrix (uint rows, uint cols) |
Create a new amatrix object representing the identity. More... | |
void | del_amatrix (pamatrix a) |
Delete an amatrix object. More... | |
void | resize_amatrix (pamatrix a, uint rows, uint cols) |
Change the dimensions of an amatrix object without preserving its coefficients. More... | |
void | resizecopy_amatrix (pamatrix a, uint rows, uint cols) |
Change the dimensions of an amatrix object while preserving as many of its coefficients as possible. More... | |
field | getentry_amatrix (pcamatrix a, uint row, uint col) |
Read a matrix entry . More... | |
void | setentry_amatrix (pamatrix a, uint row, uint col, field x) |
Set a matrix entry, . More... | |
field | addentry_amatrix (pamatrix a, uint row, uint col, field x) |
Add to a matrix entry, . More... | |
uint | getactives_amatrix () |
Get number of currently initialized amatrix objects. More... | |
size_t | getsize_amatrix (pcamatrix a) |
Get size of a given amatrix object. More... | |
size_t | getsize_heap_amatrix (pcamatrix a) |
Get heap size of a given amatrix object. More... | |
void | clear_amatrix (pamatrix a) |
Set a matrix to zero. More... | |
void | clear_lower_amatrix (pamatrix a, bool strict) |
Set the lower triangular part of a matrix to zero. More... | |
void | clear_upper_amatrix (pamatrix a, bool strict) |
Set the upper triangular part of a matrix to zero. More... | |
void | identity_amatrix (pamatrix a) |
Set a matrix to identity. More... | |
void | random_amatrix (pamatrix a) |
Fill a matrix with random values. More... | |
void | random_invertible_amatrix (pamatrix a, real alpha) |
Fill a square matrix with random values and ensure that it is invertible. More... | |
void | random_selfadjoint_amatrix (pamatrix a) |
Fill a matrix with random values and ensure that it is self-adjoint. More... | |
void | random_spd_amatrix (pamatrix a, real alpha) |
Fill a matrix with random values and ensure that it is positive definite. More... | |
void | copy_amatrix (bool atrans, pcamatrix a, pamatrix b) |
Copy a matrix into another matrix, or . More... | |
void | copy_colpiv_amatrix (bool atrans, pcamatrix a, const uint *colpiv, pamatrix b) |
Copy a matrix into another matrix, permuting the columns, i.e., or . More... | |
pamatrix | clone_amatrix (pcamatrix src) |
Create a duplicate of an existing amatrix. More... | |
void | copy_sub_amatrix (bool atrans, pcamatrix a, pamatrix b) |
Copy a matrix into another matrix, or . More... | |
void | print_amatrix (pcamatrix a) |
Print a matrix. More... | |
void | print_matlab_amatrix (pcamatrix a) |
Print a matrix in Matlab format. More... | |
real | check_ortho_amatrix (bool atrans, pcamatrix a) |
Check whether a matrix or its adjoint is isometric. More... | |
void | scale_amatrix (field alpha, pamatrix a) |
Scale a matrix by a factor , . More... | |
void | conjugate_amatrix (pamatrix a) |
compute the complex conjugate of a matrix . More... | |
field | dotprod_amatrix (pcamatrix a, pcamatrix b) |
Compute the Frobenius inner product of two matrices and . More... | |
real | norm2_amatrix (pcamatrix A) |
Approximate the spectral norm of a matrix . More... | |
real | normfrob_amatrix (pcamatrix a) |
Compute the Frobenius norm of a matrix . More... | |
real | normfrob2_amatrix (pcamatrix a) |
Compute the squared Frobenius norm of a matrix . More... | |
real | norm2diff_amatrix (pcamatrix a, pcamatrix b) |
Approximate the spectral norm of the difference of two matrices and . More... | |
void | addeval_amatrix_avector (field alpha, pcamatrix a, pcavector src, pavector trg) |
Multiply a matrix by a vector , . More... | |
void | addevaltrans_amatrix_avector (field alpha, pcamatrix a, pcavector src, pavector trg) |
Multiply the adjoint of a matrix by a vector , . More... | |
void | mvm_amatrix_avector (field alpha, bool atrans, pcamatrix a, pcavector src, pavector trg) |
Multiply a matrix or its adjoint by a vector, or . More... | |
void | add_amatrix (field alpha, bool atrans, pcamatrix a, pamatrix b) |
Add two matrices, or . More... | |
void | addmul_amatrix (field alpha, bool atrans, pcamatrix a, bool btrans, pcamatrix b, pamatrix c) |
Multiply two matrices, , , or . More... | |
void | bidiagmul_amatrix (field alpha, bool atrans, pamatrix a, pcavector d, pcavector l) |
Multiply a matrix by a bidiagonal matrix, or . More... | |
Representation of a matrix as an array in column-major order.
The amatrix class is used to handle standard linear algebra operations like matrix multiplication, factorization, solving linear systems or eigenvalue problems.
Add two matrices, or .
alpha | Scaling factor . |
atrans | Set if is to be added instead of . |
a | Source matrix . |
b | Target matrix . |
Add to a matrix entry, .
a | Matrix . |
row | Row index . |
col | Column index . |
x | Summand. |
Multiply a matrix by a vector , .
The matrix is multiplied by the source vector , the result is scaled by and added to the target vector .
alpha | Scaling factor . |
a | Matrix . |
src | Source vector . |
trg | Target vector . |
Multiply the adjoint of a matrix by a vector , .
The adjoint is multiplied by the source vector , the result is scaled by and added to the target vector .
alpha | Scaling factor . |
a | Matrix . |
src | Source vector . |
trg | Target vector . |
Multiply two matrices, , , or .
The matrices (or ) and (or ) are multiplied, the result is scaled by and added to the target matrix .
alpha | Scaling factor . |
atrans | Set if is to be used instead of . |
a | Left factor . |
btrans | Set if is to be used instead of . |
b | Right factor . |
c | Target matrix . |
Multiply a matrix by a bidiagonal matrix, or .
The matrix (or ) is multiplied by the lower bidiagonal matrix described by the diagonal vector and the subdiagonal vector , the result is scaled by and written back into , i.e., or (adding zeros to for the last column or row).
alpha | Scaling factor . |
atrans | Set if is to be used instead of . |
a | Matrix . |
d | Diagonal entries of . |
l | Subdiagonal entries of . |
Check whether a matrix or its adjoint is isometric.
Compute either or . If the return value is small, or are isometric matrices. For square matrices, this also means that they are orthogonal.
atrans | Set if is to be checked, otherwise is used. |
a | Matrix . |
atrans==false
and otherwise. void clear_amatrix | ( | pamatrix | a | ) |
Set a matrix to zero.
a | Target matrix. |
Set the lower triangular part of a matrix to zero.
a | Target matrix. |
strict | If set, only the strict lower triangular part should be cleared. |
Set the upper triangular part of a matrix to zero.
a | Target matrix. |
strict | If set, only the strict upper triangular part should be cleared. |
Create a duplicate of an existing amatrix.
src | Matrix to be duplicated. |
src
. void conjugate_amatrix | ( | pamatrix | a | ) |
compute the complex conjugate of a matrix .
a | Matrix that will be conjugated. |
Copy a matrix into another matrix, or .
The numbers of rows and columns have to match.
atrans | Set if is to be used instead of . |
a | Source matrix. |
b | Target matrix. |
Copy a matrix into another matrix, permuting the columns, i.e., or .
The numbers of rows and columns have to match.
atrans | Set if is to be used instead of . |
a | Source matrix. |
colpiv | Array of dimension a->cols containing the column indices. |
b | Target matrix. |
Copy a matrix into another matrix, or .
If is smaller than (or ), only the upper left part of is copied. If (or ) is smaller than , only the upper left part of is filled.
atrans | Set if is to be used instead of . |
a | Source matrix. |
b | Target matrix. |
void del_amatrix | ( | pamatrix | a | ) |
Delete an amatrix object.
Releases the storage corresponding to the object.
a | Object to be deleted. |
Compute the Frobenius inner product of two matrices and .
The Frobenius inner product is given by .
a | Matrix . |
b | Matrix . |
uint getactives_amatrix | ( | ) |
Get number of currently initialized amatrix objects.
Calls to initialization functions like init_amatrix and constructors like new_amatrix increase an internal counter, while uninit_amatrix and del_amatrix decrease it.
Read a matrix entry .
a | Matrix . |
row | Row index . |
col | Column index . |
size_t getsize_amatrix | ( | pcamatrix | a | ) |
Get size of a given amatrix object.
Computes the size of the amatrix object and the storage allocated for the coefficients. If the object uses the coefficients of another object (e.g., if it was created using new_sub_amatrix), no coefficient storage is added.
a | Matrix object. |
size_t getsize_heap_amatrix | ( | pcamatrix | a | ) |
Get heap size of a given amatrix object.
Computes the size of storage allocated for the coefficients on the heap, but not for the amatrix object itself. If the object uses the coefficients of another object (e.g., if it was created using new_sub_amatrix), no storage is required.
a | Matrix object. |
void identity_amatrix | ( | pamatrix | a | ) |
Set a matrix to identity.
Sets all diagonal entries to one and all off-diagonal entries to zero. For square matrices, this yields an identity matrix.
a | Target matrix. |
Initialize an amatrix object.
Sets up the components of the object and allocates storage for the coefficient array.
a | Object to be initialized. |
rows | Number of rows. |
cols | Number of columns. |
Initialize an amatrix object and set it to identity.
Sets up the components of the object, allocates storage for the coefficient array, sets the diagonal to one and all off-diagonal entries to zero. For square matrices, this yields an identity matrix.
a | Object to be initialized. |
rows | Number of rows. |
cols | Number of columns. |
Initialize an amatrix object using a given array for the coefficients.
Sets up the components of the object and uses the given array to represent the coefficients.
a | Object to be initialized. |
src | Source array, should contain at least rows * cols elements. |
rows | Number of rows. |
cols | Number of columns. |
Initialize an amatrix object to represent a submatrix.
Sets up the components of the object and uses part of the storage of another amatrix for the coefficient array, leading to a new matrix representing a submatrix of the source. Changes to the coefficients of the new matrix also change coefficients of the source matrix.
a | Object to be initialized. |
src | Source matrix. |
rows | Number of rows. |
roff | Row offset, should satisfy rows+roff<=src->rows . |
cols | Number of columns. |
coff | Column offset, should satisfy cols+coff<=src->cols . |
Initialize an amatrix object by a vector.
Sets up the components of the object and uses part of the storage of an avector in order to represent the matrix.
a | Object to be initialized. |
src | Source vector. |
rows | Number of rows. |
cols | Number of columns. |
Initialize an amatrix object and set it to zero.
Sets up the components of the object, allocates storage for the coefficient array, and sets it to zero.
a | Object to be initialized. |
rows | Number of rows. |
cols | Number of columns. |
Multiply a matrix or its adjoint by a vector, or .
The matrix or its adjoint is multiplied by the source vector , the result is scaled by and added to the target vector .
alpha | Scaling factor . |
atrans | Set if is to be used instead of . |
a | Matrix . |
src | Source vector . |
trg | Target vector . |
Create a new amatrix object.
Allocates storage for the object and sets up its components.
rows | Number of rows. |
cols | Number of columns. |
Create a new amatrix object representing the identity.
Allocates storage for the object and sets diagonal entries to one and off-diagonal entries to zero. For square matrices, this yields an identity matrix.
rows | Number of rows. |
cols | Number of columns. |
Create a new amatrix object representing a submatrix.
Allocates storage for the object, but uses part of the storage of another amatrix object to keep the coefficients. Since the leading dimension of the source matrix is used, this allows us to work with a rectangular submatrix of the original matrix.
src | Source matrix. |
rows | Number of rows. |
roff | Row offset, should satisfy rows+roff<=src->rows . |
cols | Number of columns. |
coff | Column offset, should satisfy cols+coff<=src->cols . |
Create a new amatrix object representing a zero matrix.
Allocates storage for the object and sets all coefficients to zero.
rows | Number of rows. |
cols | Number of columns. |
Approximate the spectral norm of a matrix .
The spectral norm is approximated by applying a few steps of the power iteration to the matrix and computing the square root of the resulting eigenvalue approximation.
A | Dense matrix . |
Approximate the spectral norm of the difference of two matrices and .
The spectral norm is approximated by applying a few steps of the power iteration to the matrix and computing the square root of the resulting eigenvalue approximation.
a | Dense matrix . |
b | Dense matrix . |
Compute the squared Frobenius norm of a matrix .
The Frobenius norm is given by .
a | Matrix . |
Compute the Frobenius norm of a matrix .
The Frobenius norm is given by .
a | Matrix . |
void print_amatrix | ( | pcamatrix | a | ) |
Print a matrix.
a | Matrix object. |
void print_matlab_amatrix | ( | pcamatrix | a | ) |
Print a matrix in Matlab format.
a | Matrix object. |
void random_amatrix | ( | pamatrix | a | ) |
Fill a matrix with random values.
a | Target matrix. |
Fill a square matrix with random values and ensure that it is invertible.
First the matrix is filled with random values, then the diagonal elements are set to , ensuring that is diagonal dominant and therefore invertible.
a | Target matrix. |
alpha | Diagonal shift , should be a positive number. |
void random_selfadjoint_amatrix | ( | pamatrix | a | ) |
Fill a matrix with random values and ensure that it is self-adjoint.
a | Target matrix. |
Fill a matrix with random values and ensure that it is positive definite.
First the matrix is filled with random values, ensuring that it becomes self-adjoint. Then the diagonal elements are set to , ensuring that is diagonal dominant and therefore positiv definite.
a | Target matrix. |
alpha | Diagonal shift , should be a positiv number. |
Change the dimensions of an amatrix object without preserving its coefficients.
Allocates new storage for the coefficients and releases the old storage.
a | Matrix to be resized. |
rows | New number of rows. |
cols | New number of columns. |
Change the dimensions of an amatrix object while preserving as many of its coefficients as possible.
Allocates new storage for the coefficients and copies as many of the old coefficients into it. If there are more rows or columns in the new matrix, the additional coefficients are left unintialized.
a | Matrix to be resized. |
rows | New number of rows. |
cols | New number of columns. |
Scale a matrix by a factor , .
alpha | Scaling factor . |
a | Target matrix . |
Set a matrix entry, .
a | Matrix . |
row | Row index . |
col | Column index . |
x | New value of . |