File numerics/src/tools/NumericsMatrix.h

Contents

File numerics/src/tools/NumericsMatrix.h#

Go to the source code of this file

Structure definition and functions related to matrix storage in Numerics.

Typedefs

typedef enum NumericsMatrix_types NM_types#

Available types of storage for NumericsMatrix

typedef NumericsMatrix RawNumericsMatrix#

RawNumericsMatrix is used without conversion in python

Enums

enum NumericsMatrix_types#

Available types of storage for NumericsMatrix

Values:

enumerator NM_DENSE#

dense format

enumerator NM_SPARSE_BLOCK#

sparse block format

enumerator NM_SPARSE#

compressed column format

enumerator NM_UNKNOWN#

unset.

Used in NM_null

enum NM_gesv_opts#

Values:

enumerator NM_NONE#

keep nothing

enumerator NM_KEEP_FACTORS#

keep all the factorization data (useful to reuse the factorization)

enumerator NM_PRESERVE#

keep the matrix as-is (useful for the dense case)

Functions

RawNumericsMatrix *NM_new(void)#

Constructors and destructors

Creation of an empty NumericsMatrix.

Returns:

a pointer to allocated space

RawNumericsMatrix *NM_eye(int size)#
RawNumericsMatrix *NM_scalar(int size, double s)#
RawNumericsMatrix *NM_create(NM_types storageType, int size0, int size1)#

create a NumericsMatrix and allocate the memory according to the matrix type

Parameters:
  • storageType – the type of storage

  • size0 – number of rows

  • size1 – number of columns

Returns:

a pointer to a NumericsMatrix

RawNumericsMatrix *NM_create_from_data(int storageType, int size0, int size1, void *data)#

create a NumericsMatrix and possibly set the data

Parameters:
  • storageType – the type of storage

  • size0 – number of rows

  • size1 – number of columns

  • data – pointer to the matrix data. If NULL, all matrixX fields are set to NULL

Returns:

a pointer to a NumericsMatrix

RawNumericsMatrix *NM_create_from_filename(const char *filename)#
RawNumericsMatrix *NM_create_from_file(FILE *file)#
void NM_version_copy(const NumericsMatrix *const A, NumericsMatrix *B)#

Copy NumericsMatrix version.

Parameters:
void NM_copy(const NumericsMatrix *const A, NumericsMatrix *B)#

Copy a NumericsMatrix inside another NumericsMatrix (deep).

Reallocations are performed if B cannot hold a copy of A

Parameters:
void NM_copy_to_sparse(NumericsMatrix *A, NumericsMatrix *B, double threshold)#

Copy a NumericsMatrix to s sparse one.

Allocation or reallocation are performed on B

Warning

It is assumed that B has been properly initialized: its storageType must be set to NM_SPARSE.

Parameters:
  • A[in] a NumericsMatrix

  • B[inout] a NumericsMatrix

  • threshold – if the original matrix is dense, a threshold can be applied on the absolute value of the entries

RawNumericsMatrix *NM_duplicate(NumericsMatrix *mat)#

create a NumericsMatrix similar to the another one.

The structure is the same

Parameters:

mat – the model matrix

Returns:

a pointer to a NumericsMatrix

NumericsSparseMatrix *numericsSparseMatrix(NumericsMatrix *A)#

Creation, if needed, of sparse matrix storage.

Parameters:

A[inout] a NumericsMatrix

Returns:

a pointer on the sparse matrix storage

CSparseMatrix *NM_triplet(NumericsMatrix *A)#

Creation, if needed, of triplet storage from sparse block storage.

Parameters:

A[inout] a NumericsMatrix initialized with sparsed block storage.

Returns:

the triplet sparse Matrix created in A.

CSparseMatrix *NM_half_triplet(NumericsMatrix *A)#

Creation, if needed, of half triplet storage from sparse block storage.

Parameters:

A[inout] a NumericsMatrix initialized with sparsed block storage.

Returns:

the triplet sparse Matrix created in A.

CSparseMatrix *NM_csc(NumericsMatrix *A)#

Creation, if needed, of compress column storage of a NumericsMatrix.

Parameters:

A[inout] a NumericsMatrix with sparse block storage initialized

Returns:

the compressed column CSparseMatrix created in A.

CSparseMatrix *NM_csc_trans(NumericsMatrix *A)#

