10
1
mirror of https://gitlab.com/scemama/QCaml.git synced 2024-12-22 12:23:31 +01:00

Less allocations

This commit is contained in:
Anthony Scemama 2018-02-10 22:19:13 +01:00
parent 943dfa9935
commit 346db83439

View File

@ -24,9 +24,8 @@ let hvrr_two_e_vector (angMom_a, angMom_b, angMom_c, angMom_d)
map_1d map_2d np nq map_1d map_2d np nq
= =
let empty = let empty = Array.make nq 0. in
Array.make nq 0. let tmp_1 = Array.make nq 0. in
in
let totAngMom_a = Angular_momentum.to_int totAngMom_a let totAngMom_a = Angular_momentum.to_int totAngMom_a
@ -54,8 +53,10 @@ let hvrr_two_e_vector (angMom_a, angMom_b, angMom_c, angMom_d)
if amxyz < 0 then if amxyz < 0 then
None None
else else
begin
let cab = Coordinate.coord center_ab xyz in
let v1_top, p1_top = let v1_top, p1_top =
if abs_float (Coordinate.coord center_ab xyz) < cutoff then if abs_float cab < cutoff then
None, None,
vrr0_v (m+1) am (totAngMom_a-1) vrr0_v (m+1) am (totAngMom_a-1)
else else
@ -68,27 +69,36 @@ let hvrr_two_e_vector (angMom_a, angMom_b, angMom_c, angMom_d)
vrr0_v (m+1) amm (totAngMom_a-2) vrr0_v (m+1) amm (totAngMom_a-2)
in in
Some ( let result = Array.make_matrix np nq 0. in
Array.init np (fun l -> for l=0 to np-1
let v1 = do
let f = let p0 =
-. expo_b.(l) *. expo_inv_p.(l) *. (Coordinate.coord center_ab xyz)
in
match v1_top with
| Some v1_top ->
v1_top.(l) |> Array.map (fun x -> f *. x)
| None -> empty
in
let p1 =
match p1_top with match p1_top with
| Some p1_top -> p1_top.(l) | Some p1_top -> p1_top.(l)
| _ -> assert false | _ -> assert false
in in
let p1 = let f0 =
Array.init nq (fun k -> -. expo_b.(l) *. expo_inv_p.(l) *. cab
v1.(k) +. expo_inv_p.(l) *. center_pq.(xyz).(l).(k) *. p1.(k))
in in
if amxyz < 1 then p1 else let v0 =
match v1_top with
| Some v1_top -> v1_top.(l)
| None -> empty
in
for k=0 to nq-1
do
tmp_1.(k) <- v0.(k) *. f0
done;
let v0 = tmp_1 in
if amxyz < 1 then
begin
for k=0 to nq-1
do
result.(l).(k) <- v0.(k) +. expo_inv_p.(l) *. center_pq.(xyz).(l).(k) *. p0.(k)
done
end
else
begin
let f = (float_of_int amxyz) *. expo_inv_p.(l) *. 0.5 let f = (float_of_int amxyz) *. expo_inv_p.(l) *. 0.5
in in
let v1 = let v1 =
@ -101,11 +111,19 @@ let hvrr_two_e_vector (angMom_a, angMom_b, angMom_c, angMom_d)
| Some p1_top2 -> p1_top2.(l) | Some p1_top2 -> p1_top2.(l)
| None -> assert false | None -> assert false
in in
Array.init nq (fun k -> for k=0 to nq-1
p1.(k) +. f *. (v1.(k) +. v2.(k) *. expo_inv_p.(l) ) ) do
) result.(l).(k) <-
) v0.(k)
in Zmap.add map_1d.(m) key result; +. expo_inv_p.(l) *. center_pq.(xyz).(l).(k) *. p0.(k)
+. f *. (v1.(k) +. v2.(k) *. expo_inv_p.(l) )
done
end
done;
Some result
end
in
Zmap.add map_1d.(m) key result;
result result
and vrr_v m angMom_a angMom_c totAngMom_a totAngMom_c = and vrr_v m angMom_a angMom_c totAngMom_a totAngMom_c =
@ -140,6 +158,9 @@ let hvrr_two_e_vector (angMom_a, angMom_b, angMom_c, angMom_d)
(acx-2,acy,acz), (acx-2,acy,acz),
aax,acx, 0 aax,acx, 0
in in
(*
let result = Array.make_matrix np nq 0. in
*)
let f1 = let f1 =
let f = (Coordinate.coord center_cd xyz) in let f = (Coordinate.coord center_cd xyz) in
Array.init nq (fun k -> expo_d.(k) *. expo_inv_q.(k) *. f) Array.init nq (fun k -> expo_d.(k) *. expo_inv_q.(k) *. f)
@ -484,9 +505,13 @@ let contracted_class_shell_pairs ~zero_m ?schwartz_p ?schwartz_q shell_p shell_q
Array.init (maxm+1) (fun _ -> Array.init (maxm+1) (fun _ ->
Array.init np (fun _ -> Array.make nq 0. ) ) Array.init np (fun _ -> Array.make nq 0. ) )
in in
let empty = Array.make (maxm+1) 0. in
Array.iteri (fun ab shell_ab -> Array.iteri (fun ab shell_ab ->
let zero_m_array_tmp = let zero_m_array_tmp =
Array.mapi (fun cd shell_cd -> Array.mapi (fun cd shell_cd ->
if (abs_float coef.(ab).(cd) < cutoff) then
empty
else
let expo_pq_inv = let expo_pq_inv =
expo_inv_p.(ab) +. expo_inv_q.(cd) expo_inv_p.(ab) +. expo_inv_q.(cd)
in in