module Sparse:sig..end
Sparse matrices
type csc
Compressed-sparse-column format.
type csr
Compressed-sparse-row format.
type '_ sformat =
| |
CSC : |
(* | Compressed-sparse-column format ( | *) |
| |
CSR : |
(* | Compressed-sparse-row format ( | *) |
Matrix storage formats.
type 's t
A sparse matrix. Values of this type are typically passed to linear
solver callback functions (like Cvode.Dls.jac_fn,
Ida.Dls.jac_fn, and Kinsol.Dls.jac_fn).
The type argument specifies the storage format, either compressed-sparse-column format or compressed-sparse-row format.
typeindex_array =(Sundials.Index.t, Sundials.Index.index_elt, Stdlib.Bigarray.c_layout)
Stdlib.Bigarray.Array1.t
Array of row or column indices
val make : 's sformat ->
int -> int -> int -> 's tmake fmt m n nnz returns an m by n sparse matrix in the
specified format with a potential for nnz non-zero elements.
All elements are initially zero.
The CSR format is only available from Sundials 2.7.0 onwards.
val from_dense : 's sformat ->
float -> Sundials_Matrix.Dense.t -> 's tCreates a sparse matrix in in the specified format from a dense matrix by copying all values of magnitude greater than the given tolerance.
The CSR format is only available from Sundials 2.7.0 onwards.
val from_band : 's sformat ->
float -> Sundials_Matrix.Band.t -> 's tCreates a sparse matrix in the specified format from a band matrix by copying all values of magnitude greater than the given tolerance.
The CSR format is only available from Sundials 2.7.0 onwards.
val sformat : 's t -> 's sformatReturn the matrix format.
val is_csc : 's t -> boolReturns true iff the matrix format is CSC.
It is essentially a version of Sundials_Matrix.Sparse.sformat with less typing
complications.
val size : 's t -> int * intm, n = size a returns the numbers of rows m and columns n
of a.
val dims : 's t -> int * intnnz, np = dims m returns the allocated number of nonzeros nnz and
of the number np of columns (for csc) or rows (for csr) in the
matrix m.
val pp : Stdlib.Format.formatter -> 's t -> unitPretty-print a sparse matrix using the Format module.
val ppi : ?start:string ->
?stop:string ->
?sep:string ->
?indent:int ->
?itemsep:string ->
?rowcol:(Stdlib.Format.formatter -> int -> unit) ->
?item:(Stdlib.Format.formatter -> int -> float -> unit) ->
unit -> Stdlib.Format.formatter -> 's t -> unitPretty-print a sparse matrix using the
Format module.
The defaults are: start="[", stop="]", sep=";",
indent=4, itemsep=" ",
rowcol=fun f i->Format.fprintf f "%2d: " i, and
item=fun f r c->Format.fprintf f "(%2d,%2d)=% -15e" r c (see
fprintf).
The indent argument specifies the indent for wrapped rows.
val set_col : csc t -> int -> int -> unitset_col a j idx sets the data index of column j to idx.
val get_col : csc t -> int -> intget_col a j returns the data index of column j.
val set_row : csr t -> int -> int -> unitset_row a j idx sets the data index of row j to idx.
val get_row : csr t -> int -> intget_row a j returns the data index of row j.
val set : 'f t -> int -> int -> float -> unitset a idx i v sets the idxth row/column to i and its value
to v.
val get : 'f t -> int -> int * floatr, v = get a idx returns the row/column r and value v at the
idxth position.
val unwrap : 's t ->
index_array * index_array *
Sundials.RealArray.tDirect access to the underlying sparse storage arrays.
In the call vals, ptrs, data = unwrap m ,
vals contains the row (if csc) or column (if csr) indices of
nonzero matrix entries in data,ptrs contains the indices of the column (if csc) or
row (if csr) entries in data and vals, anddata contains the values of the nonzero entries.NB: The Sundials_Matrix.Sparse.scale_add, Sundials_Matrix.Sparse.scale_addi, Sundials_Matrix.Sparse.blit, and Sundials_Matrix.Sparse.resize functions,
invoked either directly or from within a solver, may replace the
underlying storage. In these cases, any previously 'unwrapped' arrays
are no longer associated with the matrix storage.
NB: For Config.sundials_version < 3.0.0, this access is
potentially unsafe and must only be used when the underlying
storage is valid, which will be the case in callbacks unless the
Sundials_Matrix.Sparse.scale_add, Sundials_Matrix.Sparse.scale_addi, Sundials_Matrix.Sparse.blit, and Sundials_Matrix.Sparse.resize functions are
used.
val resize : ?nnz:int -> 's t -> unitReallocates the underlying arrays to the given number of non-zero elements, or otherwise to the current number of non-zero elements .
NB: The Sundials_Matrix.Sparse.resize operation may replace the underlying storage of the
matrix argument. In this case, any previously 'unwrapped' array is no
longer associated with the matrix storage.
val ops : ('s t, Nvector_serial.data) Sundials_Matrix.matrix_opsOperations on sparse matrices.
val scale_add : float -> 's t -> 's t -> unitscale_add c A B calculates $A = cA + B$.
NB: The Sundials_Matrix.Sparse.scale_add operation, invoked either directly or from within
a solver, may replace the underlying storage of its first matrix
argument does not contain the sparsity of the second matrix argument.
In this case, any previously 'unwrapped' array is no longer associated
with the matrix storage.
val scale_addi : float -> 's t -> unitscale_addi c A calculates $A = cA + I$.
NB: The Sundials_Matrix.Sparse.scale_add operation, invoked either directly or from within
a solver, may replace the underlying storage of its matrix argument
if it does not already contain a complete diagonal. In this
case, any previously 'unwrapped' array is no longer associated with
the matrix storage.
val matvec : 's t ->
Sundials.RealArray.t -> Sundials.RealArray.t -> unitThe call matvec a x y computes the matrix-vector product $y = Ax$.
val set_to_zero : 's t -> unitFills a matrix with zeros.
val blit : src:'s t -> dst:'s t -> unitblit ~src ~dst copies the contents of src into dst. Both
must have the same size.
NB: This operation, invoked either directly or from within a solver, may replace the underlying storage of its second matrix argument if it does not contain the sparsity of the first matrix argument. In this case, any previously 'unwrapped' array is no longer associated with the matrix storage.
val copy_to_csr : csc t ->
csr tval copy_to_csc : csr t ->
csc tval space : 's t -> int * intlrw, liw = space a returns the storage requirements of a as
lrw realtype words and liw integer words.
val set_rowval : csc t -> int -> int -> unitset_rowval a idx i sets the idxth row to i.
val get_rowval : csc t -> int -> intr = get_rowval a idx returns the row r at the idxth position.
val set_colval : csr t -> int -> int -> unitset_colval a idx i sets the idxth column to i.
val get_colval : csr t -> int -> intc = get_colval a idx returns the column c at the idxth
position.
val set_data : 'f t -> int -> float -> unitset_data a idx v sets the value of the idxth row v.
val get_data : 'f t -> int -> floatv = get_data a idx returns the value v at the idxth position.
val invalidate : 's t -> unitCalled internally when the corresponding value in the underlying library ceases to exist. Has no effect when Config.sundials_version >= 3.0.0.