Creation, if needed, of the transposed compress column storage from compress column storage.

Parameters:

A[inout] a NumericsMatrix with sparse block storage.

Returns:

the transposed compressed column matrix created in A.

CSparseMatrix *NM_csr(NumericsMatrix *A)#

Creation, if needed, of compress row storage of a NumericsMatrix.

Warning

This rely on the MKL

Parameters:

A[inout] a NumericsMatrix with sparse block storage initialized

Returns:

the compressed row CSparseMatrix created in A.

void NM_fill(NumericsMatrix *M, NM_types storageType, int size0, int size1, void *data)#

fill an existing NumericsMatrix struct

Parameters:
  • M[inout] the struct to fill

  • storageType – the type of storage

  • size0 – number of rows

  • size1 – number of columns

  • data – pointer to the matrix data. If NULL, all matrixX fields are set to NULL

RawNumericsMatrix *NM_new_SBM(int size0, int size1, SparseBlockStructuredMatrix *m1)#

new NumericsMatrix with sparse storage from minimal set of data

Parameters:
Returns:

a pointer to a NumericsMatrix

RawNumericsMatrix *NM_transpose(NumericsMatrix *A)#

new NumericsMatrix equal to the transpose of a given matrix

Parameters:

A[in]

Returns:

a pointer to a NumericsMatrix

void NM_null(NumericsMatrix *A)#

set NumericsMatrix fields to NULL

Parameters:

A – a matrix

bool NM_destructible(const NumericsMatrix *A)#

Check if a matrix is destructible.

Parameters:

A[in] the NumericsMatrix

Returns:

true if the matrix is destructible

RawNumericsMatrix *NM_preserve(NumericsMatrix *A)#

Preservation of a matrix before in-place transformations such as factorizations.

Parameters:

A[in] the NumericsMatrix

Returns:

a pointer on the preserved Matrix;

RawNumericsMatrix *NM_unpreserve(NumericsMatrix *A)#

Set the matrix as destructible, clear the preserved data.

Parameters:

A[in] the NumericsMatrix

Returns:

a pointer on the Matrix;

bool NM_LU_factorized(const NumericsMatrix *const A)#

Check for a previous LU factorization.

Parameters:

A[in] the NumericsMatrix

Returns:

true if the matrix has been LU factorized.

bool NM_Cholesky_factorized(const NumericsMatrix *const A)#

Check for a previous Cholesky factorization.

Parameters:

A[in] the NumericsMatrix

Returns:

true if the matrix has been Cholesky factorized.

bool NM_LDLT_factorized(const NumericsMatrix *const A)#

Check for a previous LDLT factorization.

Parameters:

A[in] the NumericsMatrix

Returns:

true if the matrix has been Cholesky factorized.

void NM_set_LU_factorized(NumericsMatrix *A, bool flag)#

Set the factorization flag.

Parameters:
void NM_set_Cholesky_factorized(NumericsMatrix *A, bool flag)#
void NM_set_LDLT_factorized(NumericsMatrix *A, bool flag)#
void NM_update_size(NumericsMatrix *A)#

update the size of the matrix based on the matrix data

Parameters:

A[inout] the matrix which size is updated

void NM_csc_alloc(NumericsMatrix *A, CS_INT nzmax)#

Allocate a csc matrix in A.

Parameters:
  • A – the matrix

  • nzmax – number of non-zero elements

void NM_csc_empty_alloc(NumericsMatrix *A, CS_INT nzmax)#

Allocate a csc matrix in A and set the vector of column pointers to 0 such that the matrix is empty.

Parameters:
  • A – the matrix

  • nzmax – number of non-zero elements

void NM_triplet_alloc(NumericsMatrix *A, CS_INT nzmax)#

Allocate a triplet matrix in A.

Parameters:
  • A – the matrix

  • nzmax – maximum number of non-zero elements

void NM_clear(NumericsMatrix *m)#

Free memory for a NumericsMatrix.

Warning: call this function only if you are sure that memory has been allocated for the structure in Numerics. This function is assumed that the memory is “owned” by this structure. Note that this function does not free m.

Parameters:

m – the matrix to be deleted.

NumericsMatrix *NM_free(NumericsMatrix *m)#
void NM_clear_not_dense(NumericsMatrix *m)#

