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

SCM Repository

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

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

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

revision 3997, Sun Jun 19 15:55:49 2016 UTC revision 3998, Sun Jun 19 17:12:03 2016 UTC
# Line 120  Line 120 
120              index = [],              index = [],
121              body = E.Opn(E.Prod,[ E.Tensor(0, []), E.Tensor(1, [])])              body = E.Opn(E.Prod,[ E.Tensor(0, []), E.Tensor(1, [])])
122          }          }
   
123       (* scalar times tensor product: <s * T_{\alpha}>_{\alpha} *)       (* scalar times tensor product: <s * T_{\alpha}>_{\alpha} *)
124      fun mulRT alpha = let      fun mulRT alpha = let
125          val expindex= specialize(alpha,0)          val expindex= specialize(alpha,0)
# Line 131  Line 130 
130                  body = E.Opn(E.Prod,[E.Tensor(0, []),  E.Tensor(1, expindex)])                  body = E.Opn(E.Prod,[E.Tensor(0, []),  E.Tensor(1, expindex)])
131              }              }
132          end          end
   
133      fun mulRF(dim,shape) =let      fun mulRF(dim,shape) =let
134           val  expindex= specialize(shape,0)           val  expindex= specialize(shape,0)
135           in E.EIN{           in E.EIN{
# Line 140  Line 138 
138               body = E.Opn(E.Prod,[E.Lift( E.Tensor(0,[])), E.Field(1,expindex)])               body = E.Opn(E.Prod,[E.Lift( E.Tensor(0,[])), E.Field(1,expindex)])
139               }               }
140           end           end
   
   
141      fun mulST(dim,shape) =let      fun mulST(dim,shape) =let
142           val  expindex= specialize(shape,0)           val  expindex= specialize(shape,0)
143           in E.EIN{           in E.EIN{
# Line 150  Line 146 
146              body = E.Opn(E.Prod,[E.Lift( E.Tensor(0,expindex)), E.Field(1,[])])              body = E.Opn(E.Prod,[E.Lift( E.Tensor(0,expindex)), E.Field(1,[])])
147              }              }
148           end           end
   
   
   
149      fun mulSS dim = E.EIN{      fun mulSS dim = E.EIN{
150               params = [E.FLD(dim),E.FLD(dim)],               params = [E.FLD(dim),E.FLD(dim)],
151               index = [],               index = [],
# Line 195  Line 188 
188               }               }
189           end           end
190    
191        fun divTS(dim, shape) = let
192            val expindex = specialize(shape,0)
193            in E.EIN{
194                params = [E.TEN(subst_flag(), shape), E.FLD(dim)],
195                index = shape,
196                body = E.Op2(E.Div, E.Lift(E.Tensor(0, expindex)), E.Field(1, []))
197                }
198             end
199    
200    
201      fun divSS dim = E.EIN{      fun divSS dim = E.EIN{
202           params = [E.FLD(dim),E.FLD(dim)],           params = [E.FLD(dim),E.FLD(dim)],
203           index = [],           index = [],
# Line 745  Line 748 
748      val atanR = op1Fn E.ArcTangent      val atanR = op1Fn E.ArcTangent
749      end (* local *)      end (* local *)
750    
751      (************************* other tensor ops *************************)      (*************************  modulate *************************)
752      fun modulate dim =E.EIN{      fun modulateTT shape =
753          params = [E.TEN(subst_flag(),[dim]), E.TEN(subst_flag(),[dim])],          E.EIN{
754          index = [dim],              params = [E.TEN(subst_flag(), shape), E.TEN(subst_flag(), shape)],
755                index = shape,
756          body = E.Opn(E.Prod,[E.Tensor(0, [E.V 0]), E.Tensor(1, [E.V 0])])          body = E.Opn(E.Prod,[E.Tensor(0, [E.V 0]), E.Tensor(1, [E.V 0])])
757      }      }
758    
759        fun modulateFF(shape, dim)  = let
760            val expindex = specialize(shape, 0)
761            in
762                E.EIN{
763                    params = [E.FLD(dim), E.FLD(dim)],
764                    index = shape,
765                    body = E.Opn(E.Prod,[E.Field(0, expindex), E.Field(1, expindex)])
766                }
767            end
768        fun modulateTF(shape, dim)  = let
769            val expindex = specialize(shape, 0)
770            in
771                E.EIN{
772                    params = [E.TEN(subst_flag(), shape), E.FLD(dim)],
773                    index = shape,
774                    body = E.Opn(E.Prod,[E.Tensor(0, expindex), E.Field(1, expindex)])
775                    }
776            end
777        fun modulateFT(shape, dim)  = let
778            val expindex = specialize(shape, 0)
779            in
780                E.EIN{
781                    params = [E.FLD(dim), E.TEN(subst_flag(), shape)],
782                    index = shape,
783                    body = E.Opn(E.Prod,[E.Field(0, expindex), E.Tensor(1, expindex)])
784                }
785            end
786    
787         (************************* other tensor ops *************************)
788      fun identity dim =E.EIN{      fun identity dim =E.EIN{
789          params = [],index = [dim,dim], body = E.G(E.Delta(E.V(0), E.V(1)))          params = [],index = [dim,dim], body = E.G(E.Delta(E.V(0), E.V(1)))
790      }      }
791    
792      fun slice (argTy,mask,const,rstTy) =let      fun sliceT (mask, const, rstTy, argTy) = let
793        fun fg e = String.concat(List.map (fn e => Int.toString(e)^",") e)
794        val _ = print(String.concat["mask:",fg const, "argTy:", fg argTy,"rstTy:", fg rstTy])
795    
796          fun iter ([],_,cnt)=[]          fun iter ([],_,cnt)=[]
797           | iter(true::es,c::cs,cnt)=[mkSxSingle c]@iter(es,cs,cnt)          | iter(true::es, c::cs, cnt)=(mkSxSingle c)::iter(es, cs, cnt)
798           |iter(false::es,cs,cnt)=[E.V cnt]@iter(es,cs,cnt+1)          |iter(false::es, cs, cnt)= (E.V cnt)::iter(es, cs, cnt+1)
799          val ix=iter(mask,const,0)          val ix=iter(mask,const,0)
800          in          val ein0 = E.EIN{params = [E.TEN(subst_flag(), argTy)], index = rstTy, body = E.Tensor(0, ix)}
801              E.EIN{  params = [E.TEN(subst_flag(),argTy)],index = rstTy,body = E.Tensor(0, ix)}  
802          end          in ein0 end
803    
804        fun sliceF (mask, const, rstTy, dim) = let
805            fun iter ([], _, cnt) = []
806            | iter(true::es, c::cs, cnt)=(mkSxSingle c)::iter(es, cs, cnt)
807            | iter(false::es, cs, cnt)=(E.V cnt)::iter(es, cs, cnt+1)
808            val ix = iter(mask, const,0 )
809            val ein0 =  E.EIN{params = [E.FLD(dim)], index = rstTy, body = E.Field(0, ix)}
810    
811            in ein0 end
812    
813      (******************** other field ops  ********************************)      (******************** other field ops  ********************************)
814      (*FLD here is bounded to image field, and dimension of h*)      (*FLD here is bounded to image field, and dimension of h*)

Legend:
Removed from v.3997  
changed lines
  Added in v.3998

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