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 1640, Wed Nov 16 02:19:51 2011 UTC branches/lamont/src/compiler/basis/basis-vars.sml revision 3272, Fri Oct 9 19:23:16 2015 UTC
# Line 53  Line 53 
53     * by the argument type signature, where     * by the argument type signature, where
54     *    i  -- int     *    i  -- int
55     *    b  -- bool     *    b  -- bool
56       *s  -- string
57     *    r  -- real (tensor[])     *    r  -- real (tensor[])
58     *    t  -- tensor[shape]     *    t  -- tensor[shape]
59     *    f  -- field#k(d)[shape]     *    f  -- field#k(d)[shape]
60       *    d  -- ty{}
61       *    T  -- ty
62     *)     *)
63    
64      (* concatenation of sequences *)
65        val at_dT = polyVar (N.op_at, all([TK],
66              fn [Ty.TYPE tv] => let
67                  val seqTyc = Ty.T_DynSequence(Ty.T_Var tv)
68                  in
69                    [seqTyc, Ty.T_Var tv] --> seqTyc
70                  end))
71        val at_Td = polyVar (N.op_at, all([TK],
72              fn [Ty.TYPE tv] => let
73                  val seqTyc = Ty.T_DynSequence(Ty.T_Var tv)
74                  in
75                    [Ty.T_Var tv, seqTyc] --> seqTyc
76                  end))
77        val at_dd = polyVar (N.op_at, all([TK],
78              fn [Ty.TYPE tv] => let
79                  val seqTyc = Ty.T_DynSequence(Ty.T_Var tv)
80                  in
81                    [seqTyc, seqTyc] --> seqTyc
82                  end))
83    
84      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)
85      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
86              val t = Ty.T_Tensor(Ty.ShapeVar dd)              val t = Ty.T_Tensor(Ty.ShapeVar dd)
# Line 70  Line 93 
93              in              in
94                [t, t] --> t                [t, t] --> t
95              end))              end))
96        val add_fr = polyVar(N.op_add, all([DK,NK], (* field + scalar *)
97              fn [Ty.DIFF k, Ty.DIM d] => let
98                val t = Ty.T_Field{diff = Ty.DiffVar(k, 0), dim = Ty.DimVar d, shape = Ty.Shape[]}
99                in
100                  [t, Ty.realTy] --> t
101                end))
102        val add_rf = polyVar(N.op_add, all([DK,NK], (* scalar + field *)
103              fn [Ty.DIFF k, Ty.DIM d] => let
104                val t = Ty.T_Field{diff = Ty.DiffVar(k, 0), dim = Ty.DimVar d, shape = Ty.Shape[]}
105                in
106                  [Ty.realTy, t] --> t
107                end))
108    
109      val sub_ii = monoVar(N.op_sub, [Ty.T_Int, Ty.T_Int] --> Ty.T_Int)      val sub_ii = monoVar(N.op_sub, [Ty.T_Int, Ty.T_Int] --> Ty.T_Int)
110      val sub_tt = polyVar(N.op_sub, all([SK], fn [Ty.SHAPE dd] => let      val sub_tt = polyVar(N.op_sub, all([SK], fn [Ty.SHAPE dd] => let
# Line 83  Line 118 
118              in              in
119                [t, t] --> t                [t, t] --> t
120              end))              end))
121        val sub_fr = polyVar(N.op_sub, all([DK,NK], (* field - scalar *)
122              fn [Ty.DIFF k, Ty.DIM d] => let
123                val t = Ty.T_Field{diff = Ty.DiffVar(k, 0), dim = Ty.DimVar d, shape = Ty.Shape[]}
124                in
125                  [t, Ty.realTy] --> t
126                end))
127        val sub_rf = polyVar(N.op_sub, all([DK,NK], (* scalar - field *)
128              fn [Ty.DIFF k, Ty.DIM d] => let
129                val t = Ty.T_Field{diff = Ty.DiffVar(k, 0), dim = Ty.DimVar d, shape = Ty.Shape[]}
130                in
131                  [Ty.realTy, t] --> t
132                end))
133    
134    (* note that we assume that operators are tested in the order defined here, so that mul_rr    (* note that we assume that operators are tested in the order defined here, so that mul_rr
135     * takes precedence over mul_rt and mul_tr!     * takes precedence over mul_rt and mul_tr!
# Line 126  Line 173 
173                [t, Ty.realTy] --> t                [t, Ty.realTy] --> t
174              end))              end))
175    
176      (* distance of tensors *)
177        local
178          val vec2Ty = let
179                val t = tensor[N2]
180                in
181                  [t, t] --> Ty.realTy
182                end
183           val vec3Ty = let
184                val t = tensor[N3]
185                in
186                  [t, t] --> Ty.realTy
187                end
188        in
189        val dist_t2  = monoVar (N.fn_dist, vec2Ty)
190        val dist_t3  = monoVar (N.fn_dist, vec3Ty)
191        end
192    
193    (* exponentiation; we distinguish between integer and real exponents to allow x^2 to be compiled    (* exponentiation; we distinguish between integer and real exponents to allow x^2 to be compiled
194     * as x*x.     * as x*x.
195     *)     *)
# Line 151  Line 215 
215                      --> field(k, d, dd)                      --> field(k, d, dd)
216                  end))                  end))
217    
218      (* curl on 2d and 3d vector fields *)
219        local
220          val diff0 = Ty.DiffConst 0
221          fun field' (k, d, dd) = field(k, Ty.DimConst d, Ty.Shape(List.map Ty.DimConst dd))
222        in
223    (* FIXME: we want to be able to require that k > 0, but we don't have a way to do that! *)
224        val curl2D = polyVar (N.op_curl, all([DK],
225              fn [Ty.DIFF k] =>
226                [field' (Ty.DiffVar(k, 0), 2, [2])] --> field' (diff0, 2, [])))
227        val curl3D = polyVar (N.op_curl, all([DK],
228              fn [Ty.DIFF k] =>
229                [field' (Ty.DiffVar(k, 0), 3, [3])] --> field' (diff0, 2, [3])))
230        end (* local *)
231    
232      val lt_ii = monoVar(N.op_lt, [Ty.T_Int, Ty.T_Int] --> Ty.T_Bool)      val lt_ii = monoVar(N.op_lt, [Ty.T_Int, Ty.T_Int] --> Ty.T_Bool)
233      val lt_rr = monoVar(N.op_lt, [Ty.realTy, Ty.realTy] --> Ty.T_Bool)      val lt_rr = monoVar(N.op_lt, [Ty.realTy, Ty.realTy] --> Ty.T_Bool)
234      val lte_ii = monoVar(N.op_lte, [Ty.T_Int, Ty.T_Int] --> Ty.T_Bool)      val lte_ii = monoVar(N.op_lte, [Ty.T_Int, Ty.T_Int] --> Ty.T_Bool)
# Line 207  Line 285 
285                  [t, t, Ty.realTy, Ty.realTy, Ty.realTy] --> t                  [t, t, Ty.realTy, Ty.realTy, Ty.realTy] --> t
286                end))                end))
287    
288        val all_rs = monoVar(N.fn_all, [Ty.realTy, Ty.T_String] --> Ty.realTy)
289    
290    
291    (* Eigenvalues/vectors of a matrix; we only support this operation on 2x2 and 3x3 matrices, so    (* Eigenvalues/vectors of a matrix; we only support this operation on 2x2 and 3x3 matrices, so
292     * we overload the function.     * we overload the function.
293     *)     *)
# Line 223  Line 304 
304    
305    (***** non-overloaded operators, etc. *****)    (***** non-overloaded operators, etc. *****)
306    
307      val op_at = polyVar (N.op_at, all([DK, NK, SK],    (* C math functions *)
308        val mathFns : (MathFuns.name * Var.var) list = let
309              fun ty n = List.tabulate(MathFuns.arity n, fn _ => Ty.realTy) --> Ty.realTy
310              in
311                List.map (fn n => (n, monoVar(MathFuns.toAtom n, ty n))) MathFuns.allFuns
312              end
313    
314      (* pseudo-operator for probing a field *)
315        val op_probe = polyVar (N.op_at, all([DK, NK, SK],
316            fn [Ty.DIFF k, Ty.DIM d, Ty.SHAPE dd] => let            fn [Ty.DIFF k, Ty.DIM d, Ty.SHAPE dd] => let
317                val k = Ty.DiffVar(k, 0)                val k = Ty.DiffVar(k, 0)
318                val d = Ty.DimVar d                val d = Ty.DimVar d
# Line 261  Line 350 
350      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)
351    
352    (* functions *)    (* functions *)
     val fn_atan2 = monoVar (N.fn_atan2, [Ty.realTy, Ty.realTy] --> 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)  
   
353      local      local
354        val crossTy = let        val crossTy = let
355              val t = tensor[N3]              val t = tensor[N3]
# Line 284  Line 358 
358              end              end
359      in      in
360      val op_cross = monoVar (N.op_cross, crossTy)      val op_cross = monoVar (N.op_cross, crossTy)
     val fn_cross = monoVar (N.fn_cross, crossTy)  
361      end      end
362    
363    (* the depriciated 'dot' function *)    (* Query functions *)
364      val fn_dot = polyVar (N.fn_dot, allNK(fn tv => let    (* distance of tensors *)
365            val t = tensor[Ty.DimVar tv]      local
366          val implicit = fn [Ty.TYPE tv] => [Ty.realTy] --> Ty.T_DynSequence(Ty.T_Var tv)
367          val realTy = fn [Ty.TYPE tv] => [Ty.realTy, Ty.realTy] --> Ty.T_DynSequence(Ty.T_Var tv)
368          val vec2Ty = let
369                val t = tensor[N2]
370            in            in
371              [t, t] --> Ty.realTy                fn [Ty.TYPE tv] => [t, Ty.realTy] --> Ty.T_DynSequence(Ty.T_Var tv)
372            end))              end
373           val vec3Ty = let
374                val t = tensor[N3]
375                in
376                  fn [Ty.TYPE tv] => [t, Ty.realTy] --> Ty.T_DynSequence(Ty.T_Var tv)
377                end
378        in
379        val fn_sphere_im  = polyVar (N.fn_sphere,all([TK], implicit))
380        val fn_sphere_r  = polyVar (N.fn_sphere,all([TK], realTy))
381        val fn_sphere_t2  = polyVar (N.fn_sphere,all([TK], vec2Ty))
382        val fn_sphere_t3 = polyVar (N.fn_sphere,all([TK], vec3Ty))
383        end
384    
385    
386    (* 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
387     * 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
# Line 305  Line 394 
394                  [Ty.T_Tensor(Ty.ShapeVar s1), Ty.T_Tensor(Ty.ShapeVar s2)]                  [Ty.T_Tensor(Ty.ShapeVar s1), Ty.T_Tensor(Ty.ShapeVar s2)]
395                    --> Ty.T_Tensor(Ty.ShapeVar s3)))                    --> Ty.T_Tensor(Ty.ShapeVar s3)))
396    
397      (* the colon (or double-dot) product operator is treated as a special case in the
398       * typechecker.  It is not included in the basis environment, but we define its type
399       * schemehere.  There is an implicit constraint on its type to have the following scheme:
400       *
401       *     ALL[sigma1, d1, d2, sigma2] .
402       *       tensor[sigma1, d1, d2] * tensor[d1, d2, sigma2] -> tensor[sigma1, sigma2]
403       *)
404        val op_colon = polyVar (N.op_colon, all([SK, SK, SK],
405                fn [Ty.SHAPE s1, Ty.SHAPE s2, Ty.SHAPE s3] =>
406                    [Ty.T_Tensor(Ty.ShapeVar s1), Ty.T_Tensor(Ty.ShapeVar s2)]
407                      --> Ty.T_Tensor(Ty.ShapeVar s3)))
408    
409      (* load image from nrrd *)
410        val fn_image = polyVar (N.fn_image, all([NK, SK],
411                fn [Ty.DIM d, Ty.SHAPE dd] => let
412                    val d = Ty.DimVar d
413                    val dd = Ty.ShapeVar dd
414                    in
415                      [Ty.T_String] --> Ty.T_Image{dim=d, shape=dd}
416                    end))
417    
418      val fn_inside = polyVar (N.fn_inside, all([DK, NK, SK],      val fn_inside = polyVar (N.fn_inside, all([DK, NK, SK],
419              fn [Ty.DIFF k, Ty.DIM d, Ty.SHAPE dd] => let              fn [Ty.DIFF k, Ty.DIM d, Ty.SHAPE dd] => let
420                  val k = Ty.DiffVar(k, 0)                  val k = Ty.DiffVar(k, 0)
# Line 315  Line 425 
425                      --> Ty.T_Bool                      --> Ty.T_Bool
426                  end))                  end))
427    
428      val fn_load = polyVar (N.fn_load, all([NK, SK],      (* Reduction Operations *)
429              fn [Ty.DIM d, Ty.SHAPE dd] => let      val fn_rMean = monoVar (N.fn_mean, [Ty.realTy] --> Ty.realTy)
430                  val d = Ty.DimVar d      val fn_rAll = monoVar (N.fn_all, [Ty.T_Bool] --> Ty.T_Bool)
431                  val dd = Ty.ShapeVar dd      val fn_rMax = monoVar (N.fn_max, [Ty.realTy] --> Ty.realTy)
432                  in      val fn_rMin = monoVar (N.fn_min, [Ty.realTy] --> Ty.realTy)
433                    [Ty.T_String] --> Ty.T_Image{dim=d, shape=dd}      val fn_rExists = monoVar (N.fn_exists, [Ty.T_Bool] --> Ty.T_Bool)
434                  end))      val fn_rProduct = monoVar (N.fn_product, [Ty.realTy] --> Ty.realTy)
435        val fn_rSum = monoVar (N.fn_sum, [Ty.realTy] --> Ty.realTy)
436        val fn_rVariance = monoVar (N.fn_variance, [Ty.realTy] --> Ty.realTy)
437    
438    
439      (* load dynamic sequence from nrrd *)
440        val fn_load = polyVar (N.fn_load, all([TK],
441                fn [Ty.TYPE tv] => [Ty.T_String] --> Ty.T_DynSequence(Ty.T_Var tv)))
442    
443        val fn_length = polyVar (N.fn_length, all([TK],
444                fn [Ty.TYPE tv] => [Ty.T_DynSequence(Ty.T_Var tv)] --> Ty.T_Int))
445    
446      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)
447      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 350  Line 470 
470                [vt1, vt2] --> mt                [vt1, vt2] --> mt
471              end              end
472      in      in
     val fn_outer = polyVar (N.fn_outer, all([NK, NK], mkOuter))  