Free memory for a NumericsMatrix except the dense matrix that is assumed not to be owned.

Parameters:

m – the matrix to be cleared.

NumericsMatrix *NM_free_not_dense(NumericsMatrix *m)#
void NM_clear_not_SBM(NumericsMatrix *m)#

Free memory for a NumericsMatrix except the SBM matrix that is assumed not to be owned.

Note that this function does not free m.

Parameters:

m – the matrix to be cleared.

NumericsMatrix *NM_free_not_SBM(NumericsMatrix *m)#
void NM_clear_other_storages(NumericsMatrix *M, NM_types storageType)#

Free memory for a NumericsMatrix except for a given storage.

Warning: call this function only if you are sure that memory has been allocated for the structure in Numerics. This function is assumed that the memory is “owned” by this structure. Note that this function does not free m.

Parameters:
  • m – the matrix to be deleted.

  • storageType – to be kept.

void NM_zentry(NumericsMatrix *M, int i, int j, double val, double threshold)#

insert an non zero entry into a NumericsMatrix.

for storageType = NM_SPARSE, a conversion to triplet is done for performing the entry in the matrix. This method is expensive in terms of memory management. For a lot of entries, use preferably a triplet matrix.

Parameters:
  • M – the NumericsMatrix

  • i – row index

  • j – column index

  • val – the value to be inserted.

  • threshold – a threshold to filter the small value in magnitude (useful for dense to sparse conversion)

void NM_entry(NumericsMatrix *M, int i, int j, double val)#

insert an entry into a NumericsMatrix.

for storageType = NM_SPARSE, a conversion to triplet is done for performing the entry in the matrix. This method is expensive in terms of memory management. For a lot of entries, use preferably a triplet matrix.

Parameters:
  • M – the NumericsMatrix

  • i – row index

  • j – column index

  • val – the value to be inserted.

double NM_get_value(const NumericsMatrix *const M, int i, int j)#

get the value of a NumericsMatrix.

Parameters:
Returns:

the value to be inserted.

bool NM_equal(NumericsMatrix *A, NumericsMatrix *B)#

compare to NumericsMatrix up to machine accuracy (DBL_EPSILON)

Parameters:
bool NM_compare(NumericsMatrix *A, NumericsMatrix *B, double tol)#

compare to NumericsMatrix up to a given tolerance

Parameters:
size_t NM_nnz(const NumericsMatrix *M)#

return the number of non-zero element.

For a dense matrix, it is the product of the dimensions (e.g. an upper bound). For a sparse matrix, it is the true number

Parameters:

M – the matrix

Returns:

the number (or an upper bound) of non-zero elements in the matrix

void NM_extract_diag_block(NumericsMatrix *M, int block_row_nb, size_t start_row, int size, double **Block)#

get the (square) diagonal block of a NumericsMatrix.

No allocation is done.

Parameters:
  • M[in] a NumericsMatrix

  • block_row_nb[in] the number of the block Row. Useful only in sparse case

  • start_row[in] the starting row. Useful only in dense case.

  • size[in] of the diag block. Only useful in dense case.

  • Block[out] the target. In the dense and sparse case (*Block) must be allocated by caller. In case of SBM case **Bout contains the resulting block (from the SBM).

void NM_extract_diag_block3(NumericsMatrix *M, int block_row_nb, double **Block)#

get a 3x3 diagonal block of a NumericsMatrix.

No allocation is done.

Parameters:
  • M[in] a NumericsMatrix

  • block_row_nb[in] the number of the block row

  • Block[out] the target. In the dense and sparse case (*Block) must be allocated by caller. In case of SBM case **Bout contains the resulting block (from the SBM).

void NM_extract_diag_block2(NumericsMatrix *M, int block_row_nb, double **Block)#

get a 2x2 diagonal block of a NumericsMatrix.

No allocation is done.

Parameters:
  • M[in] a NumericsMatrix

  • block_row_nb[in] the number of the block row

  • Block[out] the target. In the dense and sparse case (*Block) must be allocated by caller. In case of SBM case **Bout contains the resulting block (from the SBM).

void NM_extract_diag_block5(NumericsMatrix *M, int block_row_nb, double **Block)#

get a 5x5 diagonal block of a NumericsMatrix.

No allocation is done.

