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

SCM Repository

[diderot] View of /branches/charisee/src/compiler/ein/operators.sml
ViewVC logotype

View of /branches/charisee/src/compiler/ein/operators.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2496 - (download) (annotate)
Tue Oct 29 05:29:46 2013 UTC (5 years, 10 months ago) by cchiw
File size: 7287 byte(s)
changes to high-to-mid
(* examples.sml
 *
 * COPYRIGHT (c) 2012 The Diderot Project (http://diderot-language.cs.uchicago.edu)
 * All rights reserved.
 *)

structure Operators = struct

    local
    structure G = GenericEin
    structure E = Ein
    structure S = Specialize
    structure P = Printer
    in
 
 (***************************Generic Operators *********************************)
 


 
 
    (* Adding tensors : < X{\alpha} + Y_{\alpha}>_{\alpha} *)
val addTensor = G.EIN{
     params = [G.TEN, G.TEN],
     index = [G.MX],
     body = G.Add[
        G.Tensor(0, [G.V(0)]),
        G.Tensor(1, [G.V(0)])
     ]
}
    
    (* Subtracting tensors *)
val subTensor = G.EIN{
    params = [G.TEN, G.TEN],
    index = [G.MX],
    body = G.Sub(G.Tensor(0, [G.V(0)]), G.Tensor(1, [G.V(0)]))
}
    
    
        
    (* Identiy: <\delta_{i j}>_{i j}  *)
val identity = G.EIN{
        params = [],
        index = [G.IX,G.IX],       (*MX-i then MX-j*)
        body = G.Delta(G.V(0), G.V(1))
}
    
    (* Trace: <M_{i, i}>  This one Sx represents both i's*)
val trace = G.EIN{
        params = [G.TEN],         (* M *)
        index = [G.SX],           (* i *)
        body = G.Sum([G.V 0],G.Tensor(0, [G.V 0, G.V 0]))
}
        
        
        (* scalar times tensor product: <s * T_{\alpha}>_{\alpha} *)
val scaleTensor = G.EIN{
        params = [G.TEN, G.TEN],    (* s and T *)
        index = [G.MX],           (* \alpha *)
        body = G.Prod[ G.Tensor(0, []),  G.Tensor(1, [G.V(0)])  ]
}
        
val divideTensor = G.EIN{
        params = [G.TEN,G.TEN],
        index = [G.MX],
        body = G.Div(G.Tensor(0, [G.V(0)]), G.Tensor(1, []))
}
    
        (* generic inner product: <T_{\alpha i} * T_{i \beta}>_{\alpha \beta} *)
val innerProduct = G.EIN{
            params = [G.TEN, G.TEN],              (* T and T' *)
            index = [G.MX, G.MX, G.SX],   (* \alpha \beta, i *)
            body = G.Sum([G.V 2], G.Prod[
            G.Tensor(0, [G.V(0),G.V(2)]),   (* T_{\alpha i} *)
            G.Tensor(1, [G.V(2),G.V(1)])    (* T'_{i \beta} *)
            ])
 }
            
            
            
            (*  <T_{\alpha i j} * B{i j \beta }>_\alpha \beta       *)
val doubleDot= G.EIN{
            params = [G.TEN,G.TEN],
            index = [G.MX, G.MX, G.SX, G.SX],
            body = G.Sum([G.V 2, G.V 3],G.Prod[
            G.Tensor(0, [G.V(0),G.V(2),G.V(3)]),
            G.Tensor(1,[G.V(2),G.V(3),G.V(1)])
            ])
}
            
        (*OuterProduct can between vectors and Tensors
            A_i T_jk=> P_ijk
            T_ij A_k=>P_ijk
    *)
    (*Vector Examples : <T_i * T_j>_ij*)
val outerProduct = G.EIN{
    params = [G.TEN, G.TEN],
    index= [G.IX, G.IX],
    body= G.Prod[G.Tensor(0, [G.V(0)]), (* T_i *)G.Tensor(1, [G.V(1)]) (* T_j  *)]
}
                
val transpose = G.EIN{
    params = [G.TEN],
    index= [G.IX,G.IX],
    body= G.Tensor(0, [G.V 1,G.V 0])
}
        
val negTensor=G.EIN{
        params = [G.TEN],
        index = [G.MX],
        body = G.Neg(G.Tensor(0, [G.V 0]))
        }
     
   (*modulate*)
(* generic mod <T_{\alpha} * T_{ \alpha}>_{\alpha } *)
val modulate = G.EIN{
        params = [G.TEN, G.TEN],              (* T and T' *)
            index = [G.MX],   (* \alpha  *)
            body = G.Prod[
            G.Tensor(0, [G.V(0)]),   (* T_{\alpha } *)
            G.Tensor(1, [G.V(0)])    (* T'_{\alpha} *)
            ]
    }
            
 (*************************Tensor and Fields********************************)
val addTenField = G.EIN{
    params = [G.TEN,G.FLD],
    index = [],
    body = G.Add[G.Tensor(0, []),G.Field(1, [])]
}
                
val subTenField = G.EIN{
    params = [G.TEN,G.FLD],
    index = [],
    body = G.Add[G.Tensor(0, []),G.Neg(G.Field(1, []))]
}
    
    
val subFieldTen = G.EIN{
    params = [G.TEN,G.FLD],
    index = [],
    body = G.Sub(G.Field(1, []),G.Tensor(0, []))
}
    
                
 (************************* Fields ******************************)
    
(* Adding Fields : < F{\alpha} + G_{\alpha}>_{\alpha} *)
val addField = G.EIN{
    params = [G.FLD,G.FLD], (*changed from tensor to field*)
    index = [G.MX],
    body = G.Add[G.Field(0, [G.V(0)]),G.Field(1, [G.V(0)])]
}
  
        
(* Subtracting Fields *)
val subField = G.EIN{
    params = [G.FLD, G.FLD],
    index = [G.MX],
    body = G.Sub(G.Field(0, [G.V(0)]), G.Field(1, [G.V(0)]))
}



    

    
val scaleField = G.EIN{
    params = [G.TEN, G.FLD],    (* s and T *)
    index = [G.MX],           (* \alpha *)
    body = G.Prod[ G.Tensor(0, []),  G.Field(1,[G.V(0)])  ]
}
    
    
        
        
val divideField = G.EIN{
    params = [G.FLD],
    index = [G.MX],
    body = G.Div(G.Field(0, [G.V(0)]), G.Tensor(1, []))
}
    
    
val negField=G.EIN{
    params = [G.FLD],
    index = [G.MX],
    body = G.Neg(G.Field(0, [G.V 0]))
}

    
(*< d F /  d_i>_i *)
val Grad=G.EIN{
    params = [G.FLD],
    index = [G.MX],
    body = G.Apply( G.Partial([G.V(0)]),G.Field(0,[]))
}
    

(*  <d F_i /d_i> *)
val Divergence= G.EIN{
    params = [G.FLD],
    index = [G.SX],
    body = G.Sum([G.V 0],G.Apply( G.Partial([G.V(0)]),G.Field(0,[G.V(0)])))
}
    


(*FLD here is bounded to image field, and dimension of h*)
val conv = G.EIN{
    params = [G.FLD,G.TEN],
    index = [G.MX],
    body= G.Conv(0,[G.V(0)],1,[])
}
 
    val conv2 = G.EIN{
    params = [G.FLD,G.TEN],
    index = [G.MX,G.MX],
    body= G.Conv(0,[G.V(0)],1,[G.V(1)])
    }
    

    
    
    (* Probe: <F(x)>_{\alpha}   *)
val probe = G.EIN{
        params = [G.FLD,G.TEN],
        index= [G.MX,G.MX],
        body= G.Probe(G.Field(0, [G.V(0)]), G.Tensor(0,[G.V(1)]))
        (* F_{\alpha}  Tensor1 is position*)
}

(***************************Specialized Terms*********************************)
(*crossProduct is on 3D vectors *)
val crossProduct = E.EIN{
    params = [E.TEN, E.TEN],
    index= [E.IX(3),E.SX(0,3), E.SX(0,3)],
    body=E.Prod[ E.Epsilon(0, 1, 2), E.Tensor(0, [E.V 1]),  E.Tensor(1, [E.V 2 ]) ]
    }
        

        
(*(F_y/dx - F_x/dy )k*)
        
 val Curl2d=E.EIN{
        params = [E.FLD 2],
        index = [],
        body = E.Sub(E.Apply(E.Partial([E.C 0]), E.Field(0,[E.C 1])),
                     E.Apply(E.Partial([E.C 1]), E.Field(0,[E.C 0])))
    }



val Curl3d=E.EIN{
        params = [E.TEN],
        index = [E.IX(3), (E.SX(0,3)), E.SX(0,3)],
        body = E.Sum([E.V 1, E.V 2],E.Apply( E.Partial([E.V 1]), E.Prod[E.Epsilon(0, 1, 2), E.Field(0,[E.V 2])]))
    }
        
        (* Add Scalars*)
val addScalar = E.EIN{
        params = [E.TEN, E.TEN],
        index = [],
        body = E.Add[ E.Tensor(0, []), E.Tensor(1, [])]
}
        
        
        (* Subtract Scalars*)
val subScalar = E.EIN{
        params = [E.TEN, E.TEN],
        index = [],
        body = E.Sub( E.Tensor(0, []), E.Tensor(1, []))
}
  
        (* Divide Scalars*)
val divScalar = E.EIN{
        params = [E.TEN, E.TEN],
        index = [],
        body = E.Div( E.Tensor(0, []), E.Tensor(1, []))
        }
        
        
        (* Product Scalars*)
        val prodScalar = E.EIN{
        params = [E.TEN, E.TEN],
        index = [],
        body = E.Prod[ E.Tensor(0, []), E.Tensor(1, [])]
        }
        
(***************************************************************)

  end; (* local *)

    end (* local *)

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