module Mat: sig
.. end
val random : ?rnd_state:Random.State.t ->
?re_from:float ->
?re_range:float ->
?im_from:float -> ?im_range:float -> int -> int -> Lacaml.Z.mat
random ?rnd_state ?re_from ?re_range ?im_from ?im_range m n
Returns an m
xn
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.
rnd_state
: default = Random.get_state ()
re_from
: default = -1.0
re_range
: default = 2.0
im_from
: default = -1.0
im_range
: default = 2.0
val create : int -> int -> Lacaml.Z.mat
create m n
Returns a matrix containing m
rows and n
columns.
val make : int -> int -> Lacaml.Z.num_type -> Lacaml.Z.mat
make m n x
Returns a matrix containing m
rows and n
columns
initialized with value x
.
val make0 : int -> int -> Lacaml.Z.mat
make0 m n x
Returns a matrix containing m
rows and n
columns
initialized with the zero element.
val of_array : Lacaml.Z.num_type array array -> Lacaml.Z.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.Z.mat -> Lacaml.Z.num_type array array
to_array mat
Returns an array of arrays initialized from matrix
mat
.
val of_col_vecs : Lacaml.Z.vec array -> Lacaml.Z.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.Z.mat -> Lacaml.Z.vec array
to_col_vecs mat
Returns an array of column vectors initialized
from matrix mat
.
val as_vec : Lacaml.Z.mat -> Lacaml.Z.vec
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.Z.num_type) -> Lacaml.Z.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.Z.num_type) -> Lacaml.Z.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.Z.mat
create_mvec m
Returns a matrix with one column containing m
rows.
val make_mvec : int -> Lacaml.Z.num_type -> Lacaml.Z.mat
make_mvec m x
Returns a matrix with one column containing m
rows
initialized with value x
.
val mvec_of_array : Lacaml.Z.num_type array -> Lacaml.Z.mat
mvec_of_array ar
Returns a matrix with one column
initialized with values from array ar
.
val mvec_to_array : Lacaml.Z.mat -> Lacaml.Z.num_type array
mvec_to_array mat
Returns an array initialized with values from
the first (not necessarily only) column vector of matrix mat
.
val from_col_vec : Lacaml.Z.vec -> Lacaml.Z.mat
from_col_vec v
Returns a matrix with one column representing vector v
.
The data is shared.
val from_row_vec : Lacaml.Z.vec -> Lacaml.Z.mat
from_row_vec v
Returns a matrix with one row representing vector v
.
The data is shared.
val empty : Lacaml.Z.mat
empty
, the empty matrix.
val identity : int -> Lacaml.Z.mat
identity n
Returns the n
xn
identity matrix.
val of_diag : Lacaml.Z.vec -> Lacaml.Z.mat
of_diag v
Returns the diagonal matrix with diagonals elements from v
.
val dim1 : Lacaml.Z.mat -> int
dim1 m
Returns the first dimension of matrix m
(number of rows).
val dim2 : Lacaml.Z.mat -> int
dim2 m
Returns the second dimension of matrix m
(number of columns).
val col : Lacaml.Z.mat -> int -> Lacaml.Z.vec
col m n
Returns the n
th column of matrix m
as a vector.
The data is shared.
val copy_row : ?vec:Lacaml.Z.vec -> Lacaml.Z.mat -> int -> Lacaml.Z.vec
copy_row ?vec mat int
Returns a copy of the n
th row of matrix m
in vector vec
.
vec
: default = fresh vector of length dim2 mat
val transpose_copy : ?m:int ->
?n:int ->
?ar:int ->
?ac:int -> Lacaml.Z.mat -> ?br:int -> ?bc:int -> Lacaml.Z.mat -> unit
transpose_copy ?m ?n ?ar ?ac a ?br ?bc b
copy the transpose
of (sub-)matrix a
into (sub-)matrix b
.
m
: default = Mat.dim1 a
n
: default = Mat.dim2 a
ar
: default = 1
ac
: default = 1
br
: default = 1
bc
: default = 1
val transpose : ?m:int -> ?n:int -> ?ar:int -> ?ac:int -> Lacaml.Z.mat -> Lacaml.Z.mat
transpose ?m ?n ?ar ?ac aa
Returns the transpose of (sub-)matrix a
.
m
: default = Mat.dim1 a
n
: default = Mat.dim2 a
ar
: default = 1
ac
: default = 1
val detri : ?up:bool -> ?n:int -> ?ar:int -> ?ac:int -> Lacaml.Z.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.
up
: default = true
n
: default = Mat.dim1 a
ar
: default = 1
ac
: default = 1
val packed : ?up:bool -> ?n:int -> ?ar:int -> ?ac:int -> Lacaml.Z.mat -> Lacaml.Z.vec
packed ?up ?n ?ar ?ac a
Returns (sub-)matrix a
in packed
storage format.
up
: default = true
n
: default = Mat.dim2 a
ar
: default = 1
ac
: default = 1
val unpacked : ?up:bool -> ?n:int -> Lacaml.Z.vec -> Lacaml.Z.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.
up
: default = true
n
: default = Vec.dim x
val add_const : Lacaml.Z.num_type ->
?m:int ->
?n:int ->
?br:int ->
?bc:int ->
?b:Lacaml.Z.mat -> ?ar:int -> ?ac:int -> Lacaml.Z.mat -> Lacaml.Z.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
.
m
: default = Mat.dim1 a
n
: default = Mat.dim2 a
br
: default = 1
bc
: default = 1
b
: default = fresh matrix of size m
by n
ar
: default = 1
ac
: default = 1
val sum : ?m:int -> ?n:int -> ?ar:int -> ?ac:int -> Lacaml.Z.mat -> Lacaml.Z.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.Z.mat -> Lacaml.Z.num_type -> unit
fill ?m ?n ?ar ?ac a x
fills the specified sub-matrix in a
with value
x
.
val copy_diag : Lacaml.Z.mat -> Lacaml.Z.vec
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.
val trace : Lacaml.Z.mat -> Lacaml.Z.num_type
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.Z.num_type -> ?ar:int -> ?ac:int -> Lacaml.Z.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.Z.mat -> ?ofs:int -> Lacaml.Z.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.Z.vec -> ?ar:int -> ?ac:int -> Lacaml.Z.mat -> unit
scal_rows ?m ?n ?ofs alphas ?ar ?ac a
row-wise scal
function for matrices.
val axpy : ?m:int ->
?n:int ->
?alpha:Lacaml.Z.num_type ->
?xr:int ->
?xc:int -> x:Lacaml.Z.mat -> ?yr:int -> ?yc:int -> Lacaml.Z.mat -> unit
axpy ?m ?n ?alpha ?xr ?xc ~x ?yr ?yc y
BLAS axpy
function for
matrices.
val gemm_diag : ?n:int ->
?k:int ->
?beta:Lacaml.Z.num_type ->
?ofsy:int ->
?y:Lacaml.Z.vec ->
?transa:Lacaml.Z.trans3 ->
?alpha:Lacaml.Z.num_type ->
?ar:int ->
?ac:int ->
Lacaml.Z.mat ->
?transb:Lacaml.Z.trans3 -> ?br:int -> ?bc:int -> Lacaml.Z.mat -> Lacaml.Z.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.
n
: default = number of rows of a
(or tr a
) and
number of columns of b
(or tr b
)
k
: default = number of columns of a
(or tr a
) and
number of rows of b
(or tr b
)
beta
: default = 0
ofsy
: default = 1
y
: default = fresh vector of size n + ofsy - 1
transa
: default = `N
alpha
: default = 1
ar
: default = 1
ac
: default = 1
transb
: default = `N
br
: default = 1
bc
: default = 1
val syrk_diag : ?n:int ->
?k:int ->
?beta:Lacaml.Z.num_type ->
?ofsy:int ->
?y:Lacaml.Z.vec ->
?trans:Lacaml.Common.trans2 ->
?alpha:Lacaml.Z.num_type ->
?ar:int -> ?ac:int -> Lacaml.Z.mat -> Lacaml.Z.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.
n
: default = number of rows of a
(or tra
)
k
: default = number of columns of a
(or tra
)
beta
: default = 0
ofsy
: default = 1
y
: default = fresh vector of size n + ofsy - 1
trans
: default = `N
alpha
: default = 1
ar
: default = 1
ac
: default = 1
val gemm_trace : ?n:int ->
?k:int ->
?transa:Lacaml.Z.trans3 ->
?ar:int ->
?ac:int ->
Lacaml.Z.mat ->
?transb:Lacaml.Z.trans3 ->
?br:int -> ?bc:int -> Lacaml.Z.mat -> Lacaml.Z.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
.
n
: default = number of rows of a
(or tr a
) and
number of columns of b
(or tr b
)
k
: default = number of columns of a
(or tr a
) and
number of rows of b
(or tr b
)
transa
: default = `N
ar
: default = 1
ac
: default = 1
transb
: default = `N
br
: default = 1
bc
: default = 1
val syrk_trace : ?n:int -> ?k:int -> ?ar:int -> ?ac:int -> Lacaml.Z.mat -> Lacaml.Z.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.
n
: default = number of rows of a
k
: default = number of columns of a
ar
: default = 1
ac
: default = 1
val symm2_trace : ?n:int ->
?upa:bool ->
?ar:int ->
?ac:int ->
Lacaml.Z.mat ->
?upb:bool -> ?br:int -> ?bc:int -> Lacaml.Z.mat -> Lacaml.Z.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
.
n
: default = dimensions of a
and b
upa
: default = true (upper triangular portion of a
is accessed)
ar
: default = 1
ac
: default = 1
upb
: default = true (upper triangular portion of b
is accessed)
br
: default = 1
bc
: default = 1
val map : (Lacaml.Z.num_type -> Lacaml.Z.num_type) ->
?m:int ->
?n:int ->
?br:int ->
?bc:int ->
?b:Lacaml.Z.mat -> ?ar:int -> ?ac:int -> Lacaml.Z.mat -> Lacaml.Z.mat
map f ?m ?n ?br ?bc ?b ?ar ?ac a
Returns matrix with f
applied to each element of a
.
m
: default = number of rows of a
n
: default = number of columns of a
b
: default = fresh matrix of size m by n
val fold_cols : ('a -> Lacaml.Z.vec -> 'a) -> ?n:int -> ?ac:int -> 'a -> Lacaml.Z.mat -> 'a
fold_cols f ?n ?ac acc a
Returns accumulator resulting from folding over each column vector.
n
: default = number of columns of a
ac
: default = 1