473      val op_outer = polyVar (N.op_outer, all([NK, NK], mkOuter))      val op_outer = polyVar (N.op_outer, all([NK, NK], mkOuter))
474      end      end
475    
     val fn_pow = monoVar (N.fn_pow, [Ty.realTy, Ty.realTy] --> Ty.realTy)  
   
476      val fn_principleEvec = polyVar (N.fn_principleEvec, all([NK],      val fn_principleEvec = polyVar (N.fn_principleEvec, all([NK],
477              fn [Ty.DIM d] => let              fn [Ty.DIM d] => let
478                  val d = Ty.DimVar d                  val d = Ty.DimVar d
# Line 363  Line 480 
480                    [matrix d] --> tensor[d]                    [matrix d] --> tensor[d]
481                  end))                  end))
482    
     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)  
   
483      val fn_trace = polyVar (N.fn_trace, all([NK],      val fn_trace = polyVar (N.fn_trace, all([NK],
484              fn [Ty.DIM d] => [matrix(Ty.DimVar d)] --> Ty.realTy))              fn [Ty.DIM d] => [matrix(Ty.DimVar d)] --> Ty.realTy))
485    
486        val fn_transpose = polyVar (N.fn_transpose, all([NK, NK],
487                fn [Ty.DIM d1, Ty.DIM d2] =>
488                  [tensor[Ty.DimVar d1, Ty.DimVar d2]] --> tensor[Ty.DimVar d2, Ty.DimVar d1]))
489    
490    (* kernels *)    (* kernels *)
491  (* FIXME: we should really get the continuity info from the kernels themselves *)  (* FIXME: we should really get the continuity info from the kernels themselves *)
492      val kn_bspln3 = monoVar (N.kn_bspln3, Ty.T_Kernel(Ty.DiffConst 2))      val kn_bspln3 = monoVar (N.kn_bspln3, Ty.T_Kernel(Ty.DiffConst 2))
493      val kn_bspln5 = monoVar (N.kn_bspln5, Ty.T_Kernel(Ty.DiffConst 4))      val kn_bspln5 = monoVar (N.kn_bspln5, Ty.T_Kernel(Ty.DiffConst 4))
494        val kn_c4hexic = monoVar (N.kn_c4hexic, Ty.T_Kernel(Ty.DiffConst 4))
495      val kn_ctmr = monoVar (N.kn_ctmr, Ty.T_Kernel(Ty.DiffConst 1))      val kn_ctmr = monoVar (N.kn_ctmr, Ty.T_Kernel(Ty.DiffConst 1))
496      val kn_tent = monoVar (N.kn_tent, Ty.T_Kernel(Ty.DiffConst 0))      val kn_tent = monoVar (N.kn_tent, Ty.T_Kernel(Ty.DiffConst 0))
497    (* kernels with false claims of differentiability, for pedagogy *)    (* kernels with false claims of differentiability, for pedagogy *)
# Line 398  Line 514 
514      val subscript = polyVar (Atom.atom "$sub", all ([TK, NK],      val subscript = polyVar (Atom.atom "$sub", all ([TK, NK],
515              fn [Ty.TYPE tv, Ty.DIM d] =>              fn [Ty.TYPE tv, Ty.DIM d] =>
516                [Ty.T_Sequence(Ty.T_Var tv, Ty.DimVar d), Ty.T_Int] --> Ty.T_Var tv))                [Ty.T_Sequence(Ty.T_Var tv, Ty.DimVar d), Ty.T_Int] --> Ty.T_Var tv))
517    
518        val dynSubscript = polyVar (Atom.atom "$dynsub", all ([TK],
519                fn [Ty.TYPE tv] => [Ty.T_DynSequence(Ty.T_Var tv), Ty.T_Int] --> Ty.T_Var tv))
520    
521      end (* local *)      end (* local *)
522    end    end

Legend:
Removed from v.1640  
changed lines
  Added in v.3272

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