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

Changed List.map to List.rev_map

This commit is contained in:
Anthony Scemama 2020-04-15 14:40:33 +02:00
parent 81a329dbfb
commit 5deb4bef6b
10 changed files with 46 additions and 33 deletions

View File

@ -127,12 +127,11 @@ let update_raw_data ?(locked=true) () =
with with
| End_of_file -> List.rev accu | End_of_file -> List.rev accu
in in
List.map (fun filename -> List.concat_map (fun filename ->
let ic = open_in filename in let ic = open_in filename in
let result = aux ic [] in let result = aux ic [] in
close_in ic; close_in ic;
result ) files result ) files
|> List.concat
|> transform [] |> transform []
in in
result result

View File

@ -840,7 +840,8 @@ end = struct
let read () = let read () =
List.map (fun x -> (x, Property.calc x)) Property.all List.rev_map (fun x -> (x, Property.calc x)) Property.all
|> List.rev
let write l = let write l =
@ -848,17 +849,18 @@ end = struct
let to_string l = let to_string l =
List.map (fun (x,b) -> List.rev_map (fun (x,b) ->
let ch = let ch =
if b then "X" else " " if b then "X" else " "
in in
Printf.sprintf "(%s) %s" ch (Property.to_string x)) l Printf.sprintf "(%s) %s" ch (Property.to_string x)) l
|> List.rev
|> String.concat "\n" |> String.concat "\n"
let of_string s = let of_string s =
String.split_on_char '\n' s String.split_on_char '\n' s
|> List.map (fun x -> |> List.rev_map (fun x ->
let (calc,prop) = let (calc,prop) =
String.trim x String.trim x
|> String_ext.rsplit2_exn ~on:' ' |> String_ext.rsplit2_exn ~on:' '
@ -874,6 +876,7 @@ end = struct
in in
(prop, calc) (prop, calc)
) )
|> List.rev
end end

View File

@ -56,7 +56,8 @@ let create m =
| (0,tail) -> | (0,tail) ->
let result = let result =
List.rev accu List.rev accu
|> List.map float_of_string |> List.rev_map float_of_string
|> List.rev
|> Array.of_list |> Array.of_list
in in
(result, tail) (result, tail)

View File

@ -111,8 +111,8 @@ let hash () =
in in
let md5_string = let md5_string =
files_to_track files_to_track
|> List.map (fun x -> Printf.sprintf "%s/%s" ezfio_filename x) |> List.rev_map (fun x -> Printf.sprintf "%s/%s" ezfio_filename x)
|> List.map hash_file |> List.rev_map hash_file
|> String.concat "" |> String.concat ""
in in

View File

@ -231,7 +231,8 @@ let run ?(daemon=true) ezfio_filename =
Array.map Array.to_list walkers_array Array.map Array.to_list walkers_array
|> Array.to_list |> Array.to_list
|> List.concat |> List.concat
|> List.map float_of_string |> List.rev_map float_of_string
|> List.rev
in in
Ezfio.set_electrons_elec_coord_pool (Ezfio.ezfio_array_of_list Ezfio.set_electrons_elec_coord_pool (Ezfio.ezfio_array_of_list
~rank:3 ~dim:[| elec_num+1 ; 3 ; walk_num_tot |] ~data:walkers_list); ~rank:3 ~dim:[| elec_num+1 ; 3 ; walk_num_tot |] ~data:walkers_list);
@ -631,7 +632,8 @@ let run ?(daemon=true) ezfio_filename =
Unix.gettimeofday () Unix.gettimeofday ()
in in
let msg = let msg =
List.map String.trim raw_msg List.rev_map String.trim raw_msg
|> List.rev
|> Message.create |> Message.create
and msg_size = and msg_size =
List.fold_left (fun accu x -> accu + (String.length x)) 0 raw_msg List.fold_left (fun accu x -> accu + (String.length x)) 0 raw_msg
@ -716,7 +718,8 @@ let run ?(daemon=true) ezfio_filename =
Unix.gettimeofday () Unix.gettimeofday ()
in in
let msg = let msg =
List.map String.trim raw_msg List.rev_map String.trim raw_msg
|> List.rev
|> Message.create |> Message.create
and msg_size = and msg_size =
List.fold_left (fun accu x -> accu + (String.length x)) 0 raw_msg List.fold_left (fun accu x -> accu + (String.length x)) 0 raw_msg

