package slap
Install
Dune Dependency
Authors
Maintainers
Sources
sha256=e3bdbaad3574e8d7c4521821bf9f0a8f09284af31f16f69184dac65b6657d182
md5=6f237f6812b3f732b311d482528a39a7
doc/slap/Slap_mat/index.html
Module Slap_mat
Slap.Mat
provides operations on sized matrices.
('m, 'n, 'num, 'prec) mat
is the type of 'm
-by-'n
matrix whose elements have OCaml type 'num
, representation kind 'prec
and memory contiguity 'cnt_or_dsc
. The internal implementation is fortran-style two-dimensional big array.
val cnt :
('m, 'n, 'num, 'prec, Slap_misc.cnt) t ->
('m, 'n, 'num, 'prec, 'cnt) t
Recover polymorphism of the fifth type parameter.
Creation of matrices
val create :
('num, 'prec) Bigarray.kind ->
'm Slap_size.t ->
'n Slap_size.t ->
('m, 'n, 'num, 'prec, 'cnt) t
create kind m n
val make :
('num, 'prec) Bigarray.kind ->
'm Slap_size.t ->
'n Slap_size.t ->
'num ->
('m, 'n, 'num, 'prec, 'cnt) t
make kind m n x
val init :
('num, 'prec) Bigarray.kind ->
'm Slap_size.t ->
'n Slap_size.t ->
(int -> int -> 'num) ->
('m, 'n, 'num, 'prec, 'cnt) t
An alias of init_cols
.
val init_cols :
('num, 'prec) Bigarray.kind ->
'm Slap_size.t ->
'n Slap_size.t ->
(int -> int -> 'num) ->
('m, 'n, 'num, 'prec, 'cnt) t
init_cols kind 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 :
('num, 'prec) Bigarray.kind ->
'm Slap_size.t ->
'n Slap_size.t ->
(int -> int -> 'num) ->
('m, 'n, 'num, 'prec, 'cnt) t
init_rows kind 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 kind : ('m, 'n, 'num, 'prec, 'cd) t -> ('num, 'prec) Bigarray.kind
val dim : ('m, 'n, 'num, 'prec, 'cd) t -> 'm Slap_size.t * 'n Slap_size.t
dim a
is (dim1 a, dim2 a)
.
val dim1 : ('m, 'n, 'num, 'prec, 'cd) t -> 'm Slap_size.t
dim1 a
val dim2 : ('m, 'n, 'num, 'prec, 'cd) t -> 'n Slap_size.t
dim1 a
val get_dyn : ('m, 'n, 'num, 'prec, 'cd) t -> int -> int -> 'num
get_dyn a i j
val set_dyn : ('m, 'n, 'num, 'prec, 'cd) t -> int -> int -> 'num -> unit
set_dyn a i j x
assigns x
to the (i,j)
element of the matrix a
.
val unsafe_get : ('m, 'n, 'num, 'prec, 'cd) t -> int -> int -> 'num
Like Slap_mat.get_dyn
, but size checking is not always performed.
val unsafe_set : ('m, 'n, 'num, 'prec, 'cd) t -> int -> int -> 'num -> unit
Like Slap_mat.set_dyn
, but size checking is not always performed.
val replace_dyn :
('m, 'n, 'num, 'prec, 'cd) t ->
int ->
int ->
('num -> 'num) ->
unit
replace_dyn a i j f
is set a i j (f (get a i j))
.
val col_dyn :
('m, 'n, 'num, 'prec, 'cd) t ->
int ->
('m, 'num, 'prec, 'cnt) Slap_vec.t
col_dyn a i
val row_dyn :
('m, 'n, 'num, 'prec, 'cd) t ->
int ->
('n, 'num, 'prec, Slap_misc.dsc) Slap_vec.t
row_dyn a i
val diag :
('n, 'n, 'num, 'prec, 'cd) t ->
('n, 'num, 'prec, Slap_misc.dsc) Slap_vec.t
diag a
val diag_rect :
('m, 'n, 'num, 'prec, 'cd) t ->
(('m, 'n) Slap_size.min, 'num, 'prec, Slap_misc.dsc) Slap_vec.t
diag_rect a
val as_vec :
('m, 'n, 'num, 'prec, Slap_misc.cnt) t ->
(('m, 'n) Slap_size.mul, 'num, 'prec, 'cnt) Slap_vec.t
as_vec a
Basic operations
val fill : ('m, 'n, 'num, 'prec, 'cd) t -> 'num -> unit
Fill the given matrix with the given value.
val copy :
?b:('m, 'n, 'num, 'prec, 'b_cd) t ->
('m, 'n, 'num, 'prec, 'a_cd) t ->
('m, 'n, 'num, 'prec, 'b_cd) t
copy ?b a
copies the matrix a
into the matrix b
.
Matrix transformations
val packed :
?up:bool ->
?x:('n Slap_size.packed, 'num, 'prec, Slap_misc.cnt) Slap_vec.t ->
('n, 'n, 'num, 'prec, 'cd) t ->
('n Slap_size.packed, 'num, 'prec, 'cnt) Slap_vec.t
packed ?up ?x a
transforms triangular matrix a
into packed storage format.
val unpacked :
?up:bool ->
?fill_num:'num option ->
?a:('n, 'n, 'num, 'prec, 'cd) t ->
('n Slap_size.packed, 'num, 'prec, Slap_misc.cnt) Slap_vec.t ->
('n, 'n, 'num, 'prec, 'cd) t
unpacked ?up ?fill_num ?a x
generates an upper or lower triangular matrix from x
stored in packed storage.
val geband_dyn :
'kl Slap_size.t ->
'ku Slap_size.t ->
?b:(('m, 'n, 'kl, 'ku) Slap_size.geband, 'n, 'num, 'prec, 'b_cd) t ->
('m, 'n, 'num, 'prec, 'a_cd) t ->
(('m, 'n, 'kl, 'ku) Slap_size.geband, 'n, 'num, 'prec, 'b_cd) t
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 option ->
?a:('m, 'n, 'num, 'prec, 'a_cd) t ->
(('m, 'n, 'kl, 'ku) Slap_size.geband, 'n, 'num, 'prec, 'b_cd) t ->
('m, 'n, 'num, 'prec, 'a_cd) t
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, 'num, 'prec, 'b_cd) t ->
('n, 'n, 'num, 'prec, 'a_cd) t ->
(('n, 'kd) Slap_size.syband, 'n, 'num, 'prec, 'b_cd) t
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 option ->
?a:('n, 'n, 'num, 'prec, 'a_cd) t ->
(('n, 'kd) Slap_size.syband, 'n, 'num, 'prec, 'b_cd) t ->
('n, 'n, 'num, 'prec, 'a_cd) t
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, 'num, 'prec, 'b_cd) t ->
('m, 'n, 'num, 'prec, 'a_cd) t ->
(('m, 'n, 'kl, 'ku) Slap_size.luband, 'n, 'num, 'prec, 'b_cd) t
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 option ->
?a:('m, 'n, 'num, 'prec, 'a_cd) t ->
(('m, 'n, 'kl, 'ku) Slap_size.luband, 'n, 'num, 'prec, 'b_cd) t ->
('m, 'n, 'num, 'prec, 'a_cd) t
unluband m kl ku ?a ab
converts matrix ab
stored in band storage for LU factorization into a matrix stored in the normal order.
Iterators
val map :
('b_num, 'b_prec) Bigarray.kind ->
('a_num -> 'b_num) ->
?b:('m, 'n, 'b_num, 'b_prec, 'b_cd) t ->
('m, 'n, 'a_num, 'a_prec, 'a_cd) t ->
('m, 'n, 'b_num, 'b_prec, 'b_cd) t
val mapi :
('b_num, 'b_prec) Bigarray.kind ->
(int -> int -> 'a_num -> 'b_num) ->
?b:('m, 'n, 'b_num, 'b_prec, 'b_cd) t ->
('m, 'n, 'a_num, 'a_prec, 'a_cd) t ->
('m, 'n, 'b_num, 'b_prec, 'b_cd) t
val fold_left :
('accum -> ('m, 'num, 'prec, 'x_cd) Slap_vec.t -> 'accum) ->
'accum ->
('m, 'n, 'num, 'prec, 'a_cd) t ->
'accum
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, 'num, 'prec, 'x_cd) Slap_vec.t -> 'accum) ->
'accum ->
('m, 'n, 'num, 'prec, 'a_cd) t ->
'accum
fold_lefti f init a
folds column vectors of matrix a
by f
in the order left to right.
val fold_right :
(('m, 'num, 'prec, 'x_cd) Slap_vec.t -> 'accum -> 'accum) ->
('m, 'n, 'num, 'prec, 'a_cd) t ->
'accum ->
'accum
fold_right f a init
folds column vectors of matrix a
by f
in the order right to left.
val fold_righti :
(int -> ('m, 'num, 'prec, 'x_cd) Slap_vec.t -> 'accum -> 'accum) ->
('m, 'n, 'num, 'prec, 'a_cd) t ->
'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, 'num, 'prec, Slap_misc.dsc) Slap_vec.t -> 'accum) ->
'accum ->
('m, 'n, 'num, 'prec, 'a_cd) t ->
'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, 'num, 'prec, Slap_misc.dsc) Slap_vec.t -> 'accum) ->
'accum ->
('m, 'n, 'num, 'prec, 'a_cd) t ->
'accum
fold_topi f init a
folds row vectors of matrix a
by f
in the order top to bottom.
val fold_bottom :
(('n, 'num, 'prec, Slap_misc.dsc) Slap_vec.t -> 'accum -> 'accum) ->
('m, 'n, 'num, 'prec, 'a_cd) t ->
'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, 'num, 'prec, Slap_misc.dsc) Slap_vec.t -> 'accum -> 'accum) ->
('m, 'n, 'num, 'prec, 'a_cd) t ->
'accum ->
'accum
fold_bottomi f a init
folds row vectors of matrix a
by f
in the order bottom to top.
val replace_all : ('m, 'n, 'num, 'prec, 'cd) t -> ('num -> 'num) -> unit
replace_all a f
modifies the matrix a
in place -- the (i,j)
-element aij
of a
will be set to f aij
.
val replace_alli :
('m, 'n, 'num, 'prec, 'cd) t ->
(int -> int -> 'num -> 'num) ->
unit
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
.
Type conversion
val to_array : ('m, 'n, 'num, 'prec, 'cd) t -> 'num array array
to_array a
val of_array_dyn :
('num, 'prec) Bigarray.kind ->
'm Slap_size.t ->
'n Slap_size.t ->
'num array array ->
('m, 'n, 'num, 'prec, 'cnt) t
Build a matrix initialized from the given array of arrays.
val unsafe_of_array :
('num, 'prec) Bigarray.kind ->
'm Slap_size.t ->
'n Slap_size.t ->
'num array array ->
('m, 'n, 'num, 'prec, 'cnt) t
Like of_array_dyn
, but size checking is not always performed.
val to_list : ('m, 'n, 'num, 'prec, 'cd) t -> 'num list list
to_list a
val of_list_dyn :
('num, 'prec) Bigarray.kind ->
'm Slap_size.t ->
'n Slap_size.t ->
'num list list ->
('m, 'n, 'num, 'prec, 'cnt) t
Build a matrix initialized from the given list of lists.
val unsafe_of_list :
('num, 'prec) Bigarray.kind ->
'm Slap_size.t ->
'n Slap_size.t ->
'num list list ->
('m, 'n, 'num, 'prec, 'cnt) t
Like of_list_dyn
, but size checking is not always performed.
val to_bigarray :
('m, 'n, 'num, 'prec, 'cd) t ->
('num, '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, 'prec, Bigarray.fortran_layout) Bigarray.Array2.t ->
('m, 'n, 'num, 'prec, 'cnt) t
of_bigarray_dyn ?share m n ba
val unsafe_of_bigarray :
?share:bool ->
'm Slap_size.t ->
'n Slap_size.t ->
('num, 'prec, Bigarray.fortran_layout) Bigarray.Array2.t ->
('m, 'n, 'num, 'prec, 'cnt) t
Like of_bigarray_dyn
, but size checking is not always performed.
Submatrices
val submat_dyn :
'm Slap_size.t ->
'n Slap_size.t ->
?ar:int ->
?ac:int ->
(_, _, 'num, 'prec, 'cd) t ->
('m, 'n, 'num, 'prec, Slap_misc.dsc) t
submat_dyn m n ?ar ?ac a
Utilities
dim_array_array aa
returns Some (n_rows, n_cols)
with the number of rows n_rows
and the number of columns n_cols
of the given array of arrays. (0, 0)
is returned if aa
is an empty array. None
is returned if aa
is not rectangular.