10
1
mirror of https://gitlab.com/scemama/QCaml.git synced 2024-11-18 20:12:26 +01:00
QCaml/linear_algebra/lib/vector.mli
2020-09-26 12:02:53 +02:00

129 lines
3.7 KiB
OCaml

(** Vector module
This module encapsulates the [Vec] module of Lacaml, to facilitate the change of backend
in the future, or to easily implement distributed vectors.
The indexing of vectors is 1-based.
*)
open Lacaml.D
type t = Vec.t
val dim : t -> int
(** Returns the dimension of the vector *)
val add : t -> t -> t
(** [c = add a b] : %{ $c = a + b$ %} *)
val sub : t -> t -> t
(** [c = sub a b] : %{ $c = a - b$ %} *)
val mul : t -> t -> t
(** [c = mul a b] : %{ $c_i = a_i \times b_i$ %} *)
val div : t -> t -> t
(** [c = div a b] : %{ $c_i = a_i / b_i$ %} *)
val dot : t -> t -> float
(** [dot v1 v2] : Dot product between v1 and v2 *)
val norm : t -> float
(** Norm of the vector : %{ ||v|| = $\sqrt{v.v}$ %} *)
val sqr : t -> t
(** [sqr t = map (fun x -> x *. x) t] *)
val sqrt : t -> t
(** [sqrt t = map sqrt t] *)
val neg : t -> t
(** [neg t = map (f x -> -. x) t *)
val reci : t -> t
(** [reci t = map (f x -> 1./x) t *)
val abs : t -> t
(** [abs t = map (f x -> abs_float x) t *)
val cos : t -> t
(** [cos t = map (f x -> cos x) t *)
val sin : t -> t
(** [sin t = map (f x -> sin x) t *)
val tan : t -> t
(** [tan t = map (f x -> tan x) t *)
val acos : t -> t
(** [acos t = map (f x -> acos x) t *)
val asin : t -> t
(** [asin t = map (f x -> asin x) t *)
val atan : t -> t
(** [atan t = map (f x -> atan x) t *)
val normalize : t -> t
(** Returns the vector normalized *)
val init : int -> (int -> float) -> t
(** Initialized the vector with a function taking the index as parameter.*)
val sum : t -> float
(** Returns the sum of the elements of the vector *)
val copy : ?n:int -> ?ofsy:int -> ?incy:int -> ?y:vec -> ?ofsx:int -> ?incx:int -> t -> t
(** Returns a copy of the vector X into Y. [ofs] controls the offset and [inc]
the increment. *)
val map : (float -> float) -> t -> t
(** Equivalent to [Array.map] *)
val iter : (float -> unit) -> t -> unit
(** Equivalent to [Array.iter] *)
val iteri : (int -> float -> unit) -> t -> unit
(** Equivalent to [Array.iteri] *)
val of_array : float array -> t
(** Converts an array of floats into a vector *)
val of_list : float list -> t
(** Converts a list of floats into a vector *)
val to_array : t -> float array
(** Converts to an array of floats *)
val to_list : t -> float list
(** Converts to a list of floats *)
val create : int -> t
(** Creates an uninitialized vector *)
val make : int -> float -> t
(** Creates a vector initialized with the given [float].*)
val make0 : int -> t
(** Creates a zero-initialized vector.*)
val fold : ('a -> float -> 'a) -> 'a -> t -> 'a
(** Equivalent to [Array.fold] *)
val random : ?rnd_state:Random.State.t -> ?from:float -> ?range:float -> int -> t
(** Returns a vector of uniform random numbers %{ $ f \le u \le f+r $
%} where [f] is [from] and [r] is [range].
Default values: [from:-1.0] [range:2.0] *)
val of_bigarray : (float, Stdlib.Bigarray.float64_elt, Stdlib.Bigarray.fortran_layout) Stdlib.Bigarray.Array1.t -> t
(** Builds by converting from a Fortran bigarray *)
val to_bigarray : t -> (float, Stdlib.Bigarray.float64_elt, Stdlib.Bigarray.fortran_layout) Stdlib.Bigarray.Array1.t
(** Converts the vector into a Fortran bigarray *)
val of_bigarray_inplace : (float, Stdlib.Bigarray.float64_elt, Stdlib.Bigarray.fortran_layout) Stdlib.Bigarray.Array1.t -> t
(** Builds by converting from a Fortran bigarray *)
val to_bigarray_inplace : t -> (float, Stdlib.Bigarray.float64_elt, Stdlib.Bigarray.fortran_layout) Stdlib.Bigarray.Array1.t
(** Converts the vector into a Fortran bigarray *)