Parameters:
  • M[in] a NumericsMatrix

  • block_row_nb[in] the number of the block row

  • Block[out] the target. In the dense and sparse case (*Block) must be allocated by caller. In case of SBM case **Bout contains the resulting block (from the SBM).

void NM_copy_diag_block3(NumericsMatrix *M, int block_row_nb, double **Block)#

get a 3x3 diagonal block of a NumericsMatrix.

No allocation is done.

Parameters:
  • M[in] a NumericsMatrix

  • block_row_nb[in] the number of the block row

  • Block[out] the target. In all cases (dense, sbm, and sparse) (*Block) must be allocated by caller. A copy is always performed

void NM_insert(NumericsMatrix *A, const NumericsMatrix *const B, const unsigned int start_i, const unsigned int start_j)#

Set the submatrix B into the matrix A on the position defined in (start_i, start_j) position.

Parameters:
  • A[in] a pointer to NumerixMatrix

  • B[in] a pointer toNumericsMatrix

  • start_i[in] a start row index

  • start_j[in] a start column index

void NM_prod_mv_3x3(int sizeX, int sizeY, NumericsMatrix *A, double *const x, double *y)#

Matrix - vector product y = A*x + y.

Parameters:
  • sizeX[in] dim of the vector x

  • sizeY[in] dim of the vector y

  • A[in] the matrix to be multiplied

  • x[in] the vector to be multiplied

  • y[inout] the resulting vector

void NM_row_prod(int sizeX, int sizeY, int currentRowNumber, NumericsMatrix *A, const double *const x, double *y, int init)#

Row of a Matrix - vector product y = rowA*x or y += rowA*x, rowA being a submatrix of A (sizeY rows and sizeX columns)

Parameters:
  • sizeX[in] dim of the vector x

  • sizeY[in] dim of the vector y

  • currentRowNumber[in] position of the first row of rowA in A (warning: real row if A is a double*, block-row if A is a SparseBlockStructuredMatrix)

  • A[in] the matrix to be multiplied

  • x[in] the vector to be multiplied

  • y[inout] the resulting vector

  • init[in] = 0 for y += Ax, =1 for y = Ax

void NM_row_prod_no_diag(size_t sizeX, size_t sizeY, int block_start, size_t row_start, NumericsMatrix *A, double *x, double *y, double *xsave, bool init)#

Row of a Matrix - vector product y = rowA*x or y += rowA*x, rowA being a submatrix of A (sizeY rows and sizeX columns)

Parameters:
  • sizeX[in] dim of the vector x

  • sizeY[in] dim of the vector y

  • block_start[in] block number (only used for SBM)

  • row_start[in] position of the first row of A (unused if A is SBM)

  • A[in] the matrix to be multiplied

  • x[in] the vector to be multiplied

  • y[inout] the resulting vector

  • xsave[in] storage for saving the part of x set to 0

  • init[in] if True y = Ax, else y += Ax

void NM_row_prod_no_diag3(size_t sizeX, int block_start, size_t row_start, NumericsMatrix *A, double *x, double *y, bool init)#

Row of a Matrix - vector product y = rowA*x or y += rowA*x, rowA being a submatrix of A (3 rows and sizeX columns)

Parameters:
  • sizeX[in] dim of the vector x

  • block_start[in] block number (only used for SBM)

  • row_start[in] position of the first row of A (unused if A is SBM)

  • A[in] the matrix to be multiplied

  • x[in] the vector to be multiplied

  • y[inout] the resulting vector

  • init[in] if True y = Ax, else y += Ax

void NM_row_prod_no_diag2(size_t sizeX, int block_start, size_t row_start, NumericsMatrix *A, double *x, double *y, bool init)#

Row of a Matrix - vector product y = rowA*x or y += rowA*x, rowA being a submatrix of A (2 rows and sizeX columns)

Parameters:
  • sizeX[in] dim of the vector x

  • block_start[in] block number (only used for SBM)

  • row_start[in] position of the first row of A (unused if A is SBM)

  • A[in] the matrix to be multiplied

  • x[in] the vector to be multiplied

  • y[inout] the resulting vector

  • init[in] if True y = Ax, else y += Ax

void NM_row_prod_no_diag1x1(size_t sizeX, int block_start, size_t row_start, NumericsMatrix *A, double *x, double *y, bool init)#
void NM_gemv(const double alpha, NumericsMatrix *A, const double *x, const double beta, double *y)#