View File

@ -83,7 +83,7 @@ let create_temp_file ?temp_filename ezfio_filename fields =
| Some name -> name | Some name -> name
in in
let out_channel = open_out filename in let out_channel = open_out filename in
(file_header ezfio_filename) :: (List.map get fields) (file_header ezfio_filename) :: (List.rev @@ List.rev_map get fields)
|> String.concat "\n" |> String.concat "\n"
|> output_string out_channel |> output_string out_channel
; close_out out_channel ; close_out out_channel
@ -210,10 +210,11 @@ let run ~c ?f ?t ?l ?m ?e ?et ?s ?ts ?w ?wt ?n ?j ?p ?input ezfio_filename =
in in
let data = let data =
( List.filter (fun x -> Str.string_match re_data x 0) raw_data ( List.filter (fun x -> Str.string_match re_data x 0) raw_data
|> List.map String.trim ) @ |> List.rev_map String.trim |> List.rev ) @
[ [
List.filter (fun x -> Str.string_match re_prop x 0) raw_data List.filter (fun x -> Str.string_match re_prop x 0) raw_data
|> List.map String.trim |> List.rev_map String.trim
|> List.rev
|> String.concat "\n" ] |> String.concat "\n" ]
in in
let open Input in let open Input in

View File

@ -309,7 +309,7 @@ let run ezfio_filename dataserver =
| head :: tail -> aux (head::header) tail | head :: tail -> aux (head::header) tail
| _ -> failwith "Too many routers in the middle" | _ -> failwith "Too many routers in the middle"
in in
aux [] (List.map String.trim raw_msg) aux [] (List.rev @@ List.rev_map String.trim raw_msg)
in in
let handle message = let handle message =
match message with match message with
@ -401,7 +401,7 @@ let run ezfio_filename dataserver =
| head :: tail -> aux (head::header) tail | head :: tail -> aux (head::header) tail
| _ -> failwith "Too many routers in the middle" | _ -> failwith "Too many routers in the middle"
in in
aux [] (List.map String.trim raw_msg) aux [] (List.rev @@ List.rev_map String.trim raw_msg)
in in
let handle message = let handle message =
match message with match message with

View File

@ -11,7 +11,8 @@ let display_table ~range property =
and data = p.Random_variable.data and data = p.Random_variable.data
in in
let results = let results =
List.map2 (fun (val1, err1) (val2,err2) -> (val1, err1, val2, err2)) conv rconv List.rev_map2 (fun (val1, err1) (val2,err2) -> (val1, err1, val2, err2)) conv rconv
|> List.rev
in in
List.iter2 (fun (val1, err1, val2, err2) block -> List.iter2 (fun (val1, err1, val2, err2) block ->
Printf.printf "%10.6f %10.6f %10.6f %10.6f %10.6f\n" Printf.printf "%10.6f %10.6f %10.6f %10.6f %10.6f\n"
@ -116,12 +117,13 @@ let display_histogram ~range property =
and norm = and norm =
1. /. (sqrt(sigma2 *. 2.*.pi)) 1. /. (sqrt(sigma2 *. 2.*.pi))
in in
List.map histo ~f:(fun (x,y) -> List.rev_map histo ~f:(fun (x,y) ->
let g = let g =
norm *. exp(-.((x-.mu)*.(x-.mu)*.one_over_2sigma2)) norm *. exp(-.((x-.mu)*.(x-.mu)*.one_over_2sigma2))
in in
(x,y,g) (x,y,g)
) )
|> List.rev
|> List.iter ~f:(fun (x,y,g) -> |> List.iter ~f:(fun (x,y,g) ->
Printf.printf "%16.10f %16.10f %16.10f\n" x y g) Printf.printf "%16.10f %16.10f %16.10f\n" x y g)
*) *)

