42 #ifndef OPENNL_MATRIX_H
43 #define OPENNL_MATRIX_H
70 #define NL_MATRIX_SPARSE_DYNAMIC 0x1001
71 #define NL_MATRIX_CRS 0x1002
72 #define NL_MATRIX_SUPERLU_EXT 0x1003
73 #define NL_MATRIX_CHOLMOD_EXT 0x1004
74 #define NL_MATRIX_FUNCTION 0x1005
75 #define NL_MATRIX_OTHER 0x1006
125 NLMatrix M,
const double* x,
double* y
497 #define NL_MATRIX_STORE_ROWS 1
503 #define NL_MATRIX_STORE_COLUMNS 2
510 #define NL_MATRIX_STORE_SYMMETRIC 4
776 NLAPI
void NLAPIENTRY nlMatrixCompress(
NLMatrix* M);
uint32_t NLuint
A 4-bytes unsigned integer.
uint64_t NLulong
A 8-bytes unsigned integer.
double NLdouble
A double-precision floating-point number.
struct NLMatrixStruct * NLMatrix
Opaque handle to a matrix.
unsigned int NLenum
A symbolic constant.
unsigned char NLboolean
A truth value (NL_TRUE or NL_FALSE).
NLAPI void NLAPIENTRY nlCRSMatrixPatternCompile(NLCRSMatrix *M)
Intializes a NLCRSMatrix from the pattern (row lengths).
NLAPI NLMatrix NLAPIENTRY nlMatrixNewFromFunction(NLuint m, NLuint n, NLMatrixFunc func)
Creates a matrix implemented by a matrix-vector function.
NLAPI void NLAPIENTRY nlSparseMatrixAddMatrix(NLSparseMatrix *M, double mul, const NLMatrix N)
Adds a matrix to another sparse matrix.
NLAPI NLMatrix NLAPIENTRY nlMatrixNewFromProduct(NLMatrix M, NLboolean product_owns_M, NLMatrix N, NLboolean product_owns_N)
Creates a matrix that represents the product of two matrices.
NLAPI NLMatrix NLAPIENTRY nlMatrixFactorize(NLMatrix M, NLenum solver)
Factorizes a matrix.
NLAPI void NLAPIENTRY nlCRSMatrixPatternSetRowLength(NLCRSMatrix *M, NLuint i, NLuint n)
Specifies the number of non-zero entries in the row of a matrix that was constructed by nlCRSMatrixCo...
NLAPI void NLAPIENTRY nlDeleteMatrix(NLMatrix M)
Deletes a matrix.
NLAPI NLuint_big NLAPIENTRY nlMatrixNNZ(NLMatrix M)
Gets the number of non-zero entries in a matrix.
NLAPI void NLAPIENTRY nlSparseMatrixAddColumn(NLSparseMatrix *M)
Adds a new empty column to a sparse matrix.
NLAPI void NLAPIENTRY nlSparseMatrixMAddRow(NLSparseMatrix *M, NLuint i1, double s, NLuint i2)
Adds a row of a sparse matrix to another row. (row[i1] += s * row[i2]).
NLAPI void NLAPIENTRY nlSparseMatrixAddRow(NLSparseMatrix *M)
Adds a new empty row to a sparse matrix.
NLAPI void NLAPIENTRY nlSparseMatrixScaleRow(NLSparseMatrix *M, NLuint i, double s)
Scales a row of a sparse matrix. (row[i] *= s).
void(* NLMatrixFunc)(const double *x, double *y)
Function pointer type for matrix-vector products.
NLAPI NLMatrixFunc NLAPIENTRY nlMatrixGetFunction(NLMatrix M)
Gets the function pointer that implements matrix x vector product.
NLAPI void NLAPIENTRY nlMultMatrixVector(NLMatrix M, const double *x, double *y)
Computes a matrix x vector product.
void(* NLMultMatrixVectorFunc)(NLMatrix M, const double *x, double *y)
Function pointer type for matrix x vector product.
void(* NLDestroyMatrixFunc)(NLMatrix M)
Function pointer type for matrix destructors.
NLuint NLuint_big
Type for internal indices.
NLAPI void NLAPIENTRY nlSparseMatrixZeroRow(NLSparseMatrix *M, NLuint i)
Zeroes a row of a sparse matrix. (row[i] = 0).
Some macros and functions used internally by OpenNL.
A compact self-contained storage for sparse matrices.
NLAPI void NLAPIENTRY nlCRSMatrixConstructSymmetric(NLCRSMatrix *M, NLuint n, NLuint_big nnz)
Constructs a new NLCRSMatrix with symmetric storage.
NLMultMatrixVectorFunc mult_func
Matrix x vector product.
NLAPI NLMatrix NLAPIENTRY nlCRSMatrixNewFromSparseMatrix(NLSparseMatrix *M)
Creates a compressed row storage matrix from a dynamic sparse matrix.
NLuint_big * rowptr
row pointers, size = m+1
NLAPI NLuint_big NLAPIENTRY nlCRSMatrixNNZ(NLCRSMatrix *M)
Gets the number of non-zero coefficient in an NLCRSMatrix.
NLAPI void NLAPIENTRY nlCRSMatrixConstructPatternSymmetric(NLCRSMatrix *M, NLuint n)
Constructs a new NLCRSMatrix with symmetric storage.
NLAPI void NLAPIENTRY nlCRSMatrixConstruct(NLCRSMatrix *M, NLuint m, NLuint n, NLuint_big nnz, NLuint nslices)
Constructs a new NLCRSMatrix.
NLuint nslices
number of slices, used by parallel spMv
NLAPI NLboolean NLAPIENTRY nlCRSMatrixSave(NLCRSMatrix *M, const char *filename)
Saves a NLCRSMatrix into a file.
NLuint n
number of columns
NLAPI NLMatrix NLAPIENTRY nlCRSMatrixNewFromSparseMatrixSymmetric(NLSparseMatrix *M)
Creates a compressed row storage matrix from a dynamic sparse matrix.
NLdouble * val
array of coefficient values, size = NNZ (number of non-zero coefficients)
NLuint * sliceptr
slice pointers, size = nslices + 1, used by parallel spMv
NLAPI void NLAPIENTRY nlCRSMatrixConstructPattern(NLCRSMatrix *M, NLuint m, NLuint n)
Constructs a new NLCRSMatrix with only the pattern.
NLAPI NLboolean NLAPIENTRY nlCRSMatrixLoad(NLCRSMatrix *M, const char *filename)
Loads a NLCRSMatrix from a file.
NLuint * colind
column indices, size = NNZ
NLDestroyMatrixFunc destroy_func
destructor
NLboolean symmetric_storage
NL_TRUE if symmetric storage is used, NL_FALSE otherwise.
Represents a coefficient in a sparse matrix.
NLuint index
index of the coefficient.
NLdouble value
value of the coefficient.
The base class for abstract matrices.
NLMultMatrixVectorFunc mult_func
Matrix x vector product.
NLuint n
number of columns
NLDestroyMatrixFunc destroy_func
Destructor.
Represents a row or a column of a sparse matrix.
NLAPI void NLAPIENTRY nlRowColumnAdd(NLRowColumn *c, NLuint index, NLdouble value)
Adds a coefficient to an NLRowColumn.
NLAPI void NLAPIENTRY nlRowColumnDestroy(NLRowColumn *c)
Destroys a NLRowColumn.
NLAPI void NLAPIENTRY nlRowColumnSort(NLRowColumn *c)
Sorts the coefficients of an NLRowColumn by increasing index.
NLAPI void NLAPIENTRY nlRowColumnGrow(NLRowColumn *c)
Allocates additional storage for the coefficients of an NLRowColumn.
NLAPI void NLAPIENTRY nlRowColumnZero(NLRowColumn *c)
Zeroes an NLRowColumn.
NLAPI void NLAPIENTRY nlRowColumnConstruct(NLRowColumn *c)
Constructs a new NLRowColumn.
NLAPI void NLAPIENTRY nlRowColumnClear(NLRowColumn *c)
Zeroes an NLRowColumn and deallocates the memory used by the NLRowColumn.
NLCoeff * coeff
the array of coefficients, with enough space to store capacity coefficients.
NLuint size
number of coefficients.
NLAPI void NLAPIENTRY nlRowColumnAppend(NLRowColumn *c, NLuint index, NLdouble value)
Appends a coefficient to an NLRowColumn .
NLuint capacity
number of coefficients that can be stored without reallocating memory.
NLuint diag_size
number of elements in the diagonal
NLuint row_capacity
Number of row descriptors allocated in the row array.
NLRowColumn * row
the rows if (storage & NL_MATRIX_STORE_ROWS), size = m, NULL otherwise
NLAPI void NLAPIENTRY nlSparseMatrixDestroy(NLSparseMatrix *M)
Destroys an NLSparseMatrix.
NLuint column_capacity
Number of column descriptors allocated in the column array.
NLAPI void NLAPIENTRY nlSparseMatrixConstruct(NLSparseMatrix *M, NLuint m, NLuint n, NLenum storage)
Constructs a new NLSparseMatrix.
NLAPI void NLAPIENTRY nlCRSMatrixAddAt(NLCRSMatrix *M, NLuint i, NLuint j, NLdouble value, NLulong index)
Adds a coefficient to an NLSparseMatrix at a known location.
NLAPI NLulong NLAPIENTRY nlCRSMatrixAdd(NLCRSMatrix *M, NLuint i, NLuint j, NLdouble value)
Adds a coefficient to an NLSparseMatrix.
NLRowColumn * column
the columns if (storage & NL_MATRIX_STORE_COLUMNS), size = n, NULL otherwise
NLAPI void NLAPIENTRY nlSparseMatrixMult(NLSparseMatrix *A, const NLdouble *x, NLdouble *y)
Computes a matrix-vector product.
NLDestroyMatrixFunc destroy_func
destructor
NLenum storage
indicates what is stored in this matrix
NLMultMatrixVectorFunc mult_func
Matrix x vector product.
NLAPI void NLAPIENTRY nlSparseMatrixSort(NLSparseMatrix *M)
Sorts the coefficients in an NLSParseMatrix.
NLuint diag_capacity
Number of elements allocated to store the diagonal.
NLAPI void NLAPIENTRY nlCRSMatrixSetCoefficientAtRowOffset(NLCRSMatrix *M, NLuint i, NLuint j, NLdouble value, NLuint row_offset)
Sets a coefficient to an NLSparseMatrix at a known row offset.
NLAPI NLuint_big NLAPIENTRY nlSparseMatrixNNZ(NLSparseMatrix *M)
Gets the number of non-zero coefficient in an NLSparseMatrix.
NLAPI void NLAPIENTRY nlSparseMatrixClear(NLSparseMatrix *M)
Clears an NLSparseMatrix.
NLuint n
number of columns
NLAPI void NLAPIENTRY nlSparseMatrixZero(NLSparseMatrix *M)
Zeroes an NLSparseMatrix.
NLAPI void NLAPIENTRY nlSparseMatrixAdd(NLSparseMatrix *M, NLuint i, NLuint j, NLdouble value)
Adds a coefficient to an NLSparseMatrix.
NLAPI NLMatrix NLAPIENTRY nlSparseMatrixNew(NLuint m, NLuint n, NLenum storage)
Constructs a new NLSparseMatrix.
NLdouble * diag
the diagonal elements, size = diag_size