Matrix vector multiplication : y = alpha A x + beta y.

Parameters:
  • alpha[in] scalar

  • A[in] a NumericsMatrix

  • x[in] pointer on a dense vector of size A->size1

  • beta[in] scalar

  • y[inout] pointer on a dense vector of size A->size1

void NM_gemm(const double alpha, NumericsMatrix *A, NumericsMatrix *B, const double beta, NumericsMatrix *C)#

Matrix matrix multiplication : C = alpha A B + beta C.

Parameters:
RawNumericsMatrix *NM_multiply(NumericsMatrix *A, NumericsMatrix *B)#

Matrix matrix multiplication : C = A B.

Parameters:
void NM_tgemv(const double alpha, NumericsMatrix *A, const double *x, const double beta, double *y)#

Transposed matrix multiplication : y += alpha transpose(A) x + y.

Parameters:
  • alpha[in] scalar

  • A[in] a NumericsMatrix

  • x[in] pointer on a dense vector of size A->size1

  • beta[in] scalar

  • y[inout] pointer on a dense vector of size A->size1

void NM_dense_to_sparse(NumericsMatrix *A, NumericsMatrix *B, double threshold)#
int NM_to_dense(NumericsMatrix *A, NumericsMatrix *B)#

Copy a NumericsMatrix into another with dense storage.

Parameters:
  • A – source matrix (any kind of storage)

  • B – targeted matrix, must be dense with the same dimension as A

void NM_dense_display_matlab(double *m, int nRow, int nCol, int lDim)#

Screen display of the matrix content stored as a double * array in Fortran style.

Parameters:
  • m – the matrix to be displayed

  • nRow – the number of rows

  • nCol – the number of columns

  • lDim – the leading dimension of M

void NM_dense_display(double *m, int nRow, int nCol, int lDim)#

Screen display of the matrix content stored as a double * array in Fortran style.

Parameters:
  • m – the matrix to be displayed

  • nRow – the number of rows

  • nCol – the number of columns

  • lDim – the leading dimension of M

void NM_vector_display(double *m, int nRow)#

Screen display of the vector content stored as a double * array.

Parameters:
  • m – the vector to be displayed

  • nRow – the number of rows

void NM_display(const NumericsMatrix *const M)#

Screen display of the matrix content.

Parameters:

M – the matrix to be displayed

void NM_display_storageType(const NumericsMatrix *const M)#

Screen display of the matrix storage.

Parameters:

M – the matrix to be displayed

void NM_display_row_by_row(const NumericsMatrix *const m)#

Screen display raw by raw of the matrix content.

Parameters:

m – the matrix to be displayed

void NM_write_in_filename(const NumericsMatrix *const M, const char *filename)#

matrix I/O

PrintInFile of the matrix content

Parameters:
  • M – the matrix to be printed

  • filename – the corresponding name of the file

void NM_read_in_filename(NumericsMatrix *const M, const char *filename)#

Read in file of the matrix content.

Parameters:
  • M – the matrix to be read

  • filename – the corresponding name of the file

void NM_write_in_file(const NumericsMatrix *const M, FILE *file)#

PrintInFile of the matrix content.

Parameters:
  • M – the matrix to be printed

  • file – filename the corresponding file

void NM_read_in_file(NumericsMatrix *const M, FILE *file)#

Read in file of the matrix content without performing memory allocation.

Parameters:
  • M – the matrix to be read

  • file – the corresponding file

RawNumericsMatrix *NM_new_from_file(FILE *file)#

Create from file a NumericsMatrix with memory allocation.

Parameters:

file – the corresponding file

Returns:

0 if the matrix

RawNumericsMatrix *NM_new_from_filename(const char *filename)#
void NM_write_in_file_scilab(const NumericsMatrix *const M, FILE *file)#

NM_write_in_file_scilab of the matrix content.

Parameters:
  • M – the matrix to be printed

  • file – the corresponding file

void NM_write_in_file_python(const NumericsMatrix *const M, FILE *file)#

NM_write_in_file_python of the matrix content.

Parameters:
  • M – the matrix to be printed

  • file – the corresponding file

void NM_read_in_file_scilab(NumericsMatrix *const M, FILE *file)#

