2019-02-28 12:08:28 +01:00
|
|
|
(* Sparse or dense matrices *)
|
|
|
|
|
|
|
|
open Lacaml.D
|
|
|
|
|
|
|
|
type t
|
|
|
|
|
|
|
|
(** {1 Accessors} *)
|
|
|
|
|
|
|
|
val is_sparse : t -> bool
|
|
|
|
(** True is the matrix is sparse. *)
|
|
|
|
|
|
|
|
val is_dense : t -> bool
|
|
|
|
(** True is the matrix is dense. *)
|
|
|
|
|
|
|
|
val dim1 : t -> int
|
|
|
|
(** First dimension of the matrix *)
|
|
|
|
|
|
|
|
val dim2 : t -> int
|
|
|
|
(** Secons dimension of the matrix *)
|
|
|
|
|
|
|
|
val get : t -> int -> int -> float
|
|
|
|
(** [get m i j] returns {% $\mathbf{m}_{ij}$ %}. *)
|
|
|
|
|
|
|
|
|
|
|
|
(** {1 Converters } *)
|
|
|
|
|
|
|
|
val to_mat : t -> Mat.t
|
|
|
|
(** Convert into a Lacaml Mat. *)
|
|
|
|
|
2019-02-28 12:30:20 +01:00
|
|
|
val to_vector_array : ?threshold:float -> t -> Vector.t array
|
2019-02-28 12:08:28 +01:00
|
|
|
(** Convert the matrix into an array of column vectors. *)
|
|
|
|
|
|
|
|
val sparse_of_dense : ?threshold:float -> t -> t
|
|
|
|
(** Creates a sparse matrix from a dense matrix. Default threshold is {!Constants.epsilon}. *)
|
|
|
|
|
|
|
|
val dense_of_sparse : t -> t
|
|
|
|
(** Creates a dense matrix from a sparse matrix. *)
|
|
|
|
|
|
|
|
val dense_of_mat : Mat.t -> t
|
|
|
|
(** Create a dense matrix from a Lacaml Mat *)
|
|
|
|
|
|
|
|
val sparse_of_mat : ?threshold:float -> Lacaml.D.Mat.t -> t
|
|
|
|
(** Create a sparse matrix from a Lacaml Mat. Default threshold is {!Constants.epsilon}. *)
|
|
|
|
|
|
|
|
val sparse_of_vector_array : Vector.t array -> t
|
|
|
|
(** Create a sparse matrix from an array of column vectors. *)
|
|
|
|
|
|
|
|
val transpose : t -> t
|
|
|
|
(** Returns the transposed matrix. *)
|
|
|
|
|
|
|
|
|
|
|
|
(** {1 Operations} *)
|
|
|
|
|
|
|
|
val outer_product : ?threshold:float -> Vector.t -> Vector.t -> t
|
|
|
|
(** Creates the matrix formed by the outer product of two vectors. *)
|
|
|
|
|
|
|
|
val mm : ?transa:trans3 -> ?transb:trans3 -> ?threshold:float -> t -> t -> t
|
|
|
|
(** Matrix multiplication *)
|
|
|
|
|
|
|
|
val mv : ?sparse:bool -> ?trans:trans3 -> ?threshold:float -> t -> Vector.t -> Vector.t
|
|
|
|
(** Matrix Vector product *)
|
|
|
|
|
2019-03-21 11:02:58 +01:00
|
|
|
val ax_eq_b : ?trans:trans3 -> t -> t -> t
|
|
|
|
(** Solves A.X = B or A'.X = B *)
|
|
|
|
|
2019-02-28 12:08:28 +01:00
|
|
|
|
|
|
|
(** {1 Printers } *)
|
|
|
|
|
|
|
|
val pp_matrix : Format.formatter -> t -> unit
|
|
|
|
|
|
|
|
|
|
|
|
(** {1 Unit testing} *)
|
|
|
|
|
|
|
|
val test_case : unit -> (string * [> `Quick ] * (unit -> unit)) list
|