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/split-einHtM.sml
ViewVC logotype

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

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

revision 2554, Sun Mar 2 19:58:48 2014 UTC revision 2555, Mon Mar 3 19:14:57 2014 UTC
# Line 83  Line 83 
83              end              end
84    
85    
   
 (*let  
     val id=ref (length params)  
         val n=length index  
         val ix=List.tabulate (n,fn v=> E.V(v))  
     fun mkTensor _=let val ref idx= id in (id:=(idx+1);E.Tensor(idx,ix)) end  
   
     fun replace e'= let  
         val q=fresh(DstTy.TensorTy(index))  
         val t=mkTensor 0  
         val newbie=createEin( params,index,e')  
         in ([(q,newbie,args)],(params@[E.TEN(1,index)], E.Neg t,[q]))  
         end  
   
     fun sort e1= (case e1  
         of E.Add  _=> replace e1  
         | E.Sub _=> replace e1  
         | E.Prod _=> replace e1  
         | E.Div _=> replace e1  
         | E.Sum _=> replace e1  
         | _=>([],params, E.Neg e1, args)  
         (*end case*))  
   
     val (newbies1,params1,lft1,args1)=sort e  
     val (p',b',args')= shift.cleanParams(lft1,params@params1, args@args1)  
     val z1=List.map (fn(e)=> createnewb(params,index,args,e) ) newbies1  
     in  
         (z1,(p',b',args'))  
     end  
   
 *)  
   
   
   
   
86  (*Outside Operator is Add*)  (*Outside Operator is Add*)
87  fun handleAdd(params, index,list1,args)=let  fun handleAdd(params, index,list1,args)=let
88        val aa=print "ADDXX"
89      val id=ref (length params)      val id=ref (length params)
90      val n=length index      val n=length index
91      val ix=List.tabulate (n,fn v=> E.V(v))      val ix=List.tabulate (n,fn v=> E.V(v))
# Line 146  Line 112 
112    
113      val (lft, newbies,params',args')=sort(list1,([],[],[],[]))      val (lft, newbies,params',args')=sort(list1,([],[],[],[]))
114      val (p',b',args')= shift.cleanParams(E.Add(lft),params@params', args@args')      val (p',b',args')= shift.cleanParams(E.Add(lft),params@params', args@args')
115    
116    
117      val z=List.map (fn(e)=> createnewb(params,index,args,e) ) newbies      val z=List.map (fn(e)=> createnewb(params,index,args,e) ) newbies
118      in      in
119          (z,(p',b',args'))          (z,(p',b',args'))
# Line 158  Line 126 
126    
127  (*Outside Operator is Sub*)  (*Outside Operator is Sub*)
128  fun handleSub(params, index,e1,e2,args)=let  fun handleSub(params, index,e1,e2,args)=let
129        val gg=print "SUBXX"
130      val id=ref (length params)      val id=ref (length params)
131      val n=length index      val n=length index
132      val ix=List.tabulate (n,fn v=> E.V(v))      val ix=List.tabulate (n,fn v=> E.V(v))
# Line 168  Line 137 
137          val s=findOp e          val s=findOp e
138          in (case s          in (case s
139              of 0=>(e,[],[],[])              of 0=>(e,[],[],[])
   
140              | _=> let              | _=> let
141                  val q=fresh(DstTy.TensorTy(index))                  val q=fresh(DstTy.TensorTy(index))
142                  in (mkTensor 0, [(q, e)],[E.TEN(1,index)],[q]) end                  in (mkTensor 0, [(q, e)],[E.TEN(1,index)],[q]) end
# Line 187  Line 155 
155  (*Outside Operator is Div *)  (*Outside Operator is Div *)
156  fun handleDiv(params, index,e1,e2,args)=let  fun handleDiv(params, index,e1,e2,args)=let
157      val id=ref (length params)      val id=ref (length params)
158        val n=length index
159      val ix=List.tabulate (n,fn v=> E.V(v))      val ix=List.tabulate (n,fn v=> E.V(v))
160      fun mkTensor _=let val ref idx= id in (id:=(idx+1);E.Tensor(idx,ix)) end      fun mkTensor _=let val ref idx= id val _ =id:=(idx+1) in (E.Tensor(idx,ix),E.TEN(1,index)) end
161      fun mkSca _=let val ref idx= id in (id:=(idx+1);E.Tensor(idx,[])) end      fun mkSca _=   let val ref idx= id val _ =id:=(idx+1) in (E.Tensor(idx,[]),E.TEN(1,[])) end
162    
163      fun divsort(e,nextfn)= let      fun divsort(e,nextfn)= let
164          val s=findOp e          val s=findOp e
# Line 198  Line 167 
167    
168              | _=> let              | _=> let
169                  val q=fresh(DstTy.TensorTy(index))                  val q=fresh(DstTy.TensorTy(index))
170                  in (nextfn 0, [(q, e)],[E.TEN(1,index)],[q]) end                  val (a,b)=nextfn 0
171                    in (a,[b], [(q, e)],[q]) end
172              (*end case*))              (*end case*))
173          end          end
174    
175      val (lft1, newbies1,params1,args1)=divsort(e1,mkTensor)      val (lft1,params1, newbies1,args1)=divsort(e1,mkTensor)
176      val (lft2, newbies2,params2,args2)=divsort(e2,mkSca)      val (lft2,params2, newbies2,args2)=divsort(e2,mkSca)
177      val (p',b',args')= shift.cleanParams(E.Div(lft1,lft2),params@params1@params2, args@args1@args2)      val (p',b',args')= shift.cleanParams(E.Div(lft1,lft2),params@params1@params2, args@args1@args2)
178    
179      val z1=List.map (fn(e)=> createnewb(params,index,args,e) ) newbies1      val z1=List.map (fn(e)=> createnewb(params,index,args,e) ) newbies1
# Line 219  Line 189 
189      val id=ref (length params)      val id=ref (length params)
190      val n=length index      val n=length index
191    
192      fun mkPTensor e=let  
         val ref idx= id  
         val (ix,index',e')=shift.cleanIndex(e, n, index)  
         in (id:=(idx+1);([E.Tensor(idx,ix)],index',e')) end  
193    
194    
195      fun foundOp (e,es,(lft,newbies, params, args))=let      fun foundOp (e,es,(lft,newbies, params, args))=let
# Line 231  Line 198 
198          val (ix,index',e')=shift.cleanIndex(e, n, index)          val (ix,index',e')=shift.cleanIndex(e, n, index)
199          val (p,ix,e')=([E.Tensor(idx,ix)],index',e')          val (p,ix,e')=([E.Tensor(idx,ix)],index',e')
200           val q=fresh(DstTy.TensorTy(ix))           val q=fresh(DstTy.TensorTy(ix))
201          in (es,(lft@p, newbies@[(q, e',ix)],params@[E.TEN(1,ix)],args@[q])) end          in (id:=(idx+1);(es,(lft@p, newbies@[(q, e',ix)],params@[E.TEN(1,ix)],args@[q]))) end
202    
203    
204      fun sort([], m)=m      fun sort([], m)=m
205          | sort(e::es,m)=(case e          | sort(e::es,m)=(case e
206              of E.Add _ => sort (foundOp(e,es,m))              of E.Add _ => sort (foundOp(e,es,m))
207              | E.Sub _=>sort (foundOp(e, es,m))              | E.Sub _=>sort (foundOp(e, es,m))
208              | E.Prod p=>sort (p@es,m)              | E.Prod p=>(sort (p@es,m))
209              | E.Div _=>sort (foundOp(e, es,m))              | E.Div _=>sort (foundOp(e, es,m))
210              | E.Neg _=>sort (foundOp(e, es,m))              | E.Neg _=>sort (foundOp(e, es,m))
211              | E.Sum _=>sort (foundOp(e, es,m))              | E.Sum _=>sort (foundOp(e, es,m))
# Line 260  Line 227 
227          (z,(p',b',args'))          (z,(p',b',args'))
228      end      end
229    
230  fun handleSumProd(params, ind,sx,list1,args)=let  fun handleSumProd(paramsO, indO,sxO,list1O,argsO)=let
231      val id=ref (length params)      val id=ref (length paramsO)
232      val n=length ind      val n=length indO
233      val m=print (String.concat["\n In Sum Prod", "n",Int.toString(n)])      val m=print (String.concat["\n In Sum Prod", "n",Int.toString(n)])
234        val (params,ind,E.Sum(sx,E.Prod list1),args)=shiftHtM.clean(paramsO, indO,E.Sum(sxO,E.Prod list1O), argsO)
235    
236        fun g(lft,[],_)=(1,lft)
237            | g(lft,(E.V s,0,ub)::es,n')=
238      fun g(lft,[],_)=(1,lft) (*lft-outer index*)              if(s=n') then (g(lft@[ub+1],es,n'+1)) else (0,[])
         | g(lft,(E.V s,0,ub)::es,n')=if(s=n') then (print "match";g(lft@[ub],es,n'+1)) else (0,[])  
239          | g _ =(0,[]) (*Can't be split, weird bound*)          | g _ =(0,[]) (*Can't be split, weird bound*)
   
240      val (c,index')= g([],sx,n)      val (c,index')= g([],sx,n)
241    
242      in  case c      in  case c
# Line 290  Line 256 
256    
257    
258  fun genfn(id,Ein.EIN{params, index, body},args)= let  fun genfn(id,Ein.EIN{params, index, body},args)= let
259        val mm=print(P.printbody(body))
260      val notDone=([],(params,body,args))      val notDone=([],(params,body,args))
261    
262      fun gen body=(case body      fun gen body=(case body
263          of  E.Field _ =>raise Fail(concat["Invalid Field here "]   )          of  E.Field _ =>raise Fail(concat["Invalid Field here "]   )
264          | E.Partial _ =>raise Fail(concat["Invalid Partial here "]   )          | E.Partial _ =>raise Fail(concat["Invalid Partial here "]   )
# Line 305  Line 272 
272          | E.Prod(E.Img _  :: _)=>notDone          | E.Prod(E.Img _  :: _)=>notDone
273          | E.Neg(E.Neg e)=> gen e          | E.Neg(E.Neg e)=> gen e
274          | E.Neg e=>  handleNeg(params, index,e,args)          | E.Neg e=>  handleNeg(params, index,e,args)
275  | E.Add a => (print "Add";handleAdd(params, index,a,args))          | E.Add a => (handleAdd(params, index,a,args))
276          | E.Sub(E.Sub(a,b),E.Sub(c,d))=> gen(E.Sub(E.Add[a,d],E.Add[b,c]))          | E.Sub(E.Sub(a,b),E.Sub(c,d))=> gen(E.Sub(E.Add[a,d],E.Add[b,c]))
277          | E.Sub(E.Sub(a,b),e2)=>gen (E.Sub(a,E.Add[b,e2]))          | E.Sub(E.Sub(a,b),e2)=>gen (E.Sub(a,E.Add[b,e2]))
278          | E.Sub(e1,E.Sub(c,d))=>gen(E.Add([E.Sub(e1,c),d]))          | E.Sub(e1,E.Sub(c,d))=>gen(E.Add([E.Sub(e1,c),d]))
279  | E.Sub(e1,e2)=>(print "SUB";handleSub(params, index,e1,e2,args))          | E.Sub(e1,e2)=>(handleSub(params, index,e1,e2,args))
280          | E.Div(E.Div(a,b),E.Div(c,d))=> gen(E.Div(E.Prod[a,d],E.Prod[b,c]))          | E.Div(E.Div(a,b),E.Div(c,d))=> gen(E.Div(E.Prod[a,d],E.Prod[b,c]))
281          | E.Div(E.Div(a,b),c)=> gen(E.Div(a, E.Prod[b,c]))          | E.Div(E.Div(a,b),c)=> gen(E.Div(a, E.Prod[b,c]))
282          | E.Div(a,E.Div(b,c))=> gen(E.Div(E.Prod[a,c],b))          | E.Div(a,E.Div(b,c))=> gen(E.Div(E.Prod[a,c],b))
283          | E.Div(e1,e2)=>handleDiv(params, index,e1,e2,args)          | E.Div(e1,e2)=>handleDiv(params, index,e1,e2,args)
284  | E.Prod e=> (print "PROD ";handleProd(params, index,e,args))          | E.Prod e=> (handleProd(params, index,e,args))
   
285          | E.Sum(_,E.Prod(E.Img _ :: _ ))=>notDone          | E.Sum(_,E.Prod(E.Img _ :: _ ))=>notDone
286  | E.Sum(sx,E.Prod e)=>(print "CAT"; handleSumProd(params, index,sx,e,args))          | E.Sum(sx,E.Prod e)=>(handleSumProd(params, index,sx,e,args))
   
   
287          | _=> notDone          | _=> notDone
288      (*end case*))      (*end case*))
289    

Legend:
Removed from v.2554  
changed lines
  Added in v.2555

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