Read in file for scilab of the matrix content.

Parameters:
  • M – the matrix to be read

  • file – the corresponding file

void NM_clearDense(NumericsMatrix *A)#

Clear dense storage, if it is existent.

Parameters:

A[inout] a Numericsmatrix

void NM_clearSparseBlock(NumericsMatrix *A)#

Clear sparse block storage, if it is existent.

Parameters:

A[inout] a Numericsmatrix

void NM_clearSparse(NumericsMatrix *A)#

Clear sparse data, if it is existent.

The linear solver parameters are also cleared.

Parameters:

A[inout] a Numericsmatrix

void NM_clearTriplet(NumericsMatrix *A)#

Clear triplet storage, if it is existent.

Parameters:

A[inout] a Numericsmatrix

void NM_clearHalfTriplet(NumericsMatrix *A)#

Clear half triplet storage, if it is existent.

Parameters:

A[inout] a Numericsmatrix

void NM_clearCSC(NumericsMatrix *A)#

Clear compressed column storage, if it is existent.

Parameters:

A[inout] a Numericsmatrix

void NM_clearCSCTranspose(NumericsMatrix *A)#

Clear transposed compressed column storage, if it is existent.

Parameters:

A[inout] a Numericsmatrix

void NM_clearCSR(NumericsMatrix *A)#

Clear compressed row storage, if it is existent.

Parameters:

A[inout] a Numericsmatrix

void NM_clearSparseStorage(NumericsMatrix *A)#

Clear triplet, csc, csc transposed storage, if they are existent.

Linear solver parameters are preserved.

Parameters:

A[inout] a Numericsmatrix

int NM_LU_factorize(NumericsMatrix *A)#

LU factorization of the matrix.

If the matrix has already been factorized (i.e if NM_LU_factorized(A) return true), nothing is done. To force a new factorization one has to set factorization flag to false : NM_set_LU_factorized(A, false) before the call to NM_LU_factorize. If the matrix is preserved, that means that a call to NM_preserve(A) has been done before the call to NM_LU_factorize, it is not destroyed, but the factorized part remains accessible for subsequent calls to NM_LU_solve. If the matrix is not preserved, then it is replaced by the factorized part.

Parameters:

A[in] the NumericsMatrix

Returns:

an int, 0 means the matrix has been factorized.

int NM_Cholesky_factorize(NumericsMatrix *A)#
int NM_LDLT_factorize(NumericsMatrix *A)#
int NM_LU_solve(NumericsMatrix *A, double *b, unsigned int nrhs)#

Solve linear system with multiple right hand size.

A call to NM_LU_factorize is done at the beginning.

Parameters:
  • A[in] the NumericsMatrix. A is not destroyed if it has been preserved by a call to NM_preserve(A).

  • b[inout] the right hand size which is a pointer on a matrix of double. It is replaced by the solutions

  • nrhs[in] the number of right hand side.

Returns:

0 if the solve succeeded.

int NM_LU_solve_matrix_rhs(NumericsMatrix *Ao, NumericsMatrix *B)#
int NM_LU_refine(NumericsMatrix *A, double *x, double tol, int max_iter, double *residu)#
int NM_Cholesky_solve(NumericsMatrix *A, double *b, unsigned int nrhs)#
int NM_Cholesky_solve_matrix_rhs(NumericsMatrix *Ao, NumericsMatrix *B)#
int NM_LDLT_solve(NumericsMatrix *A, double *b, unsigned int nrhs)#
int NM_LDLT_refine(NumericsMatrix *Ao, double *x, double *b, unsigned int nrhs, double tol, int maxitref, int job)#
int NM_gesv_expert(NumericsMatrix *A, double *b, unsigned keep)#
int NM_posv_expert(NumericsMatrix *A, double *b, unsigned keep)#
int NM_gesv_expert_multiple_rhs(NumericsMatrix *A, double *b, unsigned int n_rhs, unsigned keep)#
int NM_Linear_solver_finalize(NumericsMatrix *Ao)#
NumericsMatrix *NM_LU_inv(NumericsMatrix *A)#

Computation of the inverse of a NumericsMatrix A usinf NM_gesv_expert.

Parameters:

A[inout] a NumericsMatrix.

Returns:

the matrix inverse.

