Commented non-inplace

This commit is contained in:
Anthony Scemama 2020-10-03 15:40:06 +02:00
parent fe7cd2c550
commit 6d37fe69bd
8 changed files with 42 additions and 23 deletions

View File

@ -177,7 +177,7 @@ let to_file ~filename kinetic =
Matrix.dim1 kinetic
in
let kinetic_x = Matrix.to_bigarray kinetic in
let kinetic_x = Matrix.to_bigarray_inplace kinetic in
for j=1 to n do
for i=1 to j do
if (abs_float kinetic_x.{i,j} > cutoff) then

View File

@ -630,7 +630,7 @@ let contracted_class_shell_pairs ?operator ~zero_m ?schwartz_p ?schwartz_q shell
let coef =
Matrix.outer_product (Vector.of_array @@ cq) (Vector.of_array @@ cp)
in
let coefx = Matrix.to_bigarray coef in
let coefx = Matrix.to_bigarray_inplace coef in
let zm_array = Matrix.init_cols np nq (fun i j ->
try

View File

@ -271,7 +271,7 @@ let get_chem_all_ij d ~k ~l =
if k = l then
let result =
Matrix.col d.three_index k
Matrix.col_inplace d.three_index k
|> Vector.to_bigarray_inplace
|> Bigarray.genarray_of_array1
in
@ -284,7 +284,7 @@ let get_chem_all_ij d ~k ~l =
| Dense a ->
let kl = sym_index k l in
let result =
Matrix.col a kl
Matrix.col_inplace a kl
|> Vector.to_bigarray_inplace
|> Bigarray.genarray_of_array1
in

View File

@ -58,17 +58,24 @@ let reshape a m n =
in
Bigarray.reshape_2 b m n
let col_inplace t j =
Mat.col t j
|> Vector.of_bigarray_inplace
(*
let col t j =
Mat.col t j
|> Vector.of_bigarray
*)
let to_col_vecs t =
Mat.to_col_vecs t
|> Array.map Vector.of_bigarray
|> Array.map Vector.of_bigarray_inplace
let to_col_vecs_list t =
Mat.to_col_vecs_list t
|> List.rev_map Vector.of_bigarray
|> List.rev_map Vector.of_bigarray_inplace
|> List.rev
let detri_inplace t =
@ -169,7 +176,7 @@ let diagonalize_symm m_H =
let m_V = lacpy m_H in
let result =
syevd ~vectors:true m_V
|> Vector.of_bigarray
|> Vector.of_bigarray_inplace
in
m_V, result
@ -214,7 +221,7 @@ let debug_matrix name a =
Format.printf "@[%s =\n@[%a@]@]@." name pp a
let outer_product_inplace m ?(alpha=1.0) u v =
ger ~alpha (Vector.to_bigarray u) (Vector.to_bigarray v) m
ger ~alpha (Vector.to_bigarray_inplace u) (Vector.to_bigarray_inplace v) m
let outer_product ?(alpha=1.0) u v =
let m = make0 (Vector.dim u) (Vector.dim v) in
@ -267,12 +274,12 @@ let copy_inplace ?m ?n ?br ?bc ~b ?ar ?ac a =
ignore @@ lacpy ?m ?n ?br ?bc ~b ?ar ?ac a
let scale_cols_inplace a v =
Vector.to_bigarray v
Vector.to_bigarray_inplace v
|> Mat.scal_cols a
let scale_cols a v =
let a' = copy a in
Vector.to_bigarray v
Vector.to_bigarray_inplace v
|> Mat.scal_cols a' ;
a'
@ -281,13 +288,13 @@ let svd a =
let d, u, vt =
gesvd (lacpy a)
in
u, (Vector.of_bigarray d), vt
u, (Vector.of_bigarray_inplace d), vt
let svd_t a =
let svd' a =
let d, u, vt =
gesvd (lacpy a)
in
u, (Vector.of_bigarray d), vt
u, (Vector.of_bigarray_inplace d), vt
let qr a =

View File

@ -68,13 +68,22 @@ val div_inplace : c:('a,'b) t -> ('a,'b) t -> ('a,'b) t -> unit
val at : ('a,'b) t -> int -> int -> float
(** [at i j] returns the element at i,j. *)
(*
val to_bigarray : ('a,'b) t -> (float, Stdlib.Bigarray.float64_elt, Stdlib.Bigarray.fortran_layout) Stdlib.Bigarray.Array2.t
(** Converts the matrix into a Bigarray in Fortran layout *)
val of_bigarray : (float, Stdlib.Bigarray.float64_elt, Stdlib.Bigarray.fortran_layout) Stdlib.Bigarray.Array2.t -> ('a,'b) t
(** Converts a [Bigarray.Array2] in Fortran layout into a matrix *)
*)
val to_bigarray_inplace :
('a,'b) 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 of_bigarray_inplace :
(float, Stdlib.Bigarray.float64_elt, Stdlib.Bigarray.fortran_layout) Stdlib.Bigarray.Array2.t -> ('a,'b) t
(** Converts a [Bigarray.Array2] in Fortran layout into a matrix in place*)
val to_col_vecs : ('a,'b) t -> 'a Vector.t array
(** Converts the matrix into an array of vectors *)
@ -87,21 +96,19 @@ val of_col_vecs : 'a Vector.t array -> ('a,'b) t
val of_col_vecs_list : 'a Vector.t list -> ('a,'b) 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 -> ('a,'b) 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 -> ('a,'b) 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 -> ('a,'b) t -> ('a,'b) 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:('a,'b) t -> ?ar:int -> ?ac:int -> ('a,'b) t -> unit
(** Copies all or part of a two-dimensional matrix A to an existing matrix B *)
(*
val col: ('a,'b) t -> int -> 'a Vector.t
(** Returns a column of the matrix as a vector *)
*)
val col_inplace: ('a,'b) t -> int -> 'a Vector.t
(** Returns a column of the matrix as a vector *)
val detri: ('a,'b) t -> ('a,'b) t
(** Takes an upper-triangular matrix, and makes it a symmetric matrix
@ -218,7 +225,7 @@ val gemm_tt_trace: ('b,'a) t -> ('c,'b) t -> float
val svd: ('a,'b) t -> ('a,'b) t * 'b Vector.t * ('b,'b) t
(** Singular value decomposition of A(m,n) when m >= n. *)
val svd_t: ('a,'b) t -> ('a,'a) t * 'a Vector.t * ('a,'b) t
val svd': ('a,'b) t -> ('a,'a) t * 'a Vector.t * ('a,'b) t
(** Singular value decomposition of A(m,n) when m < n. *)
val qr: ('a,'b) t -> ('a,'b) t * ('b,'b) t

View File

@ -10,7 +10,7 @@ let canonical_ortho ?thresh:(thresh=1.e-6) ~overlap c =
if x >= thresh then 1. /. x
else 0. ) d_sqrt
in
let dx = Vector.to_bigarray d in
let dx = Vector.to_bigarray_inplace d in
if n < Vector.dim d_sqrt then
Printf.printf "Removed linear dependencies below %f\n" (1. /. dx.{n})
;

View File

@ -42,9 +42,12 @@ let to_list t = Vec.to_list t
let make n x = Vec.make n x
let of_bigarray_inplace t = t
(*
let of_bigarray t = copy t
let to_bigarray t = copy t
*)
let of_bigarray_inplace t = t
let to_bigarray_inplace t = t
let random ?rnd_state ?(from= -. 1.0) ?(range=2.0) n =

View File

@ -121,11 +121,13 @@ val random : ?rnd_state:Random.State.t -> ?from:float -> ?range:float -> int ->
%} 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 -> 'a t
(** Builds by converting from a Fortran bigarray *)
val to_bigarray : 'a 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 -> 'a t
(** Builds by converting from a Fortran bigarray *)