package lacaml

  1. Overview
  2. Docs
Matrix operations
Creation of matrices
val random : ?rnd_state:Random.State.t -> ?re_from:float -> ?re_range:float -> ?im_from:float -> ?im_range:float -> int -> int -> Lacaml_complex64.mat

random ?rnd_state ?re_from ?re_range ?im_from ?im_range m n

  • returns

    an mxn matrix initialized with random elements sampled uniformly from re_range and im_range starting at re_from and im_from for real and imaginary numbers respectively. A random state rnd_state can be passed.

  • parameter rnd_state

    default = Random.get_state ()

  • parameter re_from

    default = -1.0

  • parameter re_range

    default = 2.0

  • parameter im_from

    default = -1.0

  • parameter im_range

    default = 2.0

Creation of matrices and accessors
val create : int -> int -> Lacaml_complex64.mat

create m n

  • returns

    a matrix containing m rows and n columns.

make m n x

  • returns

    a matrix containing m rows and n columns initialized with value x.

val make0 : int -> int -> Lacaml_complex64.mat

make0 m n x

  • returns

    a matrix containing m rows and n columns initialized with the zero element.

val of_array : Lacaml_complex64.num_type array array -> Lacaml_complex64.mat

of_array ar

  • returns

    a matrix initialized from the array of arrays ar. It is assumed that the OCaml matrix is in row major order (standard).

val to_array : Lacaml_complex64.mat -> Lacaml_complex64.num_type array array

to_array mat

  • returns

    an array of arrays initialized from matrix mat.

val of_col_vecs : Lacaml_complex64.vec array -> Lacaml_complex64.mat

of_col_vecs ar

  • returns

    a matrix whose columns are initialized from the array of vectors ar. The vectors must be of same length.

val to_col_vecs : Lacaml_complex64.mat -> Lacaml_complex64.vec array

to_col_vecs mat

  • returns

    an array of column vectors initialized from matrix mat.

as_vec mat

  • returns

    a vector containing all elements of the matrix in column-major order. The data is shared.

val init_rows : int -> int -> (int -> int -> Lacaml_complex64.num_type) -> Lacaml_complex64.mat

init_cols m n f

  • returns

    a matrix containing m rows and n columns, where each element at row and col is initialized by the result of calling f row col. The elements are passed row-wise.

val init_cols : int -> int -> (int -> int -> Lacaml_complex64.num_type) -> Lacaml_complex64.mat

init_cols m n f

  • returns

    a matrix containing m rows and n columns, where each element at row and col is initialized by the result of calling f row col. The elements are passed column-wise.

val create_mvec : int -> Lacaml_complex64.mat

create_mvec m

  • returns

    a matrix with one column containing m rows.

make_mvec m x

  • returns

    a matrix with one column containing m rows initialized with value x.

val mvec_of_array : Lacaml_complex64.num_type array -> Lacaml_complex64.mat

mvec_of_array ar

  • returns

    a matrix with one column initialized with values from array ar.

val mvec_to_array : Lacaml_complex64.mat -> Lacaml_complex64.num_type array

mvec_to_array mat

  • returns

    an array initialized with values from the first (not necessarily only) column vector of matrix mat.

from_col_vec v

  • returns

    a matrix with one column representing vector v. The data is shared.

from_row_vec v

  • returns

    a matrix with one row representing vector v. The data is shared.

empty, the empty matrix.

val identity : int -> Lacaml_complex64.mat

identity n

  • returns

    the nxn identity matrix.

of_diag v

  • returns

    the diagonal matrix with diagonals elements from v.

val dim1 : Lacaml_complex64.mat -> int

dim1 m

  • returns

    the first dimension of matrix m (number of rows).

val dim2 : Lacaml_complex64.mat -> int

dim2 m

  • returns

    the second dimension of matrix m (number of columns).

col m n

  • returns

    the nth column of matrix m as a vector. The data is shared.

copy_row ?vec mat int

  • returns

    a copy of the nth row of matrix m in vector vec.

  • parameter vec

    default = fresh vector of length dim2 mat

Matrix transformations
val transpose_copy : ?m:int -> ?n:int -> ?ar:int -> ?ac:int -> Lacaml_complex64.mat -> ?br:int -> ?bc:int -> Lacaml_complex64.mat -> unit

transpose_copy ?m ?n ?ar ?ac a ?br ?bc b copy the transpose of (sub-)matrix a into (sub-)matrix b.

  • parameter m

    default = Mat.dim1 a

  • parameter n

    default = Mat.dim2 a

  • parameter ar

    default = 1

  • parameter ac

    default = 1

  • parameter br

    default = 1

  • parameter bc

    default = 1

val transpose : ?m:int -> ?n:int -> ?ar:int -> ?ac:int -> Lacaml_complex64.mat -> Lacaml_complex64.mat

transpose ?m ?n ?ar ?ac aa

  • returns

    the transpose of (sub-)matrix a.

  • parameter m

    default = Mat.dim1 a

  • parameter n

    default = Mat.dim2 a

  • parameter ar

    default = 1

  • parameter ac

    default = 1

