10
1
mirror of https://gitlab.com/scemama/QCaml.git synced 2024-12-23 12:53:46 +01:00
QCaml/linear_algebra/lib/vector.mli

145 lines
4.1 KiB
OCaml
Raw Normal View History

2020-09-26 12:02:53 +02:00
(** 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.
*)
2020-10-02 14:43:58 +02:00
open Lacaml.D
2020-09-26 12:02:53 +02:00
2020-10-02 15:49:09 +02:00
type 'a t
2020-10-02 14:43:58 +02:00
(* Parameter ['a] defines the basis on which the vector is expanded. *)
2020-09-26 12:02:53 +02:00
2020-10-02 18:55:19 +02:00
val relabel : 'a t -> 'b t
2020-10-02 14:43:58 +02:00
val dim : 'a t -> int
2020-09-26 12:02:53 +02:00
(** Returns the dimension of the vector *)
2020-10-02 14:43:58 +02:00
val add : 'a t -> 'a t -> 'a t
2020-09-26 12:02:53 +02:00
(** [c = add a b] : %{ $c = a + b$ %} *)
2020-10-02 14:43:58 +02:00
val sub : 'a t -> 'a t -> 'a t
2020-09-26 12:02:53 +02:00
(** [c = sub a b] : %{ $c = a - b$ %} *)
2020-10-02 14:43:58 +02:00
val mul : 'a t -> 'a t -> 'a t
2020-09-26 12:02:53 +02:00
(** [c = mul a b] : %{ $c_i = a_i \times b_i$ %} *)
2020-10-02 14:43:58 +02:00
val div : 'a t -> 'a t -> 'a t
2020-09-26 12:02:53 +02:00
(** [c = div a b] : %{ $c_i = a_i / b_i$ %} *)
2020-10-02 14:43:58 +02:00
val dot : 'a t -> 'a t -> float
2020-09-26 12:02:53 +02:00
(** [dot v1 v2] : Dot product between v1 and v2 *)
2020-10-02 14:43:58 +02:00
val norm : 'a t -> float
2020-09-26 12:02:53 +02:00
(** Norm of the vector : %{ ||v|| = $\sqrt{v.v}$ %} *)
2020-10-02 14:43:58 +02:00
val sqr : 'a t -> 'a t
2020-09-26 12:02:53 +02:00
(** [sqr t = map (fun x -> x *. x) t] *)
2020-10-02 14:43:58 +02:00
val sqrt : 'a t -> 'a t
2020-09-26 12:02:53 +02:00
(** [sqrt t = map sqrt t] *)
2020-10-02 14:43:58 +02:00
val neg : 'a t -> 'a t
2020-09-26 12:02:53 +02:00
(** [neg t = map (f x -> -. x) t *)
2020-10-02 14:43:58 +02:00
val reci : 'a t -> 'a t
2020-09-26 12:02:53 +02:00
(** [reci t = map (f x -> 1./x) t *)
2020-10-02 14:43:58 +02:00
val abs : 'a t -> 'a t
2020-09-26 12:02:53 +02:00
(** [abs t = map (f x -> abs_float x) t *)
2020-10-02 14:43:58 +02:00
val cos : 'a t -> 'a t
2020-09-26 12:02:53 +02:00
(** [cos t = map (f x -> cos x) t *)
2020-10-02 14:43:58 +02:00
val sin : 'a t -> 'a t
2020-09-26 12:02:53 +02:00
(** [sin t = map (f x -> sin x) t *)
2020-10-02 14:43:58 +02:00
val tan : 'a t -> 'a t
2020-09-26 12:02:53 +02:00
(** [tan t = map (f x -> tan x) t *)
2020-10-02 14:43:58 +02:00
val acos : 'a t -> 'a t
2020-09-26 12:02:53 +02:00
(** [acos t = map (f x -> acos x) t *)
2020-10-02 14:43:58 +02:00
val asin : 'a t -> 'a t
2020-09-26 12:02:53 +02:00
(** [asin t = map (f x -> asin x) t *)
2020-10-02 14:43:58 +02:00
val atan : 'a t -> 'a t
2020-09-26 12:02:53 +02:00
(** [atan t = map (f x -> atan x) t *)
2020-10-18 01:58:22 +02:00
val amax : 'a t -> float
(** Maximum of the absolute values of the elements of the vector. *)
2020-10-02 14:43:58 +02:00
val normalize : 'a t -> 'a t
2020-09-26 12:02:53 +02:00
(** Returns the vector normalized *)
2020-10-02 14:43:58 +02:00
val init : int -> (int -> float) -> 'a t
(** Initialize the vector with a function taking the index as parameter.*)
2020-09-26 12:02:53 +02:00
2020-10-02 14:43:58 +02:00
val sum : 'a t -> float
2020-09-26 12:02:53 +02:00
(** Returns the sum of the elements of the vector *)
2020-10-02 14:43:58 +02:00
val copy : ?n:int -> ?ofsy:int -> ?incy:int -> ?y:vec -> ?ofsx:int -> ?incx:int -> 'a t -> 'a t
2020-09-26 12:02:53 +02:00
(** Returns a copy of the vector X into Y. [ofs] controls the offset and [inc]
the increment. *)
2020-10-02 14:43:58 +02:00
val map : (float -> float) -> 'a t -> 'a t
2020-09-26 12:02:53 +02:00
(** Equivalent to [Array.map] *)
2020-10-02 14:43:58 +02:00
val iter : (float -> unit) -> 'a t -> unit
2020-09-26 12:02:53 +02:00
(** Equivalent to [Array.iter] *)
2020-10-02 14:43:58 +02:00
val iteri : (int -> float -> unit) -> 'a t -> unit
2020-09-26 12:02:53 +02:00
(** Equivalent to [Array.iteri] *)
2020-10-02 14:43:58 +02:00
val of_array : float array -> 'a t
2020-09-26 12:02:53 +02:00
(** Converts an array of floats into a vector *)
2020-10-02 14:43:58 +02:00
val of_list : float list -> 'a t
2020-09-26 12:02:53 +02:00
(** Converts a list of floats into a vector *)
2020-10-02 14:43:58 +02:00
val to_array : 'a t -> float array
2020-09-26 12:02:53 +02:00
(** Converts to an array of floats *)
2020-10-02 14:43:58 +02:00
val to_list : 'a t -> float list
2020-09-26 12:02:53 +02:00
(** Converts to a list of floats *)
2020-10-02 14:43:58 +02:00
val create : int -> 'a t
2020-09-26 12:02:53 +02:00
(** Creates an uninitialized vector *)
2020-10-02 14:43:58 +02:00
val make : int -> float -> 'a t
2020-09-26 12:02:53 +02:00
(** Creates a vector initialized with the given [float].*)
2020-10-02 14:43:58 +02:00
val make0 : int -> 'a t
2020-09-26 12:02:53 +02:00
(** Creates a zero-initialized vector.*)
2020-10-02 18:55:19 +02:00
val fold : ('a -> float -> 'a) -> 'a -> 'b t -> 'a
2020-09-26 12:02:53 +02:00
(** Equivalent to [Array.fold] *)
2020-10-02 14:43:58 +02:00
val random : ?rnd_state:Random.State.t -> ?from:float -> ?range:float -> int -> 'a t
2020-09-26 12:02:53 +02:00
(** 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] *)
2020-10-03 15:40:06 +02:00
(*
2020-10-02 14:43:58 +02:00
val of_bigarray : (float, Stdlib.Bigarray.float64_elt, Stdlib.Bigarray.fortran_layout) Stdlib.Bigarray.Array1.t -> 'a t
2020-09-26 12:02:53 +02:00
(** Builds by converting from a Fortran bigarray *)
2020-10-02 14:43:58 +02:00
val to_bigarray : 'a t -> (float, Stdlib.Bigarray.float64_elt, Stdlib.Bigarray.fortran_layout) Stdlib.Bigarray.Array1.t
2020-09-26 12:02:53 +02:00
(** Converts the vector into a Fortran bigarray *)
2020-10-03 15:40:06 +02:00
*)
2020-09-26 12:02:53 +02:00
2020-10-02 14:43:58 +02:00
val of_bigarray_inplace : (float, Stdlib.Bigarray.float64_elt, Stdlib.Bigarray.fortran_layout) Stdlib.Bigarray.Array1.t -> 'a t
2020-09-26 12:02:53 +02:00
(** Builds by converting from a Fortran bigarray *)
2020-10-02 14:43:58 +02:00
val to_bigarray_inplace : 'a t -> (float, Stdlib.Bigarray.float64_elt, Stdlib.Bigarray.fortran_layout) Stdlib.Bigarray.Array1.t
2020-09-26 12:02:53 +02:00
(** Converts the vector into a Fortran bigarray *)
val (%.) : 'a t -> int -> float
(** [t%.(i)] Returns the i-th element of the vector *)
val set : 'a t -> int -> float -> unit
(** Modifies the value in-place at the i-th position *)