int NM_inverse_diagonal_block_matrix_in_place(NumericsMatrix *A)#
NumericsMatrix *NM_inverse_diagonal_block_matrix(NumericsMatrix *A, unsigned int block_number, unsigned int *blocksizes)#

Computation of the inverse of a NumericsMatrix A composed of diagonal blocks for each block a dense inverse is performed and then inserted into the global inverse.

Parameters:
  • A[in] a NumericsMatrix.

  • block_number[in] the number of blocks

  • blocksize[in] the sizes of diagonal blocks

Returns:

the matrix inverse.

static inline int NM_gesv(NumericsMatrix *A, double *b, bool preserve)#

Direct computation of the solution of a real system of linear equations: A x = b.

Parameters:
  • A[inout] a NumericsMatrix. On a dense factorisation A.iWork is initialized.

  • b[inout] pointer on a dense vector of size A->size1

  • preserve – preserve the original matrix data. Only useful in the dense case, where the LU factorization is done in-place.

Returns:

0 if successful, else the error is specific to the backend solver used

NumericsMatrix *NM_gesv_inv(NumericsMatrix *A)#

Computation of the inverse of a NumericsMatrix A usinf NM_gesv_expert.

Parameters:

A[inout] a NumericsMatrix.

Returns:

the matrix inverse.

void NM_setSparseSolver(NumericsMatrix *A, NSM_linear_solver solver_id)#

Set the linear solver.

Parameters:
  • A – the matrix

  • solver_id – id of the solver

NumericsMatrixInternalData *NM_internalData(NumericsMatrix *A)#

Get Matrix internal data with initialization if needed.

Parameters:

A[inout] a NumericsMatrix.

Returns:

a pointer on internal data.

void NM_internalData_new(NumericsMatrix *M)#

Allocate the internalData structure (but not its content!)

Parameters:

M – the matrix to modify

void NM_internalData_copy(const NumericsMatrix *const A, NumericsMatrix *B)#

Copy the internalData structure.

Parameters:

M – the matrix to modify

void *NM_iWork(NumericsMatrix *A, size_t size, size_t sizeof_elt)#

Integer work vector initialization, if needed.

Parameters:
  • A[inout] pointer on a NumericsMatrix.

  • size[in] number of element to allocate

  • sizeof_elt[in] of an element in bytes (result of sizeof for instance)

Returns:

pointer on A->iWork allocated space of with the right size

double *NM_dWork(NumericsMatrix *A, int size)#

Double workspace initialization, if needed.

Parameters:
  • A[inout] pointer on a NumericsMatrix.

  • size[in] the size of needed space.

Returns:

pointer on A->dWork allocated space of with the right size

void NM_add_to_diag3(NumericsMatrix *M, double alpha)#

Add a constant term to the diagonal elements, when the block of the SBM are 3x3.

Parameters:
  • M – the matrix

  • alpha – the term to add

void NM_add_to_diag5(NumericsMatrix *M, double alpha)#

Add a constant term to the diagonal elements, when the block of the SBM are 5x5.

Parameters:
  • M – the matrix

  • alpha – the term to add

RawNumericsMatrix *NM_add(double alpha, NumericsMatrix *A, double beta, NumericsMatrix *B)#

Add two matrices with coefficients C = alpha*A + beta*B.

Parameters:
  • alpha – the first coefficient

  • A – the first matrix

  • beta – the second coefficient

  • B – the second matrix

Returns:

C a new NumericsMatrix

void NM_scal(double alpha, NumericsMatrix *A)#

Multiply a matrix with a double alpha*A –> A.

Parameters:
  • alpha – the coefficient

  • A – the matrix

static inline void NM_assert(NM_types type, NumericsMatrix *M)#

assert that a NumericsMatrix has the right structure given its type

Parameters:
  • type – expected type

  • M – the matrix to check

int NM_check(const NumericsMatrix *const A)#

Check the matrix (the sparse format for now)

Parameters:

A – the matrix to check

Returns:

0 if the matrix storage is fine, 1 if not

double NM_norm_1(NumericsMatrix *const A)#

Compute the 1-norm of a sparse matrix = max (sum (abs (A))), largest column sum of a matrix (the sparse format for now)

Parameters:

A – the matrix

Returns:

the norm

double NM_norm_inf(NumericsMatrix *const A)#