val detri : ?up:bool -> ?n:int -> ?ar:int -> ?ac:int -> Lacaml_complex64.mat -> unit

detri ?up ?n ?ar ?ac a takes a triangular (sub-)matrix a, i.e. one where only the upper (iff up is true) or lower triangle is defined, and makes it a symmetric matrix by mirroring the defined triangle along the diagonal.

  • parameter up

    default = true

  • parameter n

    default = Mat.dim1 a

  • parameter ar

    default = 1

  • parameter ac

    default = 1

val packed : ?up:bool -> ?n:int -> ?ar:int -> ?ac:int -> Lacaml_complex64.mat -> Lacaml_complex64.vec

packed ?up ?n ?ar ?ac a

  • returns

    (sub-)matrix a in packed storage format.

  • parameter up

    default = true

  • parameter n

    default = Mat.dim2 a

  • parameter ar

    default = 1

  • parameter ac

    default = 1

val unpacked : ?up:bool -> ?n:int -> Lacaml_complex64.vec -> Lacaml_complex64.mat

unpacked ?up x

  • returns

    an upper or lower (depending on up) triangular matrix from packed representation vec. The other triangle of the matrix will be filled with zeros.

  • parameter up

    default = true

  • parameter n

    default = Vec.dim x

Arithmetic and other matrix operations
val add_const : Lacaml_complex64.num_type -> ?m:int -> ?n:int -> ?br:int -> ?bc:int -> ?b:Lacaml_complex64.mat -> ?ar:int -> ?ac:int -> Lacaml_complex64.mat -> Lacaml_complex64.mat

add_const c ?m ?n ?br ?bc ?b ?ar ?ac a adds constant c to the designated m by n submatrix in a and stores the result in the designated submatrix in b.

  • parameter m

    default = Mat.dim1 a

  • parameter n

    default = Mat.dim2 a

  • parameter ar

    default = 1

  • parameter ac

    default = 1

  • parameter br

    default = 1

  • parameter bc

    default = 1

  • parameter b

    default = fresh matrix of size m by n

val sum : ?m:int -> ?n:int -> ?ar:int -> ?ac:int -> Lacaml_complex64.mat -> Lacaml_complex64.num_type

sum ?m ?n ?ar ?ac a computes the sum of all elements in the m-by-n submatrix starting at row ar and column ac.

val fill : ?m:int -> ?n:int -> ?ar:int -> ?ac:int -> Lacaml_complex64.mat -> Lacaml_complex64.num_type -> unit

fill ?m ?n ?ar ?ac a x fills the specified sub-matrix in a with value x.

copy_diag m

  • returns

    the diagonal of matrix m as a vector. If m is not a square matrix, the longest possible sequence of diagonal elements will be returned.

trace m

  • returns

    the trace of matrix m. If m is not a square matrix, the sum of the longest possible sequence of diagonal elements will be returned.

val scal : ?m:int -> ?n:int -> Lacaml_complex64.num_type -> ?ar:int -> ?ac:int -> Lacaml_complex64.mat -> unit

scal ?m ?n alpha ?ar ?ac a BLAS scal function for (sub-)matrices.

val scal_cols : ?m:int -> ?n:int -> ?ar:int -> ?ac:int -> Lacaml_complex64.mat -> ?ofs:int -> Lacaml_complex64.vec -> unit

scal_cols ?m ?n ?ar ?ac a ?ofs alphas column-wise scal function for matrices.

val scal_rows : ?m:int -> ?n:int -> ?ofs:int -> Lacaml_complex64.vec -> ?ar:int -> ?ac:int -> Lacaml_complex64.mat -> unit

scal_rows ?m ?n ?ofs alphas ?ar ?ac a row-wise scal function for matrices.

val axpy : ?alpha:Lacaml_complex64.num_type -> ?m:int -> ?n:int -> ?xr:int -> ?xc:int -> Lacaml_complex64.mat -> ?yr:int -> ?yc:int -> Lacaml_complex64.mat -> unit

axpy ?alpha ?m ?n ?xr ?xc x ?yr ?yc y BLAS axpy function for matrices.

val gemm_diag : ?n:int -> ?k:int -> ?beta:Lacaml_complex64.num_type -> ?ofsy:int -> ?y:Lacaml_complex64.vec -> ?transa:Lacaml_complex64.trans3 -> ?alpha:Lacaml_complex64.num_type -> ?ar:int -> ?ac:int -> Lacaml_complex64.mat -> ?transb:Lacaml_complex64.trans3 -> ?br:int -> ?bc:int -> Lacaml_complex64.mat -> Lacaml_complex64.vec

