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

SCM Repository

[diderot] Diff of /branches/charisee/src/compiler/high-to-mid/shiftHtM.sml
ViewVC logotype

Diff of /branches/charisee/src/compiler/high-to-mid/shiftHtM.sml

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

revision 2524, Fri Jan 17 20:17:12 2014 UTC revision 2525, Tue Jan 21 19:14:22 2014 UTC
# Line 2  Line 2 
2  structure shiftHtM = struct  structure shiftHtM = struct
3      local      local
4      structure E = Ein      structure E = Ein
5        structure P=Printer
6    
7      in      in
8    
# Line 108  Line 109 
109    
110  fun cleanIndex(e, intialn,index)=let  fun cleanIndex(e, intialn,index)=let
111      (*Each element in the list is unique*)      (*Each element in the list is unique*)
112    
113    
114      fun uniq(list1,n)=let      fun uniq(list1,n)=let
115          fun m([],l)=l          fun m([],l)=l
116              | m(e1::es,l)= (case e1              | m(e1::es,l)= (case e1
# Line 149  Line 152 
152    
153      val ix=findOuterIndex(e, intialn)      val ix=findOuterIndex(e, intialn)
154    
155        fun q(E.V p,E.V n)=""(*"print(String.concat["\n", Int.toString(p),"===>>",Int.toString(n),"\n"])*)
156    
157      fun g([],index',_,_,mapp)=(index',mapp)      fun g([],index',_,_,mapp)=(index',mapp)
158          | g(e::es,index',n,c, mapp)= let          | g(e::es,index',n,c, mapp)= let
159              val b=List.find (fn(E.V v)=>v=n) ix              val b=List.find (fn(E.V v)=>v=n) ix
160                  in case b                  in case b
161                      of NONE=>g(es,index',n+1, c, mapp)                      of NONE=>g(es,index',n+1, c, mapp)
162                      |_=> let val mapp'=insert(E.V n, E.V c) mapp                      |_=> let val mapp'=insert(E.V n, E.V c) mapp
163                        val y=q(E.V n,E.V c)
164                      in g(es, index'@[e], n+1, c+1, mapp') end                      in g(es, index'@[e], n+1, c+1, mapp') end
165                  end                  end
166    
167      val (index',mapp)=g(index,[],0,0,empty)      val (index',mapp)=g(index,[],0,0,empty)
168    
169    
170    
171    
172      fun createMapp([],n,mapp)=(mapp,n)      fun createMapp([],n,mapp)=(mapp,n)
173          | createMapp((s,_,_)::es,n,mapp)= let          | createMapp((s,_,_)::es,n,mapp)= let
174                val E.V p=s
175              (* val qq=print ("\n Inserting")*)
176                val y=q(s,E.V n)
177              val m=insert(s, E.V n) mapp (*check here*)              val m=insert(s, E.V n) mapp (*check here*)
178              in createMapp(es,n+1, m) end              in createMapp(es,n+1, m) end
179    
# Line 170  Line 181 
181    
182      fun rewriteIndex(e, smapp) =(case e      fun rewriteIndex(e, smapp) =(case e
183          of E.V v =>let val l=lookup e smapp          of E.V v =>let val l=lookup e smapp
184              in case l of NONE=> (print"error"; E.V 99)                  in case l of NONE=> raise Fail("error Could not find :"^Int.toString(v))
185              | SOME s=> s end              | SOME s=> s end
186          | E.C _=> e          | E.C _=> e
187          (*end case*))          (*end case*))
188    
189      fun singleIndex(e,smapp)=let      fun singleIndex(e,smapp)=let
190          val l=lookup (E.V e) smapp          val l=lookup (E.V e) smapp
191           (* val g=print(String.concat["\n SingleIndex:", Int.toString(e)])*)
192          in case l          in case l
193              of NONE=> (raise Fail" error could not find index" )              of NONE=> (raise Fail" error could not find index" )
194              | SOME(E.V s)=> s              | SOME(E.V s)=> s
195          end          end
196    
197      fun rewrite (body,n,smapp)=(case body      fun rewrite (body,n,smapp,embed)=(case body
198          of  E.Tensor(id,ix)=> E.Tensor(id, (List.map (fn e=>rewriteIndex(e, smapp)) ix))          of  E.Tensor(id,ix)=> E.Tensor(id, (List.map (fn e=>rewriteIndex(e, smapp)) ix))
199          | E.Epsilon(i,j,k)=>E.Epsilon(singleIndex(i, smapp),singleIndex(j, smapp),singleIndex(k, smapp))          | E.Epsilon(i,j,k)=>E.Epsilon(singleIndex(i, smapp),singleIndex(j, smapp),singleIndex(k, smapp))
200          | E.Value i=> (print "found value";E.Value(singleIndex (i,smapp)))          | E.Value i=> (E.Value(singleIndex (i,smapp)))
201          | E.Delta(i,j)=> E.Delta(rewriteIndex(i,smapp), rewriteIndex(j,smapp))          | E.Delta(i,j)=> E.Delta(rewriteIndex(i,smapp), rewriteIndex(j,smapp))
202          | E.Add e=> E.Add(List.map (fn(e1)=>rewrite(e1,n,smapp)) e)          | E.Add e=> E.Add(List.map (fn(e1)=>rewrite(e1,n,smapp,embed)) e)
203          | E.Sub(e1,e2)=>  E.Sub(rewrite(e1,n,smapp),rewrite(e2,n,smapp))          | E.Sub(e1,e2)=>  E.Sub(rewrite(e1,n,smapp,embed),rewrite(e2,n,smapp,embed))
204          | E.Div(e1,e2)=>  E.Div(rewrite(e1,n,smapp),rewrite(e2,n,smapp))          | E.Div(e1,e2)=>  E.Div(rewrite(e1,n,smapp,embed),rewrite(e2,n,smapp,embed))
205    
206            | E.Sum(sx,E.Prod e) =>let
207    
208                    (*  val level=(Int.toString(embed))
209                val q=print "\n START *************************************\n"
210    val qqqq=print level
211    *)
212    val (mm,nn)=createMapp(sx,n,smapp)
213    
214    
215    
216                val k=E.Prod(List.map (fn(e1)=> rewrite(e1,nn,mm,embed+1)) e)
217                in E.Sum((List.map (fn(e1, lb,ub)=>(rewriteIndex(e1,mm),lb,ub)) sx),k) end
218    
219          | E.Sum(sx,e)=> let          | E.Sum(sx,e)=> let
220        (*
221                val q=print "\n START *************************************\n "
222      val level=(Int.toString(embed))
223    val qqqq=print level*)
224    
225              val (mm,nn)=createMapp(sx,n,smapp)              val (mm,nn)=createMapp(sx,n,smapp)
226              in E.Sum((List.map (fn(e1, lb,ub)=>(rewriteIndex(e1,mm),lb,ub)) sx),rewrite(e,nn,mm)) end  
227          | E.Prod e=> E.Prod(List.map (fn(e1)=>rewrite(e1,n,smapp)) e)  
228          | E.Neg e=> E.Neg(rewrite(e, n, smapp))  
229                val m=E.Sum((List.map (fn(e1, lb,ub)=>(rewriteIndex(e1,mm),lb,ub)) sx),rewrite(e,nn,mm,embed+1))
230    (*
231                    val qq=print level
232                    val q=print "END *************************************\n "
233    
234    *)
235                in m end
236    
237            | E.Prod e=> E.Prod(List.map (fn(e1)=>rewrite(e1,n,smapp,embed)) e)
238            | E.Neg e=> E.Neg(rewrite(e, n, smapp,embed))
239          |  E.Krn (h,dx, pos)=>          |  E.Krn (h,dx, pos)=>
240              E.Krn(h,(List.map (fn (e1,e2)=>(e1,rewriteIndex(e2, smapp))) dx), rewrite(pos,n,smapp))              E.Krn(h,(List.map (fn (e1,e2)=>(e1,rewriteIndex(e2, smapp))) dx), rewrite(pos,n,smapp,embed))
241          |  E.Img (v,alpha, pos)=>          |  E.Img (v,alpha, pos)=>
242              E.Img(v,(List.map (fn e=>rewriteIndex(e, smapp)) alpha),              E.Img(v,(List.map (fn e=>rewriteIndex(e, smapp)) alpha),
243                  (List.map (fn e=>rewrite(e, n, smapp)) pos))                  (List.map (fn e=>rewrite(e, n, smapp,embed)) pos))
244          | E.Conv(v,alpha,h, dx)=> E.Conv(v, (List.map (fn e=>rewriteIndex(e, smapp)) alpha),h,(List.map (fn e=>rewriteIndex(e, smapp)) dx))          | E.Conv(v,alpha,h, dx)=> E.Conv(v, (List.map (fn e=>rewriteIndex(e, smapp)) alpha),h,(List.map (fn e=>rewriteIndex(e, smapp)) dx))
245          | E.Probe(e1,e2)=>raise Fail "Probe- Should have been expanded"          | E.Probe(e1,e2)=>raise Fail "Probe- Should have been expanded"
246          | _=> body          | _=> body
247          (*end case*))          (*end case*))
248    
249      val e'=rewrite(e, length ix, mapp)      val e'=rewrite(e, length ix, mapp,0)
250    
251      in      in
252          (ix,index',e')          (ix,index',e')

Legend:
Removed from v.2524  
changed lines
  Added in v.2525

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