Compute the inf-norm of a sparse matrix = max (sum (abs (A^T))), largest row sum of a matrix (the sparse format for now)

Parameters:

A – the matrix

Returns:

the norm

int NM_is_symmetric(NumericsMatrix *A)#
double NM_symmetry_discrepancy(NumericsMatrix *A)#
static inline NumericsMatrix *NM_convert(NumericsMatrix *A)#

Pass a NumericsMatrix through swig typemaps.

This is only useful in python.

Parameters:

A – the matrix

Returns:

a NumericsMatrix

double NM_iterated_power_method(NumericsMatrix *A, double tol, int itermax)#

Compute the maximum eigenvalue with the iterated power method.

Parameters:

A – the matrix

Returns:

the maximum eigenvalue

int NM_max_by_columns(NumericsMatrix *A, double *max)#

Compute the maximum values by columns.

Parameters:
  • A – the matrix

  • max – the vector of max that must be preallocated

Returns:

info

int NM_max_by_rows(NumericsMatrix *A, double *max)#

Compute the maximum values by rows.

Parameters:
  • A – the matrix

  • max – the vector of max that must be preallocated

Returns:

info

int NM_max_abs_by_columns(NumericsMatrix *A, double *max)#

Compute the maximum absolute values by columns.

Parameters:
  • A – the matrix

  • max – the vector of max that must be preallocated

Returns:

info

int NM_max_abs_by_rows(NumericsMatrix *A, double *max)#

Compute the maximum absolute values by rows.

Parameters:
  • A – the matrix

  • max – the vector of max that must be preallocated

Returns:

info

int NM_compute_balancing_matrices(NumericsMatrix *A, double tol, int itermax, BalancingMatrices *B)#

Compute the balancing matrices for a given matrix by iteration.

Parameters:
  • A – the matrix

  • tol – tolerance on the balanced matrix

  • itermax – max number of iterations

  • alloated – structure for the balancing matrices and the balanced matrix

Returns:

0 if succeed.

BalancingMatrices *NM_BalancingMatrices_new(NumericsMatrix *A)#

Create a Balancing Matrices structure.

Parameters:

A – the matrix to be balanced

BalancingMatrices *NM_BalancingMatrices_free(BalancingMatrices *A)#

free a Balancing Matrices structure

void NM_reset_version(NumericsMatrix *M, NM_types id)#

Reset the version of a NM_types storage.

Parameters:
void NM_reset_versions(NumericsMatrix *M)#

Reset versions of all storages.

Parameters:

M – the NumericsMatrix

void NM_version_sync(NumericsMatrix *M)#
int NM_isnan(NumericsMatrix *M)#
struct NumericsMatrixInternalData#
#include <NumericsMatrix.h>

Structure for simple workspaces.

Public Members

size_t iWorkSize#

size of iWork

void *iWork#

integer workspace

size_t sizeof_elt#

sizeof_elt of an element in bytes (result of sizeof for instance)

size_t dWorkSize#

size of dWork

double *dWork#

double workspace

bool isLUfactorized#

true if the matrix has already been LU-factorized

bool isCholeskyfactorized#

true if the matrix has already been Cholesky factorized

bool isLDLTfactorized#

true if the matrix has already been LDLT factorized

bool isInversed#

true if the matrix contains its inverse (in place inversion)

struct NumericsMatrix#
#include <NumericsMatrix.h>

Interface to different type of matrices in numerics component.

See NM_* functions for linear algebra operations on dense, sparse block and sparse storage.

Public Members

NM_types storageType#

the type of storage: 0: dense (double*), 1: SparseBlockStructuredMatrix, 2: classical sparse (csc, csr or triplet) via CSparse (from T.

Davis)

int size0#

number of rows

int size1#

number of columns

double *matrix0#

dense storage

SparseBlockStructuredMatrix *matrix1#

sparse block storage

NumericsSparseMatrix *matrix2#

csc, csr or triplet storage

NumericsMatrixInternalData *internalData#

internal storage, used for workspace among other things

NumericsDataVersion version#
NumericsMatrix *destructible#

pointer on the destructible matrix, by default points toward the matrix itself

struct BalancingMatrices#

Public Members

int size0#
int size1#
NumericsMatrix *D1#
NumericsMatrix *D2#
NumericsMatrix *A#