package osdp

  1. Overview
  2. Docs

Module Matrix.QSource

Matrix with Q.t coefficients from the library Zarith.

Sourcemodule Coeff = Scalar.Q

Type of coefficients.

Sourcetype t

Type of matrices.

Sourceexception Dimension_error of string

Most of the functions in this module can raise this exception.

Conversion functions.

Sourceval of_list_list : Coeff.t list list -> t

of_list_list l returns the matrix with lines corresponding to the elements of the list l. All lists in l must have the same length.

Sourceval to_list_list : t -> Coeff.t list list
Sourceval of_array_array : Coeff.t array array -> t

of_array_array a returns the matrix with lines corresponding to the elements of a. All arrays in a must have the same size. A copy of the array is made internally.

Sourceval to_array_array : t -> Coeff.t array array

The returned array is a copy that can be freely modified by the user.

Construction functions.

Sourceval zeros : int -> int -> t

zeros n m builds a matrix of size n x m with all coefficients equal to Coeff.of_int O. n and m must be non negative.

Sourceval eye : int -> t

eye n builds the identity matrix of size n (i.e., a square matrix of size n with coefficients (i, j) equal to Coeff.of_int O when i != j and Coeff.of_int 1 when i = j). n must be non negative.

Sourceval kron : int -> int -> int -> t

kron n i j builds the square matrix of size n with all coefficients equal to zero (i.e., Coeff.of_int 0 except coefficients (i, j) which is one (i.e., Coeff.of_int 1). n, i and j must satisfy 0 <= i < n and 0 <= j < n.

Sourceval kron_sym : int -> int -> int -> t

kron_sym n i j builds the square matrix of size n with all coefficients equal to zero (i.e., Coeff.of_int 0 except coefficients (i, j) and (j, i) which are one (i.e., Coeff.of_int 1). n, i and j must satisfy 0 <= i < n and 0 <= j < n.

Sourceval block : t array array -> t

block a returns the block matrix corresponding to the array a. For instance block [|[|a; b|]; [|c; d|]|] builds the block matrix [a, b; c, d]. The array a must have a positive size. All arrays in array a must have the same positive size. Matrices dimensions must be consistent (for instance, in the previous example, a and b must have the same number of rows and a and c the same number of columns).

Sourceval lift_block : t -> int -> int -> int -> int -> t

lift_block m i j k l returns a matrix of size i x j with zeros everywhere except starting from indices k x l where matrix m is copied. The parameters must satisfy 0 <= k, 0 <= l, k + nb_lines m <= i and l + nb_cols m <= j.

Matrix operations.

Sourceval transpose : t -> t

Matrix transposition.

Sourceval minus : t -> t

Unary minus.

Sourceval mult_scalar : Coeff.t -> t -> t

mult_scalar s m multiplies matrix m by scalar s.

Sourceval add : t -> t -> t

Matrix addition. Both matrices must have the same size.

Sourceval sub : t -> t -> t

Matrix subtraction. Both matrices must have the same size.

Sourceval mult : t -> t -> t

Matrix multiplication. First matrix must have as many columns as the second as rows.

Sourceval power : t -> int -> t

power m n computes m^n, n must be non negative.

Various operations.

Sourceval nb_lines : t -> int
Sourceval nb_cols : t -> int
Sourceval is_symmetric : t -> bool
Sourceval remove_0_row_cols : t -> t

Returns the same matrix, without its rows and columns containing only 0.

Sourceval gauss_split : t -> int * t * t

gauss_split m for a matrix m of size l x c returns (n, m1, m2) where n is the rank of the input matrix (n <= l), m1 its row space, i.e., a matrix of size l' x c where l' <= l characterizing the same space as m but with no linear dependencies, and m2 a matrix of size l' x l mapping original dimensions in m to the ones of m1 (m1 = m2 x m).

Prefix and infix operators.

To use this operators, it's convenient to use local opens. For instance to write the matrix operations m1 * m2 + I_3x3:

let module M = Osdp.Matrix.Float in M.(m1 * m2 + eye 3)
Sourceval (~:) : t -> t

Same as transpose.

Sourceval (~-) : t -> t

Same as minus.

Sourceval (*.) : Coeff.t -> t -> t

Same as mult_scalar.

Sourceval (+) : t -> t -> t

Same as add.

Sourceval (-) : t -> t -> t

Same as sub.

Sourceval (*) : t -> t -> t

Same as mult.

Sourceval (**) : t -> int -> t

Same as power.

Printing.

Sourceval pp : Format.formatter -> t -> unit
OCaml

Innovation. Community. Security.