10
0
mirror of https://gitlab.com/scemama/EZFIO.git synced 2024-12-22 20:33:42 +01:00

Changed ocaml flattened_ezfio_data to flattened_ezfio -> much faster

This commit is contained in:
Anthony Scemama 2014-11-03 17:29:58 +01:00
parent 0c097dac4f
commit 293c6b971a
2 changed files with 26 additions and 21 deletions

View File

@ -306,19 +306,29 @@ let ezfio_get_element { rank=r ; dim=d ; data=data } coord =
;; ;;
let flattened_ezfio_data d = let flattened_ezfio { rank ; dim ; data } =
match d with let flatten_2 d =
| Ezfio_item d -> d let l = List.map (function
| Ezfio_data d -> | Ezfio_item i -> i
let d = Array.to_list d in | Ezfio_data i -> assert false
let rec do_work accu = function ) (Array.to_list d)
| [] -> accu in Array.concat l
| (Ezfio_item x)::tail -> do_work (Array.append accu x) tail
| (Ezfio_data x)::tail ->
let newaccu = do_work accu (Array.to_list x )
in do_work newaccu tail
in in
do_work (Array.of_list []) d
let rec flatten_n rank d =
if (rank = 2) then
flatten_2 d
else
let l = List.map (function
| Ezfio_data x -> flatten_n (rank-1) x
| Ezfio_item _ -> assert false
) (Array.to_list d)
in Array.concat l
in
match data with
| Ezfio_item d -> d
| Ezfio_data d -> flatten_n rank d
;; ;;
@ -367,13 +377,8 @@ let read_array type_conversion group name : 'a ezfio_array =
assert (rank == Array.length dimensions) ; assert (rank == Array.length dimensions) ;
(* Read one-dimensional arrays *) (* Read one-dimensional arrays *)
let read_1d nmax = let read_1d nmax =
let rec do_work accu = function Ezfio_item (Array.init nmax (fun i->
| 0 -> Array.of_list (List.rev accu) type_conversion (trim (input_line in_channel))) )
| n ->
let trimmed_line = trim (input_line in_channel) in
do_work ( (type_conversion trimmed_line)::accu ) (n-1)
in
Ezfio_item (do_work [] nmax)
in in
(* Read multi-dimensional arrays *) (* Read multi-dimensional arrays *)
let rec read_nd = function let rec read_nd = function
@ -419,7 +424,7 @@ let write_array print_fun group name a =
let uz_filename = Filename.temp_file "" ".tmp" ~temp_dir:(Sys.getcwd ()) in let uz_filename = Filename.temp_file "" ".tmp" ~temp_dir:(Sys.getcwd ()) in
let out_channel = open_out uz_filename in let out_channel = open_out uz_filename in
let { rank=rank ; dim=dimensions ; data=data } = a in let { rank=rank ; dim=dimensions ; data=data } = a in
let data = flattened_ezfio_data data let data = flattened_ezfio a
in in
begin begin
(* Write rank *) (* Write rank *)

View File

@ -1 +1 @@
VERSION=1.1.8 VERSION=1.1.9