Skip to content

Commit

Permalink
progress on lower bound refinement
Browse files Browse the repository at this point in the history
  • Loading branch information
ellisk committed Apr 26, 2014
1 parent ff018f6 commit 7627556
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
21 changes: 17 additions & 4 deletions compress.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,25 @@ open Expression
open Type
open Library
open Utils
open Task

let compress lambda dagger type_array (task_solutions : task*(int*float list) list) =

let compress lambda dagger type_array (task_solutions : (task * (int*float) list) list) =
let (i2n,n2i,_) = dagger in
let terminals = List.filter (fun (i,_) -> is_leaf_ID dagger i) (hash_bindings i2n) in
(* find the productions that are used in more than one task *)
let task_uses = List.map (fun (_,solutions) ->
let = in
) task_solutions
in
List.fold_left (fun a (i,_) ->
IntSet.union a (get_sub_IDs dagger i)
) IntSet.empty solutions
) task_solutions in
let task_counts = List.fold_left (fun counts uses ->
IntSet.fold (fun i a ->
try
let old_count = IntMap.find i a in
IntMap.add i (old_count+1) a
with Not_found -> IntMap.add i 1 a
) uses counts
) IntMap.empty task_uses in
let candidates = List.filter (fun (i,c) -> c > 1 && not (is_leaf_ID dagger i)) (IntMap.bindings task_counts) in
0
8 changes: 7 additions & 1 deletion expression.ml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

open Obj
open Type

open Utils


type expression =
Expand Down Expand Up @@ -103,6 +103,12 @@ let is_leaf_ID (g,_,_) i =
ExpressionLeaf(_) -> true
| _ -> false;;

let rec get_sub_IDs g i =
let (i2n,_,_) = g in
match Hashtbl.find i2n i with
ExpressionLeaf(_) -> IntSet.singleton i
| ExpressionBranch(f,x) ->
IntSet.add i (IntSet.union (get_sub_IDs g f) (get_sub_IDs g f));;

(* performs type inference upon the entire graph of expressions *)
(* returns an array whose ith element is the type of the ith expression *)
Expand Down
2 changes: 1 addition & 1 deletion utils.ml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@


module IntMap = Map.Make(struct type t = int let compare = compare end)
module IntSet = Set.Make(struct type t = int let compare = compare end)

let compose f g = fun x -> f (g x);;

Expand Down

0 comments on commit 7627556

Please sign in to comment.