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

SCM Repository

[diderot] Diff of /branches/lamont/src/compiler/basis/basis-vars.sml
ViewVC logotype

Diff of /branches/lamont/src/compiler/basis/basis-vars.sml

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

trunk/src/compiler/basis/basis-vars.sml revision 1383, Thu Jun 23 20:24:04 2011 UTC branches/vis12/src/compiler/basis/basis-vars.sml revision 1945, Fri Jul 6 14:54:21 2012 UTC
# Line 56  Line 56 
56     *    r  -- real (tensor[])     *    r  -- real (tensor[])
57     *    t  -- tensor[shape]     *    t  -- tensor[shape]
58     *    f  -- field#k(d)[shape]     *    f  -- field#k(d)[shape]
59       *    d  -- ty{}
60       *    T  -- ty
61     *)     *)
62    
63      (* concatenation of sequences *)
64        val at_dT = polyVar (N.op_at, all([TK],
65              fn [Ty.TYPE tv] => let
66                  val seqTyc = Ty.T_DynSequence(Ty.T_Var tv)
67                  in
68                    [seqTyc, Ty.T_Var tv] --> seqTyc
69                  end))
70        val at_Td = polyVar (N.op_at, all([TK],
71              fn [Ty.TYPE tv] => let
72                  val seqTyc = Ty.T_DynSequence(Ty.T_Var tv)
73                  in
74                    [Ty.T_Var tv, seqTyc] --> seqTyc
75                  end))
76        val at_dd = polyVar (N.op_at, all([TK],
77              fn [Ty.TYPE tv] => let
78                  val seqTyc = Ty.T_DynSequence(Ty.T_Var tv)
79                  in
80                    [seqTyc, seqTyc] --> seqTyc
81                  end))
82    
83      val add_ii = monoVar(N.op_add, [Ty.T_Int, Ty.T_Int] --> Ty.T_Int)      val add_ii = monoVar(N.op_add, [Ty.T_Int, Ty.T_Int] --> Ty.T_Int)
84      val add_tt = polyVar(N.op_add, all([SK], fn [Ty.SHAPE dd] => let      val add_tt = polyVar(N.op_add, all([SK], fn [Ty.SHAPE dd] => let
85              val t = Ty.T_Tensor(Ty.ShapeVar dd)              val t = Ty.T_Tensor(Ty.ShapeVar dd)
# Line 170  Line 192 
192      val neq_rr = monoVar(N.op_neq, [Ty.realTy, Ty.realTy] --> Ty.T_Bool)      val neq_rr = monoVar(N.op_neq, [Ty.realTy, Ty.realTy] --> Ty.T_Bool)
193    
194    
195      val neg_i = monoVar(N.op_neg, [Ty.T_Int, Ty.T_Int] --> Ty.T_Bool)      val neg_i = monoVar(N.op_neg, [Ty.T_Int] --> Ty.T_Int)
196      val neg_t = polyVar(N.op_neg, all([SK],      val neg_t = polyVar(N.op_neg, all([SK],
197            fn [Ty.SHAPE dd] => let            fn [Ty.SHAPE dd] => let
198                val t = Ty.T_Tensor(Ty.ShapeVar dd)                val t = Ty.T_Tensor(Ty.ShapeVar dd)
# Line 207  Line 229 
229                  [t, t, Ty.realTy, Ty.realTy, Ty.realTy] --> t                  [t, t, Ty.realTy, Ty.realTy, Ty.realTy] --> t
230                end))                end))
231    
232      (* Eigenvalues/vectors of a matrix; we only support this operation on 2x2 and 3x3 matrices, so
233       * we overload the function.
234       *)
235        local
236          fun evals d = monoVar (N.fn_evals, [matrix d] --> Ty.T_Sequence(Ty.realTy, d))
237          fun evecs d = monoVar (N.fn_evecs, [matrix d] --> Ty.T_Sequence(tensor[d], d))
238        in
239        val evals2x2 = evals(Ty.DimConst 2)
240        val evecs2x2 = evecs(Ty.DimConst 2)
241        val evals3x3 = evals(Ty.DimConst 3)
242        val evecs3x3 = evecs(Ty.DimConst 3)
243        end
244    
245    
246    (***** non-overloaded operators, etc. *****)    (***** non-overloaded operators, etc. *****)
247    
248      val op_at = polyVar (N.op_at, all([DK, NK, SK],    (* C math functions *)
249        val mathFns : (MathFuns.name * Var.var) list = let
250              fun ty n = List.tabulate(MathFuns.arity n, fn _ => Ty.realTy) --> Ty.realTy
251              in
252                List.map (fn n => (n, monoVar(MathFuns.toAtom n, ty n))) MathFuns.allFuns
253              end
254    
255      (* pseudo-operator for probing a field *)
256        val op_probe = polyVar (N.op_at, all([DK, NK, SK],
257            fn [Ty.DIFF k, Ty.DIM d, Ty.SHAPE dd] => let            fn [Ty.DIFF k, Ty.DIM d, Ty.SHAPE dd] => let
258                val k = Ty.DiffVar(k, 0)                val k = Ty.DiffVar(k, 0)
259                val d = Ty.DimVar d                val d = Ty.DimVar d
# Line 248  Line 291 
291      val op_not = monoVar (N.op_not, [Ty.T_Bool] --> Ty.T_Bool)      val op_not = monoVar (N.op_not, [Ty.T_Bool] --> Ty.T_Bool)
292    
293    (* functions *)    (* functions *)
     val fn_atan2 = monoVar (N.fn_atan2, [Ty.realTy, Ty.realTy] --> Ty.realTy)  
   
     val fn_CL = monoVar (N.fn_CL, [tensor[N3, N3]] --> Ty.realTy)  
   
 (* the following is depreciated in favor of the infix operator *)  
     val fn_convolve = polyVar (N.fn_convolve, all([DK, NK, SK],  
             fn [Ty.DIFF k, Ty.DIM d, Ty.SHAPE dd] => let  
                 val k = Ty.DiffVar(k, 0)  
                 val d = Ty.DimVar d  
                 val dd = Ty.ShapeVar dd  
                 in  
                   [Ty.T_Kernel k, Ty.T_Image{dim=d, shape=dd}]  
                     --> field(k, d, dd)  
                 end))  
   
     val fn_cos = monoVar (N.fn_cos, [Ty.realTy] --> Ty.realTy)  
   
294      local      local
295        val crossTy = let        val crossTy = let
296              val t = tensor[N3]              val t = tensor[N3]
# Line 273  Line 299 
299              end              end
300      in      in
301      val op_cross = monoVar (N.op_cross, crossTy)      val op_cross = monoVar (N.op_cross, crossTy)
     val fn_cross = monoVar (N.fn_cross, crossTy)  
302      end      end
303    
   (* the depriciated 'dot' function *)  
     val fn_dot = polyVar (N.fn_dot, allNK(fn tv => let  
           val t = tensor[Ty.DimVar tv]  
           in  
             [t, t] --> Ty.realTy  
           end))  
   
304    (* the inner product operator (including dot product) is treated as a special case in the    (* the inner product operator (including dot product) is treated as a special case in the
305     * typechecker.  It is not included in the basis environment, but we define its type scheme     * typechecker.  It is not included in the basis environment, but we define its type scheme
306     * here.  There is an implicit constraint on its type to have the following scheme:     * here.  There is an implicit constraint on its type to have the following scheme:
# Line 294  Line 312 
312                  [Ty.T_Tensor(Ty.ShapeVar s1), Ty.T_Tensor(Ty.ShapeVar s2)]                  [Ty.T_Tensor(Ty.ShapeVar s1), Ty.T_Tensor(Ty.ShapeVar s2)]
313                    --> Ty.T_Tensor(Ty.ShapeVar s3)))                    --> Ty.T_Tensor(Ty.ShapeVar s3)))
314    
315    (* Eigenvalues of a matrix *)    (* the colon (or double-dot) product operator is treated as a special case in the
316      val fn_evals = polyVar (N.fn_trace, all([NK],     * typechecker.  It is not included in the basis environment, but we define its type
317              fn [Ty.DIM d] => let     * schemehere.  There is an implicit constraint on its type to have the following scheme:
318                  val d = Ty.DimVar d     *
319                  in     *     ALL[sigma1, d1, d2, sigma2] .
320                    [matrix d] --> Ty.T_Sequence(Ty.realTy, d)     *       tensor[sigma1, d1, d2] * tensor[d1, d2, sigma2] -> tensor[sigma1, sigma2]
321                  end))     *)
322        val op_colon = polyVar (N.op_colon, all([SK, SK, SK],
323                fn [Ty.SHAPE s1, Ty.SHAPE s2, Ty.SHAPE s3] =>
324                    [Ty.T_Tensor(Ty.ShapeVar s1), Ty.T_Tensor(Ty.ShapeVar s2)]
325                      --> Ty.T_Tensor(Ty.ShapeVar s3)))
326    
327    (* Eigenvectors of a matrix *)    (* load image from nrrd *)
328      val fn_evecs = polyVar (N.fn_trace, all([NK],      val fn_image = polyVar (N.fn_image, all([NK, SK],
329              fn [Ty.DIM d] => let              fn [Ty.DIM d, Ty.SHAPE dd] => let
330                  val d = Ty.DimVar d                  val d = Ty.DimVar d
331                    val dd = Ty.ShapeVar dd
332                  in                  in
333                    [matrix d] --> Ty.T_Sequence(tensor[d], d)                    [Ty.T_String] --> Ty.T_Image{dim=d, shape=dd}
334                  end))                  end))
335    
336      val fn_inside = polyVar (N.fn_inside, all([DK, NK, SK],      val fn_inside = polyVar (N.fn_inside, all([DK, NK, SK],
# Line 320  Line 343 
343                      --> Ty.T_Bool                      --> Ty.T_Bool
344                  end))                  end))
345    
346      val fn_load = polyVar (N.fn_load, all([NK, SK],    (* load dynamic sequence from nrrd *)
347              fn [Ty.DIM d, Ty.SHAPE dd] => let      val fn_load = polyVar (N.fn_load, all([TK],
348                  val d = Ty.DimVar d              fn [Ty.TYPE tv] => [Ty.T_String] --> Ty.T_DynSequence(Ty.T_Var tv)))
349                  val dd = Ty.ShapeVar dd  
350                  in      val fn_length = polyVar (N.fn_length, all([TK],
351                    [Ty.T_String] --> Ty.T_Image{dim=d, shape=dd}              fn [Ty.TYPE tv] => [Ty.T_DynSequence(Ty.T_Var tv)] --> Ty.T_Int))
                 end))  
352    
353      val fn_max = monoVar (N.fn_max, [Ty.realTy, Ty.realTy] --> Ty.realTy)      val fn_max = monoVar (N.fn_max, [Ty.realTy, Ty.realTy] --> Ty.realTy)
354      val fn_min = monoVar (N.fn_min, [Ty.realTy, Ty.realTy] --> Ty.realTy)      val fn_min = monoVar (N.fn_min, [Ty.realTy, Ty.realTy] --> Ty.realTy)
# Line 355  Line 377 
377                [vt1, vt2] --> mt                [vt1, vt2] --> mt
378              end              end
379      in      in
     val fn_outer = polyVar (N.fn_outer, all([NK, NK], mkOuter))  
380      val op_outer = polyVar (N.op_outer, all([NK, NK], mkOuter))      val op_outer = polyVar (N.op_outer, all([NK, NK], mkOuter))
381      end      end
382    
     val fn_pow = monoVar (N.fn_pow, [Ty.realTy, Ty.realTy] --> Ty.realTy)  
   
383      val fn_principleEvec = polyVar (N.fn_principleEvec, all([NK],      val fn_principleEvec = polyVar (N.fn_principleEvec, all([NK],
384              fn [Ty.DIM d] => let              fn [Ty.DIM d] => let
385                  val d = Ty.DimVar d                  val d = Ty.DimVar d
# Line 368  Line 387 
387                    [matrix d] --> tensor[d]                    [matrix d] --> tensor[d]
388                  end))                  end))
389    
     val fn_sin = monoVar (N.fn_sin, [Ty.realTy] --> Ty.realTy)  
   
     val fn_sqrt = monoVar (N.fn_sqrt, [Ty.realTy] --> Ty.realTy)  
   
     val fn_tan = monoVar (N.fn_tan, [Ty.realTy] --> Ty.realTy)  
   
390      val fn_trace = polyVar (N.fn_trace, all([NK],      val fn_trace = polyVar (N.fn_trace, all([NK],
391              fn [Ty.DIM d] => let              fn [Ty.DIM d] => [matrix(Ty.DimVar d)] --> Ty.realTy))
                 val d = Ty.DimVar d  
                 in  
                   [matrix d] --> Ty.realTy  
                 end))  
392    
393    (* kernels *)    (* kernels *)
394  (* FIXME: we should really get the continuity info from the kernels themselves *)  (* FIXME: we should really get the continuity info from the kernels themselves *)
# Line 403  Line 412 
412      val zero = polyVar (Atom.atom "$zero", all ([SK],      val zero = polyVar (Atom.atom "$zero", all ([SK],
413              fn [Ty.SHAPE dd] => [] --> Ty.T_Tensor(Ty.ShapeVar dd)))              fn [Ty.SHAPE dd] => [] --> Ty.T_Tensor(Ty.ShapeVar dd)))
414    
415      (* sequence subscript *)
416        val subscript = polyVar (Atom.atom "$sub", all ([TK, NK],
417                fn [Ty.TYPE tv, Ty.DIM d] =>
418                  [Ty.T_Sequence(Ty.T_Var tv, Ty.DimVar d), Ty.T_Int] --> Ty.T_Var tv))
419      end (* local *)      end (* local *)
420    end    end

Legend:
Removed from v.1383  
changed lines
  Added in v.1945

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