mirror of
https://gitlab.com/scemama/QCaml.git
synced 2024-08-28 23:42:00 +02:00
Added exponential of matrix
This commit is contained in:
parent
b7add6b2b6
commit
3c27ec0c10
@ -382,7 +382,24 @@ let qr a =
|
||||
q, r
|
||||
|
||||
|
||||
let (%:) t (i,j) = t.{i,j}
|
||||
let exponential a =
|
||||
assert (dim1 a = dim2 a);
|
||||
let a = to_bigarray_inplace a in
|
||||
let n = Mat.dim1 a in
|
||||
let a2 = Lacaml.D.gemm a a in
|
||||
let (lv, wr, _wi, rv) = Lacaml.D.geev a2 in
|
||||
let tau = Vec.map (fun x -> -. sqrt x) wr in
|
||||
let cos_tau =
|
||||
Mat.init_cols n n (fun i j ->
|
||||
if i<>j then 0. else cos tau.{i})
|
||||
in
|
||||
let sin_tau =
|
||||
Mat.init_cols n n (fun i j ->
|
||||
if i<>j then 0. else (sin tau.{i}) /. tau.{i})
|
||||
in
|
||||
let g = Lacaml.D.gemm in
|
||||
Mat.add (g lv @@ g cos_tau rv) (g lv @@ g sin_tau @@ g rv a)
|
||||
|> of_bigarray_inplace
|
||||
|
||||
|
||||
let to_file ~filename ?(sym=false) ?(cutoff=0.) t =
|
||||
@ -411,6 +428,7 @@ let to_file ~filename ?(sym=false) ?(cutoff=0.) t =
|
||||
|
||||
|
||||
|
||||
let (%:) t (i,j) = t.{i,j}
|
||||
|
||||
let set t i j v = t.{i,j} <- v
|
||||
|
||||
|
@ -279,7 +279,6 @@ val gemm_tn_trace: ('b,'a) t -> ('b,'c) t -> float
|
||||
val gemm_tt_trace: ('b,'a) t -> ('c,'b) t -> float
|
||||
(** Computes the trace of a GEMM with [~transa=`T] and [~transb=`T]. *)
|
||||
|
||||
|
||||
val svd: ('a,'b) t -> ('a,'b) t * 'b Vector.t * ('b,'b) t
|
||||
(** Singular value decomposition of A(m,n) when m >= n. *)
|
||||
|
||||
@ -298,6 +297,9 @@ val normalize_mat_inplace : ('a,'b) t -> unit
|
||||
val diagonalize_symm : ('a,'a) t -> ('a,'a) t * 'a Vector.t
|
||||
(** Diagonalize a symmetric matrix. Returns the eigenvectors and the eigenvalues. *)
|
||||
|
||||
val exponential : ('a,'a) t -> ('a,'a) t
|
||||
(** Computes the exponential of a square matrix. *)
|
||||
|
||||
val xt_o_x : o:('a,'a) t -> x:('a,'b) t -> ('b,'b) t
|
||||
(** Computes {% $\mathbf{X^\dag\, O\, X}$ %} *)
|
||||
|
||||
|
@ -109,6 +109,7 @@ let values t point =
|
||||
let a = Ao.Basis.values (Simulation.ao_basis t.simulation) point in
|
||||
Matrix.gemv_t c a
|
||||
|
||||
|
||||
let of_hartree_fock hf =
|
||||
let mo_coef = HF.eigenvectors hf in
|
||||
let simulation = HF.simulation hf in
|
||||
|
Loading…
Reference in New Issue
Block a user