Module Vec.Make
Make
takes as input the signature of an object language and generates a module to perform vector computations in this language.
Parameters
Repr : Basic_structures.Basic_intf.Lang.Empty
Monad : Basic_structures.Basic_intf.Codegen_monad with type 'a m = 'a Repr.m
S : Basic_structures.Basic_intf.Lang.Shape with type 'a m = 'a Repr.m
B : Basic_structures.Basic_intf.Lang.Bool with type 'a m = 'a Repr.m
R : Basic_structures.Basic_intf.Lang.Ring with type 'a m = 'a Repr.m
R_storage : Basic_structures.Basic_intf.Lang.Storage with type 'a m = 'a Repr.m and type elt = R.t
E : Basic_structures.Basic_intf.Lang.Exn with type 'a m = 'a Repr.m
M : Basic_structures.Basic_intf.Lang.Sequencing with type 'a m = 'a Repr.m
Signature
type 'a k
= 'a Monad.t
Ambient monad.
type 'a m
= 'a Repr.m
Representation.
type 'a shape
= 'a S.t
Type of shapes.
type ('a, 'b) morphism
= ('a, 'b) S.Morphism.t
Type of shape morphisms.
type elt
= R.t
Type of elements.
type 'i t
= ('i shape, 'i m, elt m) Linalg.Intf.vec
type 'i out
= ('i shape, 'i m, elt m, unit m) Linalg.Intf.ovec
val make : 'i shape -> ('i m -> elt m) -> 'i t
Creates an input vector from a dimension and a function.
val get : 'i t -> 'i m -> elt m k
Get an elemement of an input vector.
- raises Out_of_bounds
if given index is not in the domain of the vector.
val unsafe_get : 'i t -> 'i m -> elt m
Get an elemement of an input vector. Does not perform bound checking.
val set : 'i out -> 'i m -> elt m -> unit m k
Set an elemement in an output vector.
- raises Out_of_bounds
if given index is not in the domain of the vector.
val map : ('a m -> 'b m) -> ('i shape, 'i m, 'a m) Linalg.Intf.vec -> ('i shape, 'i m, 'b m) Linalg.Intf.vec
val mapi : ('i m -> 'a m -> 'b m) -> ('i shape, 'i m, 'a m) Linalg.Intf.vec -> ('i shape, 'i m, 'b m) Linalg.Intf.vec
val map2 : ('a m -> 'b m -> 'c m) -> ('i shape, 'i m, 'a m) Linalg.Intf.vec -> ('i shape, 'i m, 'b m) Linalg.Intf.vec -> ('i shape, 'i m, 'c m) Linalg.Intf.vec k
val map2i : ('i m -> 'a m -> 'b m -> 'c m) -> ('i shape, 'i m, 'a m) Linalg.Intf.vec -> ('i shape, 'i m, 'b m) Linalg.Intf.vec -> ('i shape, 'i m, 'c m) Linalg.Intf.vec k
val assign : ('i shape, 'i m, 'a m, unit m) Linalg.Intf.ovec -> ('i shape, 'i m, 'a m) Linalg.Intf.vec -> ('i shape, 'i m, unit m) Linalg.Intf.vec k
val zero : 'i shape -> 'i t
Everywhere zero vector.
val basis : 'i shape -> 'i m -> elt m -> 'i t k
basis s i r
is the vector of shapes
everywhere equal to R.zero except at indexi
where it is equal tor
. RaisesOut_of_bounds
ifi
does not belong tos
.
val add : 'i t -> 'i t -> 'i t k
Pointwise addition. Raises
Dimensions_mismatch
if the shape of operands are not equal.
val sub : 'i t -> 'i t -> 'i t k
Pointwise subtraction. Raises
Dimensions_mismatch
if the shape of operands are not equal.
val mul : 'i t -> 'i t -> 'i t k
Pointwise multiplication. Raises
Dimensions_mismatch
if the shape of operands are not equal.
val swap : 'i m -> 'i m -> 'i t -> 'i t k
Swapping of indices. Raises
Out_of_bounds
if given indices are invalid.
val iter : ('i shape, 'i m, unit m) Linalg.Intf.vec -> unit m
iter v
iterates the effectful computation at each index
val reduce : (elt m -> elt m -> elt m) -> elt m -> ('i shape, 'i m, elt m) Linalg.Intf.vec -> elt m
reduce op zero v
folds the binary, associative operatorop
over the elements ofv
with initial valuezero
. Fold ordering is implementation-dependent: consider using commutative operators.
val (:=) : ('i shape, 'i m, 'a m, unit m) Linalg.Intf.ovec -> ('i shape, 'i m, 'a m) Linalg.Intf.vec -> unit m k
Vector assignement.
- raises Dimensions_mismatch
if the size of operands are not equal.
val add_ : 'i out -> 'i t -> 'i t -> unit m k
Pointwise addition, stores result in first operand.
- raises Dimensions_mismatch
if the size of operands are not equal.
val sub_ : 'i out -> 'i t -> 'i t -> unit m k
Pointwise subtraction, stores result in first operand.
- raises Dimensions_mismatch
if the size of operands are not equal.
val mul_ : 'i out -> 'i t -> 'i t -> unit m k
Pointwise multiplication, stores result in first operand.
- raises Dimensions_mismatch
if the size of operands are not equal.
val dot : 'i t -> 'i t -> elt m k
Dot product.
- raises Dimensions_mismatch
if the size of operands are not equal.
module Infix : sig ... end