mirror of
https://gitlab.com/scemama/QCaml.git
synced 2024-08-30 00:03:42 +02:00
--amend
This commit is contained in:
parent
08e41378dd
commit
35e63bf4fc
30
Utils/Conventions.ml
Normal file
30
Utils/Conventions.ml
Normal file
@ -0,0 +1,30 @@
|
||||
(** Contains the conventions relative to the program.
|
||||
|
||||
The phase convention is given by:
|
||||
{% $\sum_i c_i > 0$ %} or {% $\min_i c_i \ge 0$ %}
|
||||
|
||||
*)
|
||||
|
||||
open Lacaml.D
|
||||
|
||||
let in_phase vec =
|
||||
let s = Vec.sum vec in
|
||||
if s = 0. then
|
||||
let rec first_non_zero k =
|
||||
if k > Vec.dim vec then
|
||||
k-1
|
||||
else if vec.{k} = 0. then
|
||||
first_non_zero (k+1)
|
||||
else k
|
||||
in
|
||||
let k = first_non_zero 1 in
|
||||
vec.{k} >= 0.
|
||||
else
|
||||
s > 0.
|
||||
|
||||
|
||||
let rephase mat =
|
||||
Mat.to_col_vecs mat
|
||||
|> Array.map (fun v -> if in_phase v then v else Vec.neg v)
|
||||
|> Mat.of_col_vecs
|
||||
|
16
Utils/Conventions.mli
Normal file
16
Utils/Conventions.mli
Normal file
@ -0,0 +1,16 @@
|
||||
(** Contains the conventions relative to the program.
|
||||
|
||||
The phase convention is given by:
|
||||
{% $\sum_i c_i > 0$ %} or {% $\min_i c_i \ge 0$ %}
|
||||
|
||||
*)
|
||||
|
||||
open Lacaml.D
|
||||
|
||||
|
||||
val in_phase : Vec.t -> bool
|
||||
(** Checks if one MO respects the phase convention *)
|
||||
|
||||
val rephase : Mat.t -> Mat.t
|
||||
(** Apply the phase convention to the MOs. *)
|
||||
|
Loading…
Reference in New Issue
Block a user