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

SCM Repository

[diderot] Diff of /branches/charisee_dev/src/compiler/mid-to-low/evalKrn-set.sml
ViewVC logotype

Diff of /branches/charisee_dev/src/compiler/mid-to-low/evalKrn-set.sml

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

revision 3394, Tue Nov 10 17:42:19 2015 UTC revision 3395, Tue Nov 10 18:23:07 2015 UTC
# Line 112  Line 112 
112      * Note that the coeffient vectors are flipped (cf high-to-low/probe.sml).      * Note that the coeffient vectors are flipped (cf high-to-low/probe.sml).
113      *)      *)
114      fun expandEvalKernel (setOrig,pre,d, h, k, x) = let      fun expandEvalKernel (setOrig,pre,d, h, k, x) = let
115        val _="\n*********************\n"
116           val {isCont, segs} = Kernel.curve (h, k)           val {isCont, segs} = Kernel.curve (h, k)
117           (* degree of polynomial *)           (* degree of polynomial *)
118           val deg = List.length(hd segs) - 1           val deg = List.length(hd segs) - 1
# Line 123  Line 124 
124           val coeffs = List.tabulate (deg+1,fn i => Var.new("P"^Int.toString i, ty))           val coeffs = List.tabulate (deg+1,fn i => Var.new("P"^Int.toString i, ty))
125    
126          (* code to define the coefficient vectors *)          (* code to define the coefficient vectors *)
127            (*
128          val coeffVecs = let          val coeffVecs = let
129              fun mk (x, (i, code)) = let              fun mk (x, (i, code)) = let
130                  val lits = List.tabulate(d, coefficient i)                  val lits = List.tabulate(d, coefficient i)
131                  val vars = List.tabulate(d, fn _ => Var.new("_f", DstTy.realTy))                  val vars = List.tabulate(d, fn _ => Var.new("_f", DstTy.realTy))
132                  val code =                (*  val code =
133                      ListPair.map (fn (x, lit) => (x, DstIL.LIT lit)) (vars, lits) @(x, DstIL.CONS(Var.ty x, vars)) :: code                      ListPair.map (fn (x, lit) => (x, DstIL.LIT lit)) (vars, lits) @(x, DstIL.CONS(Var.ty x, vars)) :: code
134                        *)
135    
136                        val code0 =ListPair.map (fn (x, lit) => (x, DstIL.LIT lit)) (vars, lits)
137                        val code =code0@(x, DstIL.CONS(Var.ty x, vars)) :: code
138                        val _ = List.map (fn e=>print(LowToString.toStringAll(LowILTypes.realTy, DstIL.ASSGN e))) [(x,DstIL.CONS(Var.ty x, vars))]
139                  in                  in
140                      (i-1, code)                      (i-1, code)
141                  end                  end
# Line 136  Line 143 
143                  #2 (List.foldr mk (deg, []) coeffs)                  #2 (List.foldr mk (deg, []) coeffs)
144              end              end
145    
146    
147             *)
148    
149             fun filterLit([],vars,code,opset)=(vars,code,opset)
150             | filterLit((lhs,rhs)::es,vars,code,opset)=let
151    
152               val (opset,var) = lowSet.filter(opset,(lhs,rhs))
153               in (case var
154                    of NONE=> filterLit(es,vars@[lhs], code@[(lhs, rhs)],opset)
155                    | SOME v =>filterLit(es,vars@[v],code,opset)
156                (*end case*))
157              end
158    
159             val (coeffVecs,setOrig) = let
160             fun mk (x, (i::xs, code,opset)) = let
161                    val lits = List.tabulate(d, coefficient i)
162                    val vars = List.tabulate(d, fn _ => Var.new("_f", DstTy.realTy))
163    
164    
165                    val code0 =ListPair.map (fn (x, lit) => (x, DstIL.LIT lit)) (vars, lits)
166                    val (vars,code0,opset)=filterLit(code0,[],[],opset)
167    
168                    val code =code@code0@[(x, DstIL.CONS(Var.ty x, vars))]
169    
170    
171    
172                    val _ = List.map (fn e=>(LowToString.toStringAll(LowILTypes.realTy, DstIL.ASSGN e))) [(x,DstIL.CONS(Var.ty x, vars))]
173                    in
174                        (xs, code,opset)
175                    end
176                val n=List.tabulate(deg+1, fn e=>e )
177                val (a,b,c)=(List.foldr mk (n, [],setOrig) (List.rev coeffs))
178                in
179                    (b,c)
180                end
181    
182    
183    
184    
185           val coeffVecsCode=List.map (fn(x,y)=>DstIL.ASSGN (x,y)) coeffVecs           val coeffVecsCode=List.map (fn(x,y)=>DstIL.ASSGN (x,y)) coeffVecs
186    
187    
188             fun getSet([],done,opset,cnt)=(done,opset,cnt)
189               | getSet( DstIL.ASSGN(lhs,rhs)::es,done,opset,cnt)=let
190                val (opset,var) = lowSet.filter(opset,(lhs,rhs))
191                    in  (case var
192                        of NONE => getSet(es,done@[DstIL.ASSGN(lhs,rhs)], opset,cnt)
193                            | SOME v=> (("TASH:replacing"^DstIL.Var.toString(lhs));getSet(es,done@[DstIL.ASSGN(lhs,DstIL.VAR v)], opset,cnt+1))
194                                (*end case*))
195                    end
196               | getSet (e1::es, done, opset,cnt)=getSet(es,done@[e1],opset,cnt)
197          (*          (*
198             val (coeffVecsCode,setOrig,cnt)=getSet(coeffVecsCode, [],setOrig,0)
199    
200          fun q(setT,done,[])=(setT,done)           val _ =("\nTASHreplaced"^Int.toString(cnt))
201            | q(setT,done,(lhs,rhs)::es)=           *)
             let  
                 val (setA, vA,A )=H.plugin(setT,Var.ty lhs,lhs,rhs)  
                 in q(setA,done@A,es)  end  
202    
203    
         val coeffVecs=List.rev coeffVecs  
         val (setOrig,coeffVecsCode) = q(setOrig,[], coeffVecs)  
         val coeffVecsCode=List.rev coeffVecsCode  
204    
205  *)       val _ = List.map (fn e=>(LowToString.toStringAll(LowILTypes.realTy,e))) coeffVecsCode
206    
207    
208          (*get dot product and addition of list of coeffs*)          (*get dot product and addition of list of coeffs*)
209           fun mkdot(setO,[e2,e1],code)=let           fun mkdot(setO,[e2,e1],code)=let
# Line 168  Line 221 
221            | mkdot (setO,[e1],[])= mkProdVec(setO,d,[x,e1])            | mkdot (setO,[e1],[])= mkProdVec(setO,d,[x,e1])
222            | mkdot _ = raise Fail "0 or 1 item in Kernel coeffs"            | mkdot _ = raise Fail "0 or 1 item in Kernel coeffs"
223          val (setC,vC,code)= mkdot(setOrig,List.rev coeffs, [])          val (setC,vC,code)= mkdot(setOrig,List.rev coeffs, [])
224            val _ =(String.concat["\n coeffVecs code :",Int.toString(length(coeffVecsCode))," other code code: ",Int.toString(length(code))])
225          in          in
226              (setC,vC,coeffVecsCode@code)              (setC,vC,coeffVecsCode@code)
227          end          end

Legend:
Removed from v.3394  
changed lines
  Added in v.3395

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