gemm_diag ?n ?k ?beta ?ofsy ?y ?transa ?transb ?alpha ?ar ?ac a ?br ?bc b computes the diagonal of the product of the (sub-)matrices a and b (taking into account potential transposing), multiplying it with alpha and adding beta times y, storing the result in y starting at the specified offset. n elements of the diagonal will be computed, and k elements of the matrices will be part of the dot product associated with each diagonal element.

  • parameter n

    default = number of rows of a (or tr a) and number of columns of b (or tr b)

  • parameter k

    default = number of columns of a (or tr a) and number of rows of b (or tr b)

  • parameter beta

    default = 0

  • parameter ofsy

    default = 1

  • parameter y

    default = fresh vector of size n + ofsy - 1

  • parameter transa

    default = `N

  • parameter alpha

    default = 1

  • parameter ar

    default = 1

  • parameter ac

    default = 1

  • parameter transb

    default = `N

  • parameter br

    default = 1

  • parameter bc

    default = 1

val syrk_diag : ?n:int -> ?k:int -> ?beta:Lacaml_complex64.num_type -> ?ofsy:int -> ?y:Lacaml_complex64.vec -> ?trans:Lacaml_common.trans2 -> ?alpha:Lacaml_complex64.num_type -> ?ar:int -> ?ac:int -> Lacaml_complex64.mat -> Lacaml_complex64.vec

syrk_diag ?n ?k ?beta ?ofsy ?y ?trans ?alpha ?ar ?ac a computes the diagonal of the symmetric rank-k product of the (sub-)matrix a, multiplying it with alpha and adding beta times y, storing the result in y starting at the specified offset. n elements of the diagonal will be computed, and k elements of the matrix will be part of the dot product associated with each diagonal element.

  • parameter n

    default = number of rows of a (or tra)

  • parameter k

    default = number of columns of a (or tra)

  • parameter beta

    default = 0

  • parameter ofsy

    default = 1

  • parameter y

    default = fresh vector of size n + ofsy - 1

  • parameter trans

    default = `N

  • parameter alpha

    default = 1

  • parameter ar

    default = 1

  • parameter ac

    default = 1

val gemm_trace : ?n:int -> ?k:int -> ?transa:Lacaml_complex64.trans3 -> ?ar:int -> ?ac:int -> Lacaml_complex64.mat -> ?transb:Lacaml_complex64.trans3 -> ?br:int -> ?bc:int -> Lacaml_complex64.mat -> Lacaml_complex64.num_type

gemm_trace ?n ?k ?transa ?ar ?ac a ?transb ?br ?bc b computes the trace of the product of the (sub-)matrices a and b (taking into account potential transposing). This is also sometimes referred to as the Frobenius product. n is the number of rows (columns) to consider in a, and k the number of columns (rows) in b.

  • parameter n

    default = number of rows of a (or tr a) and number of columns of b (or tr b)

  • parameter k

    default = number of columns of a (or tr a) and number of rows of b (or tr b)

  • parameter transa

    default = `N

  • parameter ar

    default = 1

  • parameter ac

    default = 1

  • parameter transb

    default = `N

  • parameter br

    default = 1

  • parameter bc

    default = 1

val syrk_trace : ?n:int -> ?k:int -> ?ar:int -> ?ac:int -> Lacaml_complex64.mat -> Lacaml_complex64.num_type

syrk_trace ?n ?k ?ar ?ac a computes the trace of either a' * a or a * a', whichever is more efficient (results are identical), of the (sub-)matrix a multiplied by its own transpose. This is the same as the square of the Frobenius norm of a matrix. n is the number of rows to consider in a, and k the number of columns to consider.

  • parameter n

    default = number of rows of a

  • parameter k

    default = number of columns of a

  • parameter ar

    default = 1

  • parameter ac

    default = 1

val symm2_trace : ?n:int -> ?upa:bool -> ?ar:int -> ?ac:int -> Lacaml_complex64.mat -> ?upb:bool -> ?br:int -> ?bc:int -> Lacaml_complex64.mat -> Lacaml_complex64.num_type

symm2_trace ?n ?upa ?ar ?ac a ?upb ?br ?bc b computes the trace of the product of the symmetric (sub-)matrices a and b. n is the number of rows and columns to consider in a and b.

  • parameter n

    default = dimensions of a and b

  • parameter upa

    default = true (upper triangular portion of a is accessed)

  • parameter ar

    default = 1

  • parameter ac

    default = 1

  • parameter upb

    default = true (upper triangular portion of b is accessed)

  • parameter br

    default = 1

  • parameter bc

    default = 1

Iterators over matrices
val map : (Lacaml_complex64.num_type -> Lacaml_complex64.num_type) -> ?m:int -> ?n:int -> ?br:int -> ?bc:int -> ?b:Lacaml_complex64.mat -> ?ar:int -> ?ac:int -> Lacaml_complex64.mat -> Lacaml_complex64.mat

map f ?m ?n ?br ?bc ?b ?ar ?ac a

  • returns

    matrix with f applied to each element of a.

  • parameter m

    default = number of rows of a

  • parameter n

    default = number of columns of a

  • parameter b

    default = fresh matrix of size m by n

val fold_cols : ('a -> Lacaml_complex64.vec -> 'a) -> ?n:int -> ?ac:int -> 'a -> Lacaml_complex64.mat -> 'a

fold_cols f ?n ?ac acc a

  • returns

    accumulator resulting from folding over each column vector.

  • parameter ac

    default = 1

  • parameter n

    default = number of columns of a

OCaml

Innovation. Community. Security.