View File

@ -103,7 +103,8 @@ let full_run ?(start_dataserver=true) ezfio_filename =
in in
match launcher match launcher
|> String.split_on_char ' ' |> String.split_on_char ' '
|> List.map String.trim |> List.rev_map String.trim
|> List.rev
|> List.filter (fun x -> x <> "") |> List.filter (fun x -> x <> "")
with with
| launcher_exe::launcher_flags -> | launcher_exe::launcher_flags ->

View File

@ -232,7 +232,7 @@ let ave_error { property ; data } =
in in
if (Property.is_scalar property) then if (Property.is_scalar property) then
List.map (fun x -> List.rev_map (fun x ->
(Sample.to_float x.Block.value, (Sample.to_float x.Block.value,
Weight.to_float x.Block.weight) Weight.to_float x.Block.weight)
) data ) data
@ -247,7 +247,7 @@ let ave_error { property ; data } =
in in
let result = let result =
Array.init dim (fun idx -> Array.init dim (fun idx ->
List.map (fun x -> List.rev_map (fun x ->
(Sample.to_float ~idx x.Block.value, (Sample.to_float ~idx x.Block.value,
Weight.to_float x.Block.weight) Weight.to_float x.Block.weight)
) list_of_samples ) list_of_samples
@ -429,7 +429,8 @@ let merge ~create_key ?update_block_id ?update_value ?update_weight t =
if (x>y) then 1 if (x>y) then 1
else if (x<y) then -1 else if (x<y) then -1
else 0) else 0)
|> List.map (fun (x,y) -> y) |> List.rev_map (fun (x,y) -> y)
|> List.rev
} }
@ -505,7 +506,7 @@ let error_x_over_y = function
(** Create float, variable operators *) (** Create float, variable operators *)
let one_variable_operator ~update_value p f = let one_variable_operator ~update_value p f =
{ p with { p with
data = List.map (fun b -> { b with data = List.rev @@ List.rev_map (fun b -> { b with
Block.value = Sample.of_float (update_value (Sample.to_float b.Block.value) ) } Block.value = Sample.of_float (update_value (Sample.to_float b.Block.value) ) }
) p.data } ) p.data }
@ -594,7 +595,8 @@ let max_value_per_compute_node t =
if (x>y) then 1 if (x>y) then 1
else if (x<y) then -1 else if (x<y) then -1
else 0) else 0)
|> List.map (fun (x,y) -> y) |> List.rev_map (fun (x,y) -> y)
|> List.rev
} }
@ -675,7 +677,8 @@ let compress_files () =
with with
| Not_found -> true | Not_found -> true
) )
|> List.map (fun x -> dir_name^x) |> List.rev_map (fun x -> dir_name^x)
|> List.rev
in in
let out_channel_dir = let out_channel_dir =
@ -774,11 +777,11 @@ let centered_cumulants { property ; data } =
|> Average.to_float |> Average.to_float
in in
let centered_data = let centered_data =
List.map (fun x -> List.rev_map (fun x ->
( (Weight.to_float x.Block.weight), ( (Weight.to_float x.Block.weight),
(Sample.to_float x.Block.value) -. ave ) (Sample.to_float x.Block.value) -. ave )
) ) data
data |> List.rev
in in
let var = let var =
let (num, denom) = let (num, denom) =
@ -795,11 +798,11 @@ let centered_cumulants { property ; data } =
let sigma_inv = let sigma_inv =
1. /. (sqrt var) 1. /. (sqrt var)
in in
List.map (fun x -> List.rev_map (fun x ->
( (Weight.to_float x.Block.weight), ( (Weight.to_float x.Block.weight),
( (Sample.to_float x.Block.value) -. ave ) *. sigma_inv ) ( (Sample.to_float x.Block.value) -. ave ) *. sigma_inv )
) ) data
data |> List.rev
in in
let (cum3,cum4) = let (cum3,cum4) =
let (cum3, cum4, denom) = let (cum3, cum4, denom) =