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

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

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

revision 2610, Fri May 2 18:31:56 2014 UTC revision 2611, Mon May 5 21:21:12 2014 UTC
# Line 10  Line 10 
10    
11  fun err str=raise Fail (String.concat["Ill-formed EIN Operator",str])  fun err str=raise Fail (String.concat["Ill-formed EIN Operator",str])
12    
13    (*Decide if two Eps changes to Deltas*)
14    (*Return:change, Deltas1, Deltas2 *)
15    fun doubleEps(E.Epsilon (a,b,c),E.Epsilon(d,e,f))=let
   
   
   
 (*remove eps Index*)  
   
 fun rmEpsIndex(i,[],[],[])= []  
     | rmEpsIndex(i,[],x,[])= [x]  
     | rmEpsIndex(i,[],x,e::es)= rmEpsIndex(i,e,[],es)@[x]  
     | rmEpsIndex(i,  ( c ,lb, ub)::b,x, es)=  
         if (i=c) then let  
                 val z=[(x@b)]  
                 in (case z of [] => es |_=>z@es) end  
         else rmEpsIndex(i,b,x@[(c ,lb, ub)],es)  
   
   
   
 fun doubleEps(count,E.Epsilon (a,b,c),E.Epsilon(d,e,f))=let  
16      (*Function is called when eps are being changed to deltas*)      (*Function is called when eps are being changed to deltas*)
17      fun createDeltas(i,s,t,u,v)= let      fun createDeltas(s,t,u,v)= let
         val c'= rmEpsIndex(E.V i,[],[],count)  
18          val d1=[E.Delta(E.V s,E.V u), E.Delta(E.V t,E.V v)]          val d1=[E.Delta(E.V s,E.V u), E.Delta(E.V t,E.V v)]
19          val d2= [E.Delta(E.V s,E.V v), E.Delta(E.V t,E.V u)]          val d2= [E.Delta(E.V s,E.V v), E.Delta(E.V t,E.V u)]
20    
21          in (1,c',d1,d2)          in (1,d1,d2)
22          end          end
23    
24      in if(a=d) then createDeltas(a,b,c,e,f)      in if(a=d) then createDeltas(b,c,e,f)
25          else if(a=e) then createDeltas(a,b,c,f,d)          else if(a=e) then createDeltas(b,c,f,d)
26          else if(a=f) then createDeltas(a,b,c,d,e)          else if(a=f) then createDeltas(b,c,d,e)
27          else if(b=d) then createDeltas(b,c,a,e,f)          else if(b=d) then createDeltas(c,a,e,f)
28          else if(b=e) then createDeltas(b,c,a,f,d)          else if(b=e) then createDeltas(c,a,f,d)
29          else if(b=f) then createDeltas(b,c,a,d,e)          else if(b=f) then createDeltas(c,a,d,e)
30          else if(c=d) then createDeltas(c,a,b,e,f)          else if(c=d) then createDeltas(a,b,e,f)
31          else if(c=e) then createDeltas(c,a,b,f,d)          else if(c=e) then createDeltas(a,b,f,d)
32          else if(c=f) then createDeltas(c,a,b,d,e)          else if(c=f) then createDeltas(a,b,d,e)
33          else (0,[],[],[])          else (0,[],[])
34      end      end
35    
36    
37    (*Distribute Eps*)
38  fun distEps([],eps,_,_)=(0,[],[],[],[])  (*Return: change,Rest of Eps, d1, d2,outer-summation, rest*)
39      | distEps([e],eps,_,_)=(0,[],[],[],[])  (*If we use the eps in the embedded summation, then we move sx to outer summation
40      | distEps(e1::e2::[],eps,c1::count,sx)=let  Otherwise keep the embedded summation term in "rest"
41          val(change,c',d1,d2)= doubleEps([c1@sx]@count,e1,e2)  *)
42          in (case change  
43          of 1=>(1, c', eps, d1,d2)  fun distributeEps(epsAll,sumexp)=let
44          |_=> (0,[],[],[],[])      (*M-Embedded summaiton is not used*)
45        val M=(0,[],[],[],[],[])
46    
47        fun distEps([],_)     = M
48            | distEps([e1],eps)=(
49                (case sumexp
50                of  [E.Sum(sx,E.Prod(e2::ps))] =>  (case doubleEps(e1,e2)
51                    of (1,d1,d2)    => (1, eps, d1,d2,sx, ps)
52                    | _             =>(0,[],[],[],[],[])
53          (*end case*))          (*end case*))
54          end              | _ => (0,[],[],[],[],[])))
55    
56      | distEps(e1::e2::current,eps,count,sx)=let          | distEps(e1::e2::current,eps) = ((case doubleEps(e1,e2)
57          val(change,c',d1,d2)= doubleEps(count,e1,e2)              of (1,d1,d2)    => (1, eps@current, d1,d2,[],sumexp)
58          in (case change              | _             => distEps(e2::current, eps@[e1])
59              of 1=>(1, c', eps@current, d1,d2)              (*end case*)))
60              |_=> distEps(e2::current, eps@[e1],count,sx)      in
61              (*end case*))          distEps(epsAll,[])
62          end          end
63    
64    
   
65  (* Transform eps to deltas*)  (* Transform eps to deltas*)
66  fun epsToDels(count,E.Prod e)= let  (*return: change, e', sx  *)
67      val (epsA,es,sx)=F.findeps([],e,[])  fun epsToDels e= let
68      val (change, s', eps,d1,d2)= distEps(epsA,[],count,sx)      val (epsAll,rest,sumexp)           = F.filterEps e
69      val deltas=E.Sub(E.Prod d1,E.Prod d2)      in (case (distributeEps(epsAll,sumexp))
70            of (0, _ , _ , _ , _ , _)  => (0,E.Const 0,[],epsAll,rest@sumexp)
71      in (case (change,eps,es)          | (change, epsUnused,d1,d2,sx,ps)  => let
72          of (0,_,_)=>(0,[],epsA,es)              val a=E.Prod(epsUnused@d1@rest@ps)
73          |(_,[],[]) =>(1,s',[deltas],[])              val b=E.Prod(epsUnused@d2@rest@ps)
74          | _ =>(1,s',[E.Sub( E.Prod(eps@d1@es), E.Prod(eps@d2@es))],[])              in
75                    (1,E.Sub(a,b),sx,[],[])
76                end
77          (*end case *))          (*end case *))
78      end      end
79    
80  (*Another strategy. Go through entire expression inside summation and jsut examine index to apply deltas*)  
81    
82  (* Apply deltas to tensors/fields*)  (* Apply deltas to tensors/fields*)
83  fun reduceDelta(c, eps, dels, es)=let  fun reduceDelta(eps, dels, es)=let
84      fun distribute(change,d,dels,[],done)=(change,dels@d,done)      fun distribute(change,d,dels,[],done)=(change,dels@d,done)
85          | distribute(change,[],[],e,done)=(change,[],done@e)          | distribute(change,[],[],e,done)=(change,[],done@e)
86          | distribute(change,[],dels,e::es,done)=distribute(change,dels,[],es,done@[e])          | distribute(change,[],dels,e::es,done)=distribute(change,dels,[],es,done@[e])
# Line 115  Line 106 
106              (*end case*))              (*end case*))
107    
108      val (change,dels',done)=distribute([],dels,[],es,[])      val (change,dels',done)=distribute([],dels,[],es,[])
109       fun m([],c')=c'  
110          | m(e::es,c')= let val s=rmEpsIndex(e,[],[],c')  
           in m(es, s) end  
     val index= m(change, c)  
111      in      in
112         (length change, index,E.Prod (eps@dels'@done))         (length change, E.Prod (eps@dels'@done))
113      end      end
114    
115    
   
116  fun matchEps(2,_,_,_)= 1 (*matched 2*)  fun matchEps(2,_,_,_)= 1 (*matched 2*)
117      | matchEps(num,_,_,[])=0      | matchEps(num,_,_,[])=0
118      | matchEps(0,_,_,[eps])=0      | matchEps(0,_,_,[eps])=0
119      | matchEps(num,[],rest,eps::epsx)=      | matchEps(num,[],rest,eps::epsx)=
120                  matchEps(num,rest,[],epsx)                  matchEps(num,rest,[],epsx)
121      | matchEps(num,E.V p::px,rest,eps::epsx)=      | matchEps(num,E.V p::px,rest,eps::epsx)=
122          if(p=eps) then (matchEps(num+1,rest@px,[],epsx))          if(p=eps) then matchEps(num+1,rest@px,[],epsx)
123          else matchEps(num,px,rest@[E.V p], eps::epsx)          else matchEps(num,px,rest@[E.V p], eps::epsx)
124      | matchEps(num,p::px,rest,eps)= matchEps(num,px,rest,eps)      | matchEps(num,p::px,rest,eps)= matchEps(num,px,rest,eps)
125    
   
126     end     end
127    
128    
   
129  end (* local *)  end (* local *)

Legend:
Removed from v.2610  
changed lines
  Added in v.2611

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