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

SCM Repository

[diderot] Diff of /branches/charisee/src/compiler/ein/mkoperators.sml
ViewVC logotype

Diff of /branches/charisee/src/compiler/ein/mkoperators.sml

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

revision 3047, Wed Mar 11 18:00:45 2015 UTC revision 3048, Wed Mar 11 20:00:27 2015 UTC
# Line 13  Line 13 
13      in      in
14    
15      fun specialize(alpha,inc)=  List.tabulate(length(alpha), (fn(x)=>E.V (x+inc)))      fun specialize(alpha,inc)=  List.tabulate(length(alpha), (fn(x)=>E.V (x+inc)))
16      fun sumIds(n,i)=List.tabulate(n, (fn v=>(E.V v, 0, i)))      fun sumIds(n,inc,alpha)=let
17            val vs=List.tabulate(n, (fn v=>E.V (v+inc)))
18            in ListPair.map  (fn(v,i)=>(v, 0, i-1))   (vs, alpha) end
19         fun sumIds2(n,i)=List.tabulate(n, (fn v=>(E.V v, 0, i)))
20    
21      (******************************* Add *****************************************)      (******************************* Add *****************************************)
22      val addRR = E.EIN{      val addRR = E.EIN{
# Line 354  Line 356 
356          end          end
357    
358      (******************** Norm  ********************************)      (******************** Norm  ********************************)
359    
360      (*get norm, but without the sqrt      (*get norm, but without the sqrt
361      * implemented as a summation over a modulate      * implemented as a summation over a modulate
362      *)      *)
363      fun magnitudeTT alpha =let      fun magnitudeTT alpha =let
          val i=List.hd alpha  
364           val expindex= specialize(alpha,0)           val expindex= specialize(alpha,0)
365           val sx= sumIds(length(alpha),i-1)           val sx= sumIds(length(alpha),0,alpha)
366           in E.EIN{           val e= E.EIN{
367              params = [E.TEN(1,alpha), E.TEN(1,alpha)],              params = [E.TEN(1,alpha), E.TEN(1,alpha)],
368              index = [],              index = [],
369              body = E.Sum(sx,              body = E.Sum(sx,
370              E.Prod[E.Tensor(0, expindex), E.Tensor(1, expindex)])              E.Prod[E.Tensor(0, expindex), E.Tensor(1, expindex)])
371              }              }
372            (*val _=print(String.concat["\ntesting mag tt",P.printerE e ])*)
373            in e
374          end          end
375    
376      fun magnitudeFF(dim,[]) =      fun magnitudeFF(dim,[]) =E.EIN{params = [E.FLD(dim),E.FLD(dim)],index = [],body =  E.Field(0, [])}
377          E.EIN{params = [E.FLD(dim)],index = [],body =  E.Field(0, [])}        | magnitudeFF(dim,alpha) =let
378         | magnitudeFF(dim,[i]) =          val expindex= specialize(alpha,0)
379            val sx= sumIds(length(alpha),0,alpha)
380            val e=
381              E.EIN{              E.EIN{
382                  params = [E.FLD(dim) ,E.FLD(dim)],                  params = [E.FLD(dim) ,E.FLD(dim)],
383                  index = [],                  index = [],
384                  body = E.Sqrt(E.Sum([(E.V 0,0,i-1)],                  body = E.Sqrt(E.Sum(sx, E.Prod[E.Field(0, expindex),E.Field(1,expindex)]))
                     E.Prod[E.Field(0, [E.V 0]),E.Field(1, [E.V 0])]  
                     ))  
385              }              }
386          | magnitudeFF(dim,[i,j]) =          (*val _=print(String.concat["\ntesting mag FF",P.printerE e ])*)
387            in e
388            end
389    
390        fun normalizeFF(dim,[]) =E.EIN{params = [E.FLD(dim)],index = [],body =  E.Field(0, [])}
391          | normalizeFF(dim,alpha) =let
392            val expindex= specialize(alpha,0)
393            (*shift indices in the inner product*)
394            val expindexDot= specialize(alpha,length(alpha))
395            val i=List.hd alpha
396            val sx= sumIds(length(alpha),length(alpha),alpha)
397            val f=E.Field(0, expindex)
398            val g=E.Field(1, expindexDot)
399            val e=
400              E.EIN{              E.EIN{
401                  params = [E.FLD(dim) ,E.FLD(dim)],                  params = [E.FLD(dim) ,E.FLD(dim)],
402                  index = [],                  index = [dim],
403                  body = E.Sqrt(E.Sum([(E.V 0,0,i-1),(E.V 1,0,j-1)],                  body = E.Prod[f,E.Div(E.Const 1,E.Sqrt(E.Sum(sx, E.Prod[g,g])))]
                     E.Prod[ E.Field(0, [E.V 0,E.V 1]), E.Field(1, [E.V 0,E.V 1])]  
                     ))  
             }  
   
     fun normalizeFF(dim,[i]) = let  
         val sx=[(E.V 0,0,i-1)]  
         val f=E.Field(0, [E.V 0])  
         in E.EIN{  
             params = [E.FLD(dim) ,E.FLD(dim)],index = [dim],  
             body = E.Prod[f,  
                 E.Div(E.Const 1,E.Sqrt(E.Sum(sx, E.Prod[f,f])))]  
404              }              }
405            (*val _=print(String.concat["\ntesting normalize FF",P.printerE e ])*)
406            in e
407          end          end
         | normalizeFF(dim,_) =raise Fail"unsupported normalize"  
408    
409      (************************* trace *************************)      (************************* trace *************************)
410      (* Trace: <M_{i, i}>  This one Sx represents both i's*)      (* Trace: <M_{i, i}>  This one Sx represents both i's*)

Legend:
Removed from v.3047  
changed lines
  Added in v.3048

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