Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] Diff of /branches/vis15/src/compiler/simplify/util.sml
ViewVC logotype

Diff of /branches/vis15/src/compiler/simplify/util.sml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 4392, Tue Aug 9 21:20:13 2016 UTC revision 4393, Tue Aug 9 22:00:05 2016 UTC
# Line 10  Line 10 
10    
11  structure Util : sig  structure Util : sig
12    
13    (* return information about a reduction operator *)    (* the standard reductions extended with pseudo reductions *)
14      val reductionInfo : Var.t -> {      datatype reduction = MEAN | VARIANCE | RED of Reductions.t
15    
16      (* identify a basis variable that specifies a reduction *)
17        val identifyReduction : Var.t -> reduction
18    
19      (* return information about how to compute a reduction operator *)
20        val reductionInfo : Reductions.t -> {
21              rator : Var.t,                      (* primitive operator *)              rator : Var.t,                      (* primitive operator *)
22              init : Literal.t,                   (* identity element to use for initialization *)              init : Literal.t,                   (* identity element to use for initialization *)
23              mvs : SimpleTypes.meta_arg list     (* meta-variable arguments for primitive application *)              mvs : SimpleTypes.meta_arg list     (* meta-variable arguments for primitive application *)
# Line 28  Line 34 
34      structure R = RealLit      structure R = RealLit
35      structure VMap = SimpleVar.Map      structure VMap = SimpleVar.Map
36    
37      fun reductionInfo rator =      datatype reduction = MEAN | VARIANCE | RED of Reductions.t
38    
39        fun identifyReduction rator =
40            if Var.same(BV.red_all, rator)            if Var.same(BV.red_all, rator)
41              then {rator = BV.op_and, init = L.Bool true, mvs = []}              then RED(Reductions.ALL)
42            else if Var.same(BV.red_exists, rator)            else if Var.same(BV.red_exists, rator)
43              then {rator = BV.op_or, init = L.Bool false, mvs = []}              then RED(Reductions.EXISTS)
44            else if Var.same(BV.red_max, rator)            else if Var.same(BV.red_max, rator)
45              then {rator = BV.fn_max_r, init = L.Real R.negInf, mvs = []}              then RED(Reductions.MAX)
46            else if Var.same(BV.red_mean, rator)            else if Var.same(BV.red_mean, rator)
47              then raise Fail "FIXME: 'mean' reduction not yet supported"              then MEAN
48            else if Var.same(BV.red_min, rator)            else if Var.same(BV.red_min, rator)
49              then {rator = BV.fn_min_r, init = L.Real R.posInf, mvs = []}              then RED(Reductions.MIN)
50            else if Var.same(BV.red_product, rator)            else if Var.same(BV.red_product, rator)
51              then {rator = BV.mul_rr, init = L.Real R.one, mvs = []}              then RED(Reductions.PRODUCT)
52            else if Var.same(BV.red_sum, rator)            else if Var.same(BV.red_sum, rator)
53              then {rator = BV.add_tt, init = L.Real R.one, mvs = [SimpleTypes.SHAPE[]]}              then RED(Reductions.SUM)
54            else if Var.same(BV.red_variance, rator)            else if Var.same(BV.red_variance, rator)
55              then raise Fail "FIXME: 'variance' reduction not yet supported"              then VARIANCE
56              else raise Fail(Var.uniqueNameOf rator ^ " is not a reduction operator")              else raise Fail(Var.uniqueNameOf rator ^ " is not a reduction operator")
57    
58        fun reductionInfo redOp = (case redOp
59               of Reductions.ALL => {rator = BV.op_and, init = L.Bool true, mvs = []}
60                | Reductions.EXISTS => {rator = BV.op_or, init = L.Bool false, mvs = []}
61                | Reductions.MAX => {rator = BV.fn_max_r, init = L.Real R.negInf, mvs = []}
62                | Reductions.MIN => {rator = BV.fn_min_r, init = L.Real R.posInf, mvs = []}
63                | Reductions.PRODUCT => {rator = BV.mul_rr, init = L.Real R.one, mvs = []}
64                | Reductions.SUM => {rator = BV.add_tt, init = L.Real R.one, mvs = [SimpleTypes.SHAPE[]]}
65              (* end case *))
66    
67      local      local
68        val n = ref 0        val n = ref 0
69        fun mkFuncId (name, ty) = let val id = !n        fun mkFuncId (name, ty) = let val id = !n

Legend:
Removed from v.4392  
changed lines
  Added in v.4393

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0