Home My Page Projects Code Snippets Project Openings diderot

# SCM Repository

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

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

branches/vis12/src/compiler/basis/basis-vars.sml revision 1926, Sat Jun 23 18:01:57 2012 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]
# Line 92  Line 93
93              in              in
94                [t, t] --> t                [t, t] --> t
95              end))              end))
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))
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 105  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 148  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 173  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 229  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
293     *)     *)
# Line 301  Line 360
360      val op_cross = monoVar (N.op_cross, crossTy)      val op_cross = monoVar (N.op_cross, crossTy)
361      end      end
362
363      (* Query functions *)
364      (* distance of tensors *)
365        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
371                  fn [Ty.TYPE tv] => [t, Ty.realTy] --> Ty.T_DynSequence(Ty.T_Var tv)
372                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
388     * 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 312  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 *)    (* load image from nrrd *)
410      val fn_image = polyVar (N.fn_image, all([NK, SK],      val fn_image = polyVar (N.fn_image, all([NK, SK],
411              fn [Ty.DIM d, Ty.SHAPE dd] => let              fn [Ty.DIM d, Ty.SHAPE dd] => let
# Line 331  Line 425
425                      --> Ty.T_Bool                      --> Ty.T_Bool
426                  end))                  end))
427
428        (* Reduction Operations *)
429        val fn_rMean = monoVar (N.fn_mean, [Ty.realTy] --> Ty.realTy)
430        val fn_rAll = monoVar (N.fn_all, [Ty.T_Bool] --> Ty.T_Bool)
431        val fn_rMax = monoVar (N.fn_max, [Ty.realTy] --> Ty.realTy)
432        val fn_rMin = monoVar (N.fn_min, [Ty.realTy] --> Ty.realTy)
433        val fn_rExists = monoVar (N.fn_exists, [Ty.T_Bool] --> Ty.T_Bool)
434        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 *)    (* load dynamic sequence from nrrd *)
441              fn [Ty.TYPE tv] => [Ty.T_String] --> Ty.T_DynSequence(Ty.T_Var tv)))              fn [Ty.TYPE tv] => [Ty.T_String] --> Ty.T_DynSequence(Ty.T_Var tv)))
# Line 378  Line 483
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 404  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.1926 changed lines Added in v.3272