package slap
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=8de0d6e7be2e47fe2e1447a1a5f99b42cbbd7e0524f163d1addf9b156337ec27
md5=6e3068a3d425ffaee22f7dacf7d6cece
doc/slap/Slap_C/Vec/index.html
Module Slap_C.Vec
module type CNTVEC = sig ... endThe signature of modules containing dynamically-sized contiguous vectors.
module type DSCVEC = sig ... endThe signature of modules containing dynamically-sized discrete vectors.
val cnt : ('n, Slap_misc.cnt) vec -> ('n, 'cnt) vecRecover polymorphism of the fourth type parameter.
Creation of vectors
val empty : (Slap_size.z, 'cnt) vecAn empty vector.
val create : 'n Slap_size.t -> ('n, 'cnt) veccreate n
val make : 'n Slap_size.t -> num_type -> ('n, 'cnt) vecmake n a
val make0 : 'n Slap_size.t -> ('n, 'cnt) veczeros n
val make1 : 'n Slap_size.t -> ('n, 'cnt) vecmake1 n
val init : 'n Slap_size.t -> (int -> num_type) -> ('n, 'cnt) vecinit n f
Accessors
val dim : ('n, 'cd) vec -> 'n Slap_size.tdim x
set_dyn x i a assigns a to the i-th element of the vector x.
Like get_dyn, but size checking is not always performed.
Like set_dyn, but size checking is not always performed.
replace_dyn v i f is set_dyn v i (f (get_dyn v i)).
Basic operations
val cons :
?y:('n Slap_size.s, 'y_cd) vec ->
num_type ->
('n, 'x_cd) vec ->
('n Slap_size.s, 'y_cd) veccons ?y e x adds element e at the beginning of vector x, and copies it into y.
val hd : ('n Slap_size.s, 'x_cd) vec -> num_typeval last : ('n Slap_size.s, 'x_cd) vec -> num_typeval tl : ?y:('n, 'y_cd) vec -> ('n Slap_size.s, 'x_cd) vec -> ('n, 'x_cd) vecval tl_dyn :
?y:('n Slap_size.p, 'y_cd) vec ->
('n, 'x_cd) vec ->
('n Slap_size.p, 'x_cd) vecval inits :
?y:('n, 'y_cd) vec ->
('n Slap_size.s, 'x_cd) vec ->
('n, 'x_cd) vecval inits_dyn :
?y:('n Slap_size.p, 'y_cd) vec ->
('n, 'x_cd) vec ->
('n Slap_size.p, 'x_cd) veccopy ?y x copies the vector x to the vector y with the BLAS-1 function [sdcz]copy.
val append :
('m, 'x_cd) vec ->
('n, 'y_cd) vec ->
(('m, 'n) Slap_size.add, 'cnt) vecConcatenate two vectors.
shared_rev (x1, x2, ..., xn)
Type conversion
val of_array_dyn : 'n Slap_size.t -> num_type array -> ('n, 'cnt) vecof_array_dyn n [|a1; ...; an|]
val unsafe_of_array : 'n Slap_size.t -> num_type array -> ('n, 'cnt) vecLike of_array_dyn, but size checking is not always performed.
val of_list_dyn : 'n Slap_size.t -> num_type list -> ('n, 'cnt) vecof_list_dyn n [a1; ...; an]
val unsafe_of_list : 'n Slap_size.t -> num_type list -> ('n, 'cnt) vecLike of_list_dyn, but size checking is not always performed.
val to_bigarray :
('n, 'cd) vec ->
(num_type, prec, Bigarray.fortran_layout) Bigarray.Array1.tto_bigarray x
val of_bigarray_dyn :
?share:bool ->
'n Slap_size.t ->
(num_type, prec, Bigarray.fortran_layout) Bigarray.Array1.t ->
('n, 'cnt) vecof_bigarray_dyn ?share n ba
val of_bigarray :
?share:bool ->
(num_type, prec, Bigarray.fortran_layout) Bigarray.Array1.t ->
(module CNTVEC)module V = (val of_bigarray ?share n ba : CNTVEC)
module Of_bigarray (X : sig ... end) : CNTVECA functor version of of_bigarray.
val unsafe_of_bigarray :
?share:bool ->
'n Slap_size.t ->
(num_type, prec, Bigarray.fortran_layout) Bigarray.Array1.t ->
('n, 'cnt) vecLike of_bigarray_dyn, but size checking is not always performed.
val of_array_c : num_type array -> (num_type, prec, 'cnt) Slap_vec.dynlet Slap.Vec.VEC n = of_array_c [|a1; ...; an|]
val of_list_c : num_type list -> (num_type, prec, 'cnt) Slap_vec.dynlet Slap.Vec.VEC n = of_list_c [a1; ...; an]
val of_bigarray_c :
?share:bool ->
(num_type, prec, Bigarray.fortran_layout) Bigarray.Array1.t ->
(num_type, prec, 'cnt) Slap_vec.dynlet Slap.Vec.VEC n = of_bigarray_c ?share ba
Iterators
map f ?y (x1, ..., xn) is (f x1, ..., f xn).
val mapi :
(int -> num_type -> num_type) ->
?y:('n, 'y_cd) vec ->
('n, 'x_cd) vec ->
('n, 'y_cd) vecmapi f ?y (x1, ..., xn) is (f 1 x1, ..., f n xn) with the vector's dimension n.
fold_left f init (x1, x2, ..., xn) is f (... (f (f init x1) x2) ...) xn.
fold_lefti f init (x1, x2, ..., xn) is f n (... (f 2 (f 1 init x1) x2) ...) xn with the vector's dimension n.
fold_right f (x1, x2, ..., xn) init is f x1 (f x2 (... (f xn init) ...)).
fold_righti f (x1, x2, ..., xn) init is f 1 x1 (f 2 x2 (... (f n xn init) ...)) with the vector's dimension n.
replace_all x f modifies the vector x in place -- the i-th element xi of x will be set to f xi.
replace_alli x f modifies the vector x in place -- the i-th element xi of x will be set to f i xi.
iter f (x1, x2, ..., xn) is f x1; f x2; ...; f xn.
iteri f (x1, x2, ..., xn) is f 1 x1; f 2 x2; ...; f n xn.
Iterators on two vectors
val map2 :
(num_type -> num_type -> num_type) ->
?z:('n, 'z_cd) vec ->
('n, 'x_cd) vec ->
('n, 'y_cd) vec ->
('n, 'z_cd) vecmap2 f ?z (x1, x2, ..., xn) (y1, y2, ..., yn) is (f x1 y1, f x2 y2, ..., f xn yn).
val mapi2 :
(int -> num_type -> num_type -> num_type) ->
?z:('n, 'z_cd) vec ->
('n, 'x_cd) vec ->
('n, 'y_cd) vec ->
('n, 'z_cd) vecmapi2 f ?z (x1, x2, ..., xn) (y1, y2, ..., yn) is (f 1 x1 y1, f 2 x2 y2, ..., f n xn yn) with the vectors' dimension n.
val fold_left2 :
('accum -> num_type -> num_type -> 'accum) ->
'accum ->
('n, 'x_cd) vec ->
('n, 'y_cd) vec ->
'accumfold_left2 f init (x1, x2, ..., xn) (y1, y2, ..., yn) is f (... (f (f init x1 y1) x2 y2) ...) xn yn.
val fold_lefti2 :
(int -> 'accum -> num_type -> num_type -> 'accum) ->
'accum ->
('n, 'x_cd) vec ->
('n, 'y_cd) vec ->
'accumfold_lefti2 f init (x1, x2, ..., xn) (y1, y2, ..., yn) is f n (... (f 2 (f 1 init x1 y1) x2 y2) ...) xn yn with the vectors' dimension n.
val fold_right2 :
(num_type -> num_type -> 'accum -> 'accum) ->
('n, 'x_cd) vec ->
('n, 'y_cd) vec ->
'accum ->
'accumfold_righti2 f (x1, x2, ..., xn) (y1, y2, ..., yn) init is f x1 y1 (f x2 y2 (... (f xn yn init) ...)).
val fold_righti2 :
(int -> num_type -> num_type -> 'accum -> 'accum) ->
('n, 'x_cd) vec ->
('n, 'y_cd) vec ->
'accum ->
'accumfold_righti2 f (x1, x2, ..., xn) (y1, y2, ..., yn) init is f 1 x1 y1 (f 2 x2 y2 (... (f n xn yn init) ...)) with the vectors' dimension n.
iter2 f (x1, x2, ..., xn) (y1, y2, ..., yn) is f x1 y1; f x2 y2; ...; f xn yn.
iteri2 f (x1, x2, ..., xn) (y1, y2, ..., yn) is f 1 x1 y1; f 2 x2 y2; ...; f n xn yn.
Iterators on three vectors
val map3 :
(num_type -> num_type -> num_type -> num_type) ->
?w:('n, 'w_cd) vec ->
('n, 'x_cd) vec ->
('n, 'y_cd) vec ->
('n, 'z_cd) vec ->
('n, 'w_cd) vecmap3 f ?w (x1, x2, ..., xn) (y1, y2, ..., yn) (z1, z2, ..., zn) is (f x1 y1 z1, f x2 y2 z2, ..., f xn yn zn).
val mapi3 :
(int -> num_type -> num_type -> num_type -> num_type) ->
?w:('n, 'w_cd) vec ->
('n, 'x_cd) vec ->
('n, 'y_cd) vec ->
('n, 'z_cd) vec ->
('n, 'w_cd) vecmapi3 f ?w (x1, x2, ..., xn) (y1, y2, ..., yn) (z1, z2, ..., zn) is (f 1 x1 y1 z1, f 2 x2 y2 z2, ..., f n xn yn zn) with the vectors' dimension n.
val fold_left3 :
('accum -> num_type -> num_type -> num_type -> 'accum) ->
'accum ->
('n, 'x_cd) vec ->
('n, 'y_cd) vec ->
('n, 'z_cd) vec ->
'accumfold_left3 f init (x1, x2, ..., xn) (y1, y2, ..., yn) (z1, z2, ..., zn) is f (... (f (f init x1 y1 z1) x2 y2 z2) ...) xn yn zn.
val fold_lefti3 :
(int -> 'accum -> num_type -> num_type -> num_type -> 'accum) ->
'accum ->
('n, 'x_cd) vec ->
('n, 'y_cd) vec ->
('n, 'z_cd) vec ->
'accumfold_lefti3 f init (x1, x2, ..., xn) (y1, y2, ..., yn) (z1, z2, ..., zn) is f n (... (f 2 (f 1 init x1 y1 z1) x2 y2 z2) ...) xn yn zn with the vectors' dimension n.
val fold_right3 :
(num_type -> num_type -> num_type -> 'accum -> 'accum) ->
('n, 'x_cd) vec ->
('n, 'y_cd) vec ->
('n, 'z_cd) vec ->
'accum ->
'accumfold_right3 f (x1, x2, ..., xn) (y1, y2, ..., yn) (z1, z2, ..., zn) init is f x1 y1 z1 (f x2 y2 z2 (... (f xn yn zn init) ...)).
val fold_righti3 :
(int -> num_type -> num_type -> num_type -> 'accum -> 'accum) ->
('n, 'x_cd) vec ->
('n, 'y_cd) vec ->
('n, 'z_cd) vec ->
'accum ->
'accumfold_righti3 f (x1, x2, ..., xn) (y1, y2, ..., yn) (z1, z2, ..., zn) init is f 1 x1 y1 z1 (f 2 x2 y2 z2 (... (f n xn yn zn init) ...)) with the vectors' dimension n.
val iter3 :
(num_type -> num_type -> num_type -> unit) ->
('n, 'x_cd) vec ->
('n, 'y_cd) vec ->
('n, 'z_cd) vec ->
unititer3 f (x1, x2, ..., xn) (y1, y2, ..., yn) (z1, z2, ..., zn) is f x1 y1 z1; f x2 y2 z2; ...; f xn yn zn.
val iteri3 :
(int -> num_type -> num_type -> num_type -> unit) ->
('n, 'x_cd) vec ->
('n, 'y_cd) vec ->
('n, 'z_cd) vec ->
unititeri3 f (x1, x2, ..., xn) (y1, y2, ..., yn) (z1, z2, ..., zn) is f 1 x1 y1 z1; f 2 x2 y2 z2; ...; f n xn yn zn.
Scanning
for_all p (x1, x2, ..., xn) is (p x1) && (p x2) && ... && (p xn).
exists p (x1, x2, ..., xn) is (p x1) || (p x2) || ... || (p xn).
for_all2 p (x1, x2, ..., xn) (y1, y2, ..., yn) is (p x1 y1) && (p x2 y2) && ... && (p xn yn).
exists2 p (x1, x2, ..., xn) (y1, y2, ..., yn) is (p x1 y1) || (p x2 y2) || ... || (p xn yn).
Arithmetic operations
add_const c ?y x adds constant value c to all elements in vector x.
val sqr_nrm2 : ?stable:bool -> ('n, 'cd) vec -> floatsqr_nrm2 ?stable x computes the square of the 2-norm (Euclidean norm) of vector x.
ssqr ?c (x1, x2, ..., xn) computes the sum of squared differences of the elements in the given vector from scalar value c: (x1 - c)^2 + (x2 - c)^2 + ... + (xn - c)^2.
val sort :
?cmp:(num_type -> num_type -> int) ->
?decr:bool ->
?p:('n, 'p_cd) Slap_common.int_vec ->
('n, 'x_cd) vec ->
unitsort ?cmp ?decr ?p x sorts the elements in vector x in increasing order according to the comparison function cmp.
neg ?y (x1, x2, ..., xn) returns (-x1, -x2, ..., -xn).
reci ?y (x1, x2, ..., xn) returns (1 / x1, 1 / x2, ..., 1 / xn).
add ?z (x1, x2, ..., xn) (y1, y2, ..., yn) returns (x1 + y1, x2 + y2, ..., xn + yn).
sub ?z (x1, x2, ..., xn) (y1, y2, ..., yn) returns (x1 - y1, x2 - y2, ..., xn - yn).
mul ?z (x1, x2, ..., xn) (y1, y2, ..., yn) returns (x1 * y1, x2 * y2, ..., xn * yn).
div ?z (x1, x2, ..., xn) (y1, y2, ..., yn) returns (x1 / y1, x2 / y2, ..., xn / yn).
zpxy (z1, z2, ..., zn) (x1, x2, ..., xn) (y1, y2, ..., yn) returns (z1 + x1 * y1, z2 + x2 * y2, ..., zn + xn * yn). This function is useful for convolutions.
zmxy (z1, z2, ..., zn) (x1, x2, ..., xn) (y1, y2, ..., yn) returns (z1 - x1 * y1, z2 - x2 * y2, ..., zn - xn * yn). This function is useful for convolutions.
ssqr_diff x yreturns the sum of squared differences of the elements of vectors x and y.
Subvectors
val subcntvec_dyn :
'm Slap_size.t ->
?ofsx:int ->
('n, Slap_misc.cnt) vec ->
('m, 'cnt) vecsubcntvec_dyn m ?ofsx x
val subdscvec_dyn :
'm Slap_size.t ->
?ofsx:int ->
?incx:int ->
('n, 'cd) vec ->
('m, Slap_misc.dsc) vecsubdscvec_dyn m ?ofsx ?incx x
val subvec_dyn :
'm Slap_size.t ->
?ofsx:int ->
?incx:int ->
('n, 'cd) vec ->
('m, Slap_misc.dsc) vecAn alias of subdscvec_dyn.
Creation of vectors
val random :
?rnd_state:Random.State.t ->
?re_from:float ->
?re_range:float ->
?im_from:float ->
?im_range:float ->
'n Slap_size.t ->
('n, 'cnt) vecrandom ?rnd_state ?from ?range n creates a n-dimensional vector randomly initialized with the uniform distribution between re_from/im_from and re_from+re_range/im_from+im_range for real and imaginary parts, respectively.