-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
open CommonOpts | ||
|
||
let cmp (time1, _) (time2, _) = CCFloat.compare time1 time2 | ||
|
||
let aux size iter_idx = | ||
let timer = Timer.make () in | ||
let types = Iter.to_list iter_idx |> List.sort_uniq Type.compare in | ||
let n_types = List.length types in | ||
let rec all_pairs i acc l = | ||
match l with | ||
| [] -> acc | ||
| t1 :: t -> | ||
Format.printf "@[<h>%i/%i: %a@]@." i n_types Type.pp t1; | ||
let acc = | ||
List.fold_left | ||
(fun acc t2 -> | ||
let env = Type.Env.make () in | ||
Timer.start timer; | ||
(try ignore @@ Acic.unify env t1 t2 | ||
with e -> | ||
Format.printf "\"%a\" \"%a\"@." Type.pp t1 Type.pp t2; | ||
raise e); | ||
Timer.stop timer; | ||
let time = Timer.get timer in | ||
if time > 5. then Format.printf "@[<h>Big time: %a@]@." Type.pp t2; | ||
CCList.tl (CCList.sorted_insert ~cmp (time, (t1, t2)) acc)) | ||
acc l | ||
in | ||
Gc.major (); | ||
all_pairs (i+1) acc t | ||
in | ||
let hof = all_pairs 1 (List.init size (fun _ -> (0., (Type.dummy, Type.dummy)))) types in | ||
Format.printf "@[<v>%a@]@." | ||
(CCList.pp ~pp_sep:(CCFormat.return "@ ") | ||
(CCPair.pp CCFloat.pp (CCPair.pp Type.pp Type.pp))) | ||
hof | ||
|
||
let print_stat () = | ||
let stats = | ||
[| | ||
Tracing.get_nb_ac (); Tracing.get_nb_arrow (); Tracing.get_nb_timeout (); | ||
|] | ||
in | ||
Fmt.pr "@.Stats@."; | ||
Format.printf "AC sol\tArrow sol\tTimeout@."; | ||
Format.printf "@[%a@]@." | ||
(CCArray.pp ~pp_sep:(CCFormat.return "\t") CCInt.pp) | ||
stats; | ||
Fmt.pr "@." | ||
|
||
let main size idx_file = | ||
let iter_idx = | ||
let db = | ||
try Db.load idx_file | ||
with Sys_error _ -> | ||
error @@ Fmt.str "cannot open index file `%a'" Fpath.pp idx_file | ||
in | ||
Db.iter db |> Iter.map snd | ||
in | ||
aux size iter_idx | ||
|
||
let main size idx_file = | ||
try Ok (main size idx_file) with Error msg -> Error (`Msg msg) | ||
|
||
open Cmdliner | ||
open Cmd | ||
|
||
let size = | ||
let docv = "size" in | ||
let doc = "Number of function in the hall of fame." in | ||
Arg.(value & opt int 10 & info [ "size" ] ~docv ~doc) | ||
|
||
let idx_file = | ||
let docv = "file" in | ||
let doc = "Set index file." in | ||
Arg.(value & opt Convs.file Paths.idx_file & info [ "index" ] ~docv ~doc) | ||
|
||
let cmd = | ||
let doc = "compute hall of fame" in | ||
Cmd.v | ||
(info "hof" ~sdocs:Manpage.s_common_options ~doc) | ||
Term.(term_result (const main $ size $ idx_file)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters