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

SCM Repository

[diderot] Diff of /branches/charisee/src/compiler/high-il/app-ein.sml
ViewVC logotype

Diff of /branches/charisee/src/compiler/high-il/app-ein.sml

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

revision 2604, Fri Apr 25 18:23:44 2014 UTC revision 2605, Wed Apr 30 01:46:09 2014 UTC
# Line 12  Line 12 
12      structure P = Printer      structure P = Printer
13      in      in
14    
   
   
   
   
15  fun insert (key, value) d =fn s =>  fun insert (key, value) d =fn s =>
16      if s = key then SOME value      if s = key then SOME value
17      else d s      else d s
# Line 23  Line 19 
19  fun lookup k d = d k  fun lookup k d = d k
20  val empty =fn key =>NONE  val empty =fn key =>NONE
21    
22  fun mapId(i ,dict,shift)= let  fun mapId(i ,dict,shift)=(case (lookup i dict)
     val l =lookup i dict  
     in (case l  
23          of NONE =>i+shift          of NONE =>i+shift
24          | SOME(j)=>j          | SOME(j)=>j
25      (*end case*))      (*end case*))
     end  
26    
27  fun mapIndex((E.V i) ,dict,shift)= let  fun mapIndex(v ,dict,shift)= (case (lookup v dict)
28  val l =lookup (E.V i) dict      of NONE =>let val E.V(i)=v in E.V(i+shift) end
     in (case l  
     of NONE =>E.V(i+shift)  
29      | SOME(j)=>j      | SOME(j)=>j
30  (*end case*))  (*end case*))
 end  
31    
32    fun mapId2(i ,dict,shift)= (case (lookup i dict)
 fun mapId2(i ,dict,shift)= let  
     val l =lookup i dict  
     in (case l  
33          of NONE =>(print "Err out of range";i+shift)          of NONE =>(print "Err out of range";i+shift)
34          | SOME(j)=>j          | SOME(j)=>j
35          (*end case*))          (*end case*))
     end  
   
   
   
   
36    
37  fun rewriteSubst(e,subId,mx,paramShift,sumShift)=let  fun rewriteSubst(e,subId,mx,paramShift,sumShift)=let
38    
39      fun insertIndex([],_,dict,shift)=(dict,shift)      fun insertIndex([],_,dict,shift)=(dict,shift)
40      | insertIndex(E.V e::es, n,dict,_)= insertIndex(es, n+1, insert(E.V n ,E.V e) dict,e-n)      | insertIndex(e1::es, n,dict,_)=(case e1
41      | insertIndex(E.C e::es, n,dict,_)= insertIndex(es, n+1, insert(E.V n ,E.C e) dict,e-n)          of E.V e=> insertIndex(es, n+1, insert(E.V n ,E.V e) dict,e-n)
42            | E.C e => insertIndex(es, n+1, insert(E.V n ,E.C e) dict,e-n)
43            (*end case*))
44    
45      val (subMu,shift)=insertIndex(mx,0,empty,0)      val (subMu,shift)=insertIndex(mx,0,empty,0)
46      val shift'=Int.max(sumShift, shift)      val shift'=Int.max(sumShift, shift)
# Line 69  Line 54 
54      fun mapParam(id)= mapId2(id, subId, 0)      fun mapParam(id)= mapId2(id, subId, 0)
55      fun apply e=(case e      fun apply e=(case e
56          of Ein.Const _ => e          of Ein.Const _ => e
57            | Ein.Value _           => raise Fail "expression before expand"
58            | Ein.Krn _             => raise Fail "expression before expand"
59            | Ein.Img  _            => raise Fail "expression before expand"
60          | Ein.Tensor(id, mx) => Ein.Tensor(mapParam id,mapAlpha mx)          | Ein.Tensor(id, mx) => Ein.Tensor(mapParam id,mapAlpha mx)
61          | Ein.Field(id, mx) => Ein.Field(mapParam id,mapAlpha mx)          | Ein.Field(id, mx) => Ein.Field(mapParam id,mapAlpha mx)
         | Ein.Krn(id,deltas,pos)=> Ein.Krn(mapParam id, deltas,apply pos)  
62          | Ein.Delta (i,j) => Ein.Delta(mapMu i,mapMu j)          | Ein.Delta (i,j) => Ein.Delta(mapMu i,mapMu j)
         | Ein.Value _=> e  
63          | Ein.Epsilon(i, j, k) =>Ein.Epsilon(mapSingle i, mapSingle j, mapSingle k)          | Ein.Epsilon(i, j, k) =>Ein.Epsilon(mapSingle i, mapSingle j, mapSingle k)
64          | Ein.Sum(c,esum)=> Ein.Sum(mapSum c, apply esum)          | Ein.Sum(c,esum)=> Ein.Sum(mapSum c, apply esum)
65          | Ein.Neg e => Ein.Neg(apply e)          | Ein.Neg e => Ein.Neg(apply e)
# Line 84  Line 70 
70          | Ein.Div(e1, e2)=> Ein.Div(apply e1, apply e2)          | Ein.Div(e1, e2)=> Ein.Div(apply e1, apply e2)
71          | Ein.Partial mx => E.Partial (mapAlpha mx)          | Ein.Partial mx => E.Partial (mapAlpha mx)
72          | Ein.Apply(e1, e2)=> Ein.Apply(apply e1, apply e2)          | Ein.Apply(e1, e2)=> Ein.Apply(apply e1, apply e2)
73          | Ein.Conv (v,mx,h,ux) =>(Ein.Conv(mapParam v, mapAlpha mx, mapParam h, mapAlpha ux))          | Ein.Conv (v,mx,h,ux)  => Ein.Conv(mapParam v, mapAlpha mx, mapParam h, mapAlpha ux)
74          | Ein.Probe(f, pos) => Ein.Probe(apply f, apply pos)          | Ein.Probe(f, pos) => Ein.Probe(apply f, apply pos)
         | Ein.Img(id,mx,pos)=> Ein.Img(mapParam id,mapAlpha mx, (List.map apply pos))  
75          (*end case*))          (*end case*))
76      in apply e end      in apply e end
77    
# Line 108  Line 93 
93    
94      val origId=createDict(nnext,place,place+n2-1,empty)      val origId=createDict(nnext,place,place+n2-1,empty)
95      val subId=createDict(n2,~1,place-1,empty)      val subId=createDict(n2,~1,place-1,empty)
   
96     in (params',origId,subId,nbeg)  end     in (params',origId,subId,nbeg)  end
97    
98    
# Line 134  Line 118 
118          else (case e          else (case e
119              of E.Tensor(id,mx)=>E.Tensor(mapId(id,origId,0), mx)              of E.Tensor(id,mx)=>E.Tensor(mapId(id,origId,0), mx)
120              | E.Field(id,mx)=> E.Field(mapId(id,origId,0), mx)              | E.Field(id,mx)=> E.Field(mapId(id,origId,0), mx)
121                |  _ => raise Fail"Id error:Term to be replaced is not a Tensor or Fields"
122              (*end case*))              (*end case*))
123          end          end
124      fun sumI(e)=let      fun sumI(e)=let
# Line 141  Line 126 
126          in v end          in v end
127    
128      fun apply e=(case e      fun apply e=(case e
129          of Ein.Const _ => e          of Ein.Value _          => raise Fail "expression before expand"
130          | Ein.Tensor(id, mx) =>rewrite (id,mx,e)          | Ein.Krn _             => raise Fail "expression before expand"
131          | Ein.Field(id, mx) => rewrite (id,mx,e)          | Ein.Img  _            => raise Fail "expression before expand"
132          | Ein.Krn(id,deltas,pos)=> Ein.Krn(mapId(id,origId,0), deltas,apply pos)          | Ein.Const _           => e
133          | Ein.Delta _ => e          | Ein.Delta _ => e
         | Ein.Value _=> e  
134          | Ein.Epsilon(i, j, k) => e          | Ein.Epsilon(i, j, k) => e
135            | Ein.Partial mx        => e
136            | Ein.Tensor(id, mx)    => rewrite (id,mx,e)
137            | Ein.Field(id, mx)     => rewrite (id,mx,e)
138          | Ein.Sum(c,esum)=> (sumIndex:=sumI(c);  Ein.Sum( c, apply esum))          | Ein.Sum(c,esum)=> (sumIndex:=sumI(c);  Ein.Sum( c, apply esum))
139          | Ein.Lift e => Ein.Lift(apply e)          | Ein.Lift e => Ein.Lift(apply e)
140          | Ein.Neg e => Ein.Neg(apply e)          | Ein.Neg e => Ein.Neg(apply e)
# Line 155  Line 142 
142          | Ein.Sub(e1, e2) => Ein.Sub(apply e1, apply e2)          | Ein.Sub(e1, e2) => Ein.Sub(apply e1, apply e2)
143          | Ein.Prod es => Ein.Prod(List.map apply es)          | Ein.Prod es => Ein.Prod(List.map apply es)
144          | Ein.Div(e1, e2)=> Ein.Div(apply e1, apply e2)          | Ein.Div(e1, e2)=> Ein.Div(apply e1, apply e2)
         | Ein.Partial mx => e  
145          | Ein.Apply(e1, e2)=> Ein.Apply(apply e1, apply e2)          | Ein.Apply(e1, e2)=> Ein.Apply(apply e1, apply e2)
146          | Ein.Conv (v,mx,h,ux) =>Ein.Conv(mapId(v, origId,0), mx, mapId(h,origId,0), ux)          | Ein.Conv (v,mx,h,ux) =>Ein.Conv(mapId(v, origId,0), mx, mapId(h,origId,0), ux)
147          | Ein.Probe(f, pos) => Ein.Probe(apply f, apply pos)          | Ein.Probe(f, pos) => Ein.Probe(apply f, apply pos)
148          | Ein.Img(id,mx,pos)=> Ein.Img(mapId(id,origId,0),mx, (List.map apply pos))  
149      (*end case*))      (*end case*))
150      val body''=apply body      val body''=apply body
151      val ref g=changed      val ref g=changed

Legend:
Removed from v.2604  
changed lines
  Added in v.2605

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