mirror of
https://gitlab.com/scemama/QCaml.git
synced 2024-11-14 10:03:39 +01:00
206 lines
6.8 KiB
OCaml
206 lines
6.8 KiB
OCaml
type t
|
|
|
|
val dim1: t -> int
|
|
(** First dimension of the matrix *)
|
|
|
|
val dim2: t -> int
|
|
(** Second dimension of the matrix *)
|
|
|
|
val make : int -> int -> float -> t
|
|
(** Creates a matrix initialized with the given value. *)
|
|
|
|
val make0 : int -> int -> t
|
|
(** Creates a zero-initialized matrix. *)
|
|
|
|
val create : int -> int -> t
|
|
(** Creates an uninitialized matrix. *)
|
|
|
|
val reshape : t -> int -> int -> t
|
|
(** Changes the dimensions of the matrix *)
|
|
|
|
val init_cols : int -> int -> (int -> int -> float) -> t
|
|
(** Creates an uninitialized matrix. *)
|
|
|
|
val identity: int -> t
|
|
(** Creates an identity matrix. *)
|
|
|
|
val fill_inplace: t -> float -> unit
|
|
(** Fills the matrix with the give value. *)
|
|
|
|
val add_const_diag : float -> t -> t
|
|
(** Adds a constant to the diagonal *)
|
|
|
|
val add_const_diag_inplace : float -> t -> unit
|
|
(** Adds a constant to the diagonal *)
|
|
|
|
val add_const_inplace : float -> t -> unit
|
|
(** Adds a constant to the diagonal *)
|
|
|
|
val add_const : float -> t -> t
|
|
(** Adds a constant to the diagonal *)
|
|
|
|
val add : t -> t -> t
|
|
(** Adds two matrices *)
|
|
|
|
val sub : t -> t -> t
|
|
(** Subtracts two matrices *)
|
|
|
|
val mul : t -> t -> t
|
|
(** Multiplies two matrices element-wise *)
|
|
|
|
val div : t -> t -> t
|
|
(** Divides two matrices element-wise *)
|
|
|
|
val add_inplace : c:t -> t -> t -> unit
|
|
(** [add_inplace c a b] : performs [c = a+b] in-place. *)
|
|
|
|
val sub_inplace : c:t -> t -> t -> unit
|
|
(** [sub_inplace c a b] : performs [c = a+b] in-place. *)
|
|
|
|
val mul_inplace : c:t -> t -> t -> unit
|
|
(** [mul_inplace c a b] : performs [c = a*b] element-wise in-place. *)
|
|
|
|
val div_inplace : c:t -> t -> t -> unit
|
|
(** [div_inplace c a b] : performs [c = a/b] element-wise in-place. *)
|
|
|
|
val at : t -> int -> int -> float
|
|
(** [at i j] returns the element at i,j. *)
|
|
|
|
val to_bigarray : t -> (float, Stdlib.Bigarray.float64_elt, Stdlib.Bigarray.fortran_layout) Stdlib.Bigarray.Array2.t
|
|
(** Converts the matrix into a Bigarray in Fortran layout *)
|
|
|
|
val to_bigarray_inplace :
|
|
t -> (float, Stdlib.Bigarray.float64_elt, Stdlib.Bigarray.fortran_layout) Stdlib.Bigarray.Array2.t
|
|
(** Converts the matrix into a Bigarray in Fortran layout in place*)
|
|
|
|
val to_col_vecs : t -> 'a Vector.t array
|
|
(** Converts the matrix into an array of vectors *)
|
|
|
|
val to_col_vecs_list : t -> 'a Vector.t list
|
|
(** Converts the matrix into a list of vectors *)
|
|
|
|
val of_col_vecs : 'a Vector.t array -> t
|
|
(** Converts an array of vectors into a matrix *)
|
|
|
|
val of_col_vecs_list : 'a Vector.t list -> t
|
|
(** Converts a list of vectors into a matrix *)
|
|
|
|
val of_bigarray : (float, Stdlib.Bigarray.float64_elt, Stdlib.Bigarray.fortran_layout) Stdlib.Bigarray.Array2.t -> t
|
|
(** Converts a [Bigarray.Array2] in Fortran layout into a matrix *)
|
|
|
|
val of_bigarray_inplace :
|
|
(float, Stdlib.Bigarray.float64_elt, Stdlib.Bigarray.fortran_layout) Stdlib.Bigarray.Array2.t -> t
|
|
(** Converts a [Bigarray.Array2] in Fortran layout into a matrix in place*)
|
|
|
|
val copy: ?m:int -> ?n:int -> ?br:int -> ?bc:int -> ?ar:int -> ?ac:int -> t -> t
|
|
(** Copies all or part of a two-dimensional matrix A to a new matrix B *)
|
|
|
|
val copy_inplace: ?m:int -> ?n:int -> ?br:int -> ?bc:int -> b:t -> ?ar:int -> ?ac:int -> t -> unit
|
|
(** Copies all or part of a two-dimensional matrix A to an existing matrix B *)
|
|
|
|
val col: t -> int -> 'a Vector.t
|
|
(** Returns a column of the matrix as a vector *)
|
|
|
|
val detri: t -> t
|
|
(** Takes an upper-triangular matrix, and makes it a symmetric matrix
|
|
by mirroring the defined triangle along the diagonal. *)
|
|
|
|
val detri_inplace: t -> unit
|
|
(** Takes an upper-triangular matrix, and makes it a symmetric matrix
|
|
by mirroring the defined triangle along the diagonal. *)
|
|
|
|
val as_vec_inplace: t -> 'a Vector.t
|
|
(** Interpret the matrix as a vector (reshape). *)
|
|
|
|
val as_vec: t -> 'a Vector.t
|
|
(** Return a copy of the reshaped matrix into a vector *)
|
|
|
|
val random: ?rnd_state:Random.State.t -> ?from:float -> ?range:float -> int -> int -> t
|
|
(** Creates a random matrix, similarly to [Vector.random] *)
|
|
|
|
val map: (float -> float) -> t -> t
|
|
(** Apply the function to all elements of the matrix *)
|
|
|
|
val map_inplace: (float -> float) -> b:t -> t -> unit
|
|
(** [map_inplace f b a] : Apply the function to all elements of the
|
|
matrix [a] and store the results in [b] *)
|
|
|
|
val scale: float -> t -> t
|
|
(** Multiplies the matrix by a constant *)
|
|
|
|
val scale_inplace: float -> t -> unit
|
|
(** Multiplies the matrix by a constant *)
|
|
|
|
val scale_cols: t -> 'a Vector.t -> t
|
|
(** Multiplies the matrix by a constant *)
|
|
|
|
val scale_cols_inplace: t -> 'a Vector.t -> unit
|
|
(** Multiplies the matrix by a constant *)
|
|
|
|
val sycon: t -> float
|
|
(** Returns the condition number of a matrix *)
|
|
|
|
val outer_product : ?alpha:float -> 'a Vector.t -> 'b Vector.t -> t
|
|
(** Computes M = %{ $\alpha u.v^t$ %} *)
|
|
|
|
val outer_product_inplace : t -> ?alpha:float -> 'a Vector.t -> 'b Vector.t -> unit
|
|
(** Computes M = %{ $\alpha u.v^t$ %} *)
|
|
|
|
val gemm_inplace : ?m:int -> ?n:int -> ?k:int -> ?beta:float -> c:t -> ?transa:[`N | `T] -> ?alpha:float ->
|
|
t -> ?transb:[`N | `T] -> t -> unit
|
|
(** Performs the Lapack GEMM operation. Default values:
|
|
[beta=0.] [transa=`N] [alpha=1.0] [transb=`N].
|
|
[gemm ~beta c ~alpha a b]: %{ $C = \beta C + \alpha A B$ *)
|
|
|
|
val gemm: ?m:int -> ?n:int -> ?k:int -> ?beta:float -> ?c:t -> ?transa:[`N | `T] -> ?alpha:float ->
|
|
t -> ?transb:[`N | `T] -> t -> t
|
|
(** Performs the Lapack GEMM operation. Default values:
|
|
[beta=0.] [transa=`N] [alpha=1.0] [transb=`N]
|
|
[gemm ~beta ~alpha a b]: %{ $C = \beta C + \alpha A B$ *)
|
|
|
|
val gemm_trace: ?transa:[`N | `T] -> t -> ?transb:[`N | `T] -> t -> float
|
|
(** Computes the trace of a GEMM. Default values:
|
|
[transa=`N] [transb=`N]
|
|
[gemm_trace a b]: %{ $C = Tr(A B)$ *)
|
|
|
|
val svd: t -> t * 'b Vector.t * t
|
|
(** Singular value decomposition. *)
|
|
|
|
val qr: t -> t * t
|
|
(** QR factorization *)
|
|
|
|
val normalize_mat : t -> t
|
|
(** Returns the matrix with all the column vectors normalized *)
|
|
|
|
val normalize_mat_inplace : t -> unit
|
|
(** Returns the matrix with all the column vectors normalized *)
|
|
|
|
val diagonalize_symm : t -> t * 'a Vector.t
|
|
(** Diagonalize a symmetric matrix. Returns the eigenvectors and the eigenvalues. *)
|
|
|
|
val xt_o_x : o:t -> x:t -> t
|
|
(** Computes {% $\mathbf{X^\dag\, O\, X}$ %} *)
|
|
|
|
val x_o_xt : o:t -> x:t -> t
|
|
(** Computes {% $\mathbf{X\, O\, X^\dag}$ %} *)
|
|
|
|
val debug_matrix: string -> t -> unit
|
|
(** Prints a matrix in stdout for debug *)
|
|
|
|
val matrix_of_file : string -> t
|
|
(** Reads a matrix from a file with format "%d %d %f" corresponding to
|
|
[i, j, A.{i,j}]. *)
|
|
|
|
val sym_matrix_of_file : string -> t
|
|
(** Reads a symmetric matrix from a file with format "%d %d %f" corresponding to
|
|
[i, j, A.{i,j}]. *)
|
|
|
|
val sysv_inplace : b:t -> t -> unit
|
|
(** Solves %{ $AX=B$ %} when A is symmetric, and stores the result in B. *)
|
|
|
|
val sysv : b:t -> t -> t
|
|
(** Solves %{ $AX=B$ %} when A is symmetric *)
|
|
|
|
val pp : Format.formatter -> t -> unit
|
|
|