package slap
Install
Dune Dependency
Authors
Maintainers
Sources
sha256=9a859ca657964c0adeeb29f3ba56291bbc6305f1c88ad71a1f532b1e7acdff55
md5=e06c98c671bee929dcda3231516d8d87
doc/slap/Slap_D/Mat/index.html
Module Slap_D.Mat
module type CNTMAT = sig ... end
The signature of modules containing dynamically-sized contiguous matrices.
module type DSCMAT = sig ... end
The signature of modules containing dynamically-sized discrete matrices.
val cnt : ('m, 'n, Slap_misc.cnt) mat -> ('m, 'n, 'cnt) mat
Recover polymorphism of the fifth type parameter.
Creation of matrices
val empty : (Slap_size.z, Slap_size.z, 'cnt) mat
An empty matrix.
val create : 'm Slap_size.t -> 'n Slap_size.t -> ('m, 'n, 'cnt) mat
create m n
val make : 'm Slap_size.t -> 'n Slap_size.t -> num_type -> ('m, 'n, 'cnt) mat
make m n x
val make0 : 'm Slap_size.t -> 'n Slap_size.t -> ('m, 'n, 'cnt) mat
make0 m n
val make1 : 'm Slap_size.t -> 'n Slap_size.t -> ('m, 'n, 'cnt) mat
make1 m n
val identity : 'n Slap_size.t -> ('n, 'n, 'cnt) mat
identity n
val init :
'm Slap_size.t ->
'n Slap_size.t ->
(int -> int -> num_type) ->
('m, 'n, 'cnt) mat
An alias of init_cols
.
val init_cols :
'm Slap_size.t ->
'n Slap_size.t ->
(int -> int -> num_type) ->
('m, 'n, 'cnt) mat
init_cols m n f
returns a fresh m
-by-n
matrix whose the (i,j)
element is initialized by the result of calling f i j
. The elements are passed column-wise.
val init_rows :
'm Slap_size.t ->
'n Slap_size.t ->
(int -> int -> num_type) ->
('m, 'n, 'cnt) mat
init_rows m n f
returns a fresh m
-by-n
matrix whose the (i,j)
element is initialized by the result of calling f i j
. The elements are passed row-wise.
Accessors
val dim : ('m, 'n, 'cd) mat -> 'm Slap_size.t * 'n Slap_size.t
dim a
is (dim1 a, dim2 a)
.
val dim1 : ('m, 'n, 'cd) mat -> 'm Slap_size.t
dim1 a
val dim2 : ('m, 'n, 'cd) mat -> 'n Slap_size.t
dim1 a
set_dyn a i j x
assigns x
to the (i,j)
element of the matrix a
.
Like get_dyn
, but size checking is not always performed.
Like set_dyn
, but size checking is not always performed.
val row_dyn : ('m, 'n, 'cd) mat -> int -> ('n, Slap_misc.dsc) vec
row_dyn a i
copy_row_dyn a i
is Vec.copy (Mat.row_dyn a i)
.
val diag : ('n, 'n, 'cd) mat -> ('n, Slap_misc.dsc) vec
diag a
val diag_rect :
('m, 'n, 'cd) mat ->
(('m, 'n) Slap_size.min, Slap_misc.dsc) vec
diag_rect a
val copy_diag_rect : ('m, 'n, 'cd) mat -> (('m, 'n) Slap_size.min, 'cnt) vec
copy_diag_rect a
is Vec.copy (Mat.diag_rect a)
.
val as_vec : ('m, 'n, Slap_misc.cnt) mat -> (('m, 'n) Slap_size.mul, 'cnt) vec
as_vec a
Basic operations
val copy :
?uplo:[ `L | `U ] ->
?b:('m, 'n, 'b_cd) mat ->
('m, 'n, 'a_cd) mat ->
('m, 'n, 'b_cd) mat
copy ?uplo ?b a
copies the matrix a
into the matrix b
with the LAPACK function lacpy
.
- If
uplo
is omitted, all elements ina
is copied. - If
uplo
is`U
, the upper trapezoidal part ofa
is copied. - If
uplo
is`L
, the lower trapezoidal part ofa
is copied.
val of_col_vecs_dyn :
'm Slap_size.t ->
'n Slap_size.t ->
('m, Slap_misc.cnt) vec array ->
('m, 'n, 'cnt) mat
Type conversion
val of_array_dyn :
'm Slap_size.t ->
'n Slap_size.t ->
num_type array array ->
('m, 'n, 'cnt) mat
Build a matrix initialized from the given array of arrays.
val unsafe_of_array :
'm Slap_size.t ->
'n Slap_size.t ->
num_type array array ->
('m, 'n, 'cnt) mat
Like of_array_dyn
, but size checking is not always performed.
val of_list_dyn :
'm Slap_size.t ->
'n Slap_size.t ->
num_type list list ->
('m, 'n, 'cnt) mat
Build a matrix initialized from the given list of lists.
val unsafe_of_list :
'm Slap_size.t ->
'n Slap_size.t ->
num_type list list ->
('m, 'n, 'cnt) mat
Like of_list_dyn
, but size checking is not always performed.
val to_bigarray :
('m, 'n, 'cd) mat ->
(num_type, prec, Bigarray.fortran_layout) Bigarray.Array2.t
to_bigarray a
val of_bigarray_dyn :
?share:bool ->
'm Slap_size.t ->
'n Slap_size.t ->
(num_type, prec, Bigarray.fortran_layout) Bigarray.Array2.t ->
('m, 'n, 'cnt) mat
of_bigarray_dyn ?share m n ba
val of_bigarray :
(num_type, prec, Bigarray.fortran_layout) Bigarray.Array2.t ->
(module CNTMAT)
module M = (val of_bigarray ba : CNTMAT)
module Of_bigarray (X : sig ... end) : CNTMAT
A functor vesion of of_bigarray
.
val unsafe_of_bigarray :
?share:bool ->
'm Slap_size.t ->
'n Slap_size.t ->
(num_type, prec, Bigarray.fortran_layout) Bigarray.Array2.t ->
('m, 'n, 'cnt) mat
Like of_bigarray_dyn
, but size checking is not always performed.
val of_array_c : num_type array array -> (num_type, prec, 'cnt) Slap_mat.dyn
let Slap.Mat.MAT n = of_array_c arr
val of_list_c : num_type list list -> (num_type, prec, 'cnt) Slap_mat.dyn
let Slap.Mat.MAT n = of_list_c kind lst
val of_bigarray_c :
?share:bool ->
(num_type, prec, Bigarray.fortran_layout) Bigarray.Array2.t ->
(num_type, prec, 'cnt) Slap_mat.dyn
let Slap.Mat.MAT n = of_bigarray_c ?share ba
Iterators
fold_left f init a
folds column vectors of matrix a
by f
in the order left to right.
val fold_lefti :
(int -> 'accum -> ('m, 'x_cd) vec -> 'accum) ->
'accum ->
('m, 'n, 'a_cd) mat ->
'accum
fold_lefti f init a
folds column vectors of matrix a
by f
in the order left to right.
fold_right f a init
folds column vectors of matrix a
by f
in the order right to left.
val fold_righti :
(int -> ('m, 'x_cd) vec -> 'accum -> 'accum) ->
('m, 'n, 'a_cd) mat ->
'accum ->
'accum
fold_righti f a init
folds column vectors of matrix a
by f
in the order right to left.
val fold_top :
('accum -> ('n, Slap_misc.dsc) vec -> 'accum) ->
'accum ->
('m, 'n, 'a_cd) mat ->
'accum
fold_top f init a
folds row vectors of matrix a
by f
in the order top to bottom.
val fold_topi :
(int -> 'accum -> ('n, Slap_misc.dsc) vec -> 'accum) ->
'accum ->
('m, 'n, 'a_cd) mat ->
'accum
fold_topi f init a
folds row vectors of matrix a
by f
in the order top to bottom.
val fold_bottom :
(('n, Slap_misc.dsc) vec -> 'accum -> 'accum) ->
('m, 'n, 'a_cd) mat ->
'accum ->
'accum
fold_bottom f a init
folds row vectors of matrix a
by f
in the order bottom to top.
val fold_bottomi :
(int -> ('n, Slap_misc.dsc) vec -> 'accum -> 'accum) ->
('m, 'n, 'a_cd) mat ->
'accum ->
'accum
fold_bottomi f a init
folds row vectors of matrix a
by f
in the order bottom to top.
replace_all a f
modifies the matrix a
in place -- the (i,j)
-element aij
of a
will be set to f aij
.
replace_all a f
modifies the matrix a
in place -- the (i,j)
-element aij
of a
will be set to f i j aij
.
Matrix transformations
transpose_copy ?b a
copies the transpose of a
into b
.
val detri : ?up:bool -> ('n, 'n, 'cd) mat -> unit
detri ?up a
converts triangular matrix a
to a symmetric matrix, i.e., copies the upper or lower triangular part of a
into another part.
val packed :
?up:bool ->
?x:('n Slap_size.packed, Slap_misc.cnt) vec ->
('n, 'n, 'cd) mat ->
('n Slap_size.packed, 'cnt) vec
packed ?up ?x a
transforms matrix a
into packed storage format.
val unpacked :
?up:bool ->
?fill_num:num_type option ->
?a:('n, 'n, 'cd) mat ->
('n Slap_size.packed, Slap_misc.cnt) vec ->
('n, 'n, 'cd) mat
unpacked ?up ?fill_num ?a x
generates an upper or lower triangular matrix from packed-storage-format vector x
.
val geband_dyn :
'kl Slap_size.t ->
'ku Slap_size.t ->
?b:(('m, 'n, 'kl, 'ku) Slap_size.geband, 'n, 'b_cd) mat ->
('m, 'n, 'a_cd) mat ->
(('m, 'n, 'kl, 'ku) Slap_size.geband, 'n, 'b_cd) mat
geband_dyn kl ku ?b a
converts matrix a
into a matrix stored in band storage.
val ungeband :
'm Slap_size.t ->
'kl Slap_size.t ->
'ku Slap_size.t ->
?fill_num:num_type option ->
?a:('m, 'n, 'a_cd) mat ->
(('m, 'n, 'kl, 'ku) Slap_size.geband, 'n, 'b_cd) mat ->
('m, 'n, 'a_cd) mat
ungeband m kl ku ?a b
converts matrix b
stored in band storage into a matrix stored in the normal order.
val syband_dyn :
'kd Slap_size.t ->
?up:bool ->
?b:(('n, 'kd) Slap_size.syband, 'n, 'b_cd) mat ->
('n, 'n, 'a_cd) mat ->
(('n, 'kd) Slap_size.syband, 'n, 'b_cd) mat
syband_dyn kd ?b a
converts matrix a
into a matrix stored in symmetric or Hermitian band storage.
val unsyband :
'kd Slap_size.t ->
?up:bool ->
?fill_num:num_type option ->
?a:('n, 'n, 'a_cd) mat ->
(('n, 'kd) Slap_size.syband, 'n, 'b_cd) mat ->
('n, 'n, 'a_cd) mat
unsyband kd ?a b
converts matrix b
stored in symmetric or Hermitian band storage into a matrix stored in the normal order.
val luband_dyn :
'kl Slap_size.t ->
'ku Slap_size.t ->
?ab:(('m, 'n, 'kl, 'ku) Slap_size.luband, 'n, 'b_cd) mat ->
('m, 'n, 'a_cd) mat ->
(('m, 'n, 'kl, 'ku) Slap_size.luband, 'n, 'b_cd) mat
luband_dyn kl ku ?ab a
converts matrix a
into a matrix stored in band storage for LU factorization.
val unluband :
'm Slap_size.t ->
'kl Slap_size.t ->
'ku Slap_size.t ->
?fill_num:num_type option ->
?a:('m, 'n, 'a_cd) mat ->
(('m, 'n, 'kl, 'ku) Slap_size.luband, 'n, 'b_cd) mat ->
('m, 'n, 'a_cd) mat
unluband m kl ku ?a ab
converts matrix ab
stored in band storage for LU factorization into a matrix stored in the normal order.
Arithmetic operations
add_const c ?b a
adds constant value c
to all elements in a
.
scal alpha a
computes a := alpha * a
with the scalar value alpha
and the matrix a
.
val scal_cols : ('m, 'n, 'cd) mat -> ('n, Slap_misc.cnt) vec -> unit
A column-wise scal
function for matrices.
val scal_rows : ('m, Slap_misc.cnt) vec -> ('m, 'n, 'cd) mat -> unit
A row-wise scal
function for matrices.
axpy ?alpha x y
computes y := alpha * x + y
.
val gemm_diag :
?beta:num_type ->
?y:('n, Slap_misc.cnt) vec ->
transa:('a_n * 'a_k, 'n * 'k, _) trans3 ->
?alpha:num_type ->
('a_n, 'a_k, 'a_cd) mat ->
transb:('b_k * 'b_n, 'k * 'n, _) trans3 ->
('b_k, 'b_n, 'b_cd) mat ->
('n, 'cnt) vec
gemm_diag ?beta ?y ~transa ?alpha a ~transb b
executes y := DIAG(alpha * OP(a) * OP(b)) + beta * y
where DIAG(x)
is the vector of the diagonal elements in matrix x
, and OP(x)
is one of OP(x)
= x
, OP(x)
= x^T
, or OP(x)
= x^H
(the conjugate transpose of x
).
val syrk_diag :
?beta:num_type ->
?y:('n, Slap_misc.cnt) vec ->
trans:('a_n * 'a_k, 'n * 'k, _) Slap_common.trans2 ->
?alpha:num_type ->
('a_n, 'a_k, 'a_cd) mat ->
('n, 'cnt) vec
syrk_diag ?beta ?y ~transa ?alpha a
executes
y := alpha * DIAG(a * a^T) + beta * y
(iftrans
=Slap_common.normal
) ory := alpha * DIAG(a^T * a) + beta * y
(iftrans
=Slap_common.trans
)
where DIAG(x)
is the vector of the diagonal elements in matrix x
.
val gemm_trace :
transa:('a_n * 'a_k, 'n * 'k, _) trans3 ->
('a_n, 'a_k, 'a_cd) mat ->
transb:('b_k * 'b_n, 'k * 'n, _) trans3 ->
('b_k, 'b_n, 'b_cd) mat ->
num_type
gemm_trace ~transa a ~transb b
syrk_trace a
computes the trace of a * a^T
or a^T * a
.
symm2_trace ?upa a ?upb b
computes the trace of a * b
with symmetric matrices a
and b
.
Submatrices
val submat_dyn :
'm Slap_size.t ->
'n Slap_size.t ->
?ar:int ->
?ac:int ->
(_, _, 'cd) mat ->
('m, 'n, Slap_misc.dsc) mat
submat_dyn m n ?ar ?ac a
Creation of matrices
val random :
?rnd_state:Random.State.t ->
?from:float ->
?range:float ->
'm Slap_size.t ->
'n Slap_size.t ->
('m, 'n, 'cnt) mat
random ?rnd_state ?from ?range m n
creates a m
-by-n
matrix randomly initialized with the uniform distribution between from
and from + range
.