Home My Page Projects Code Snippets Project Openings diderot

# SCM Repository

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

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

revision 3397, Tue Nov 10 19:44:40 2015 UTC revision 3398, Wed Nov 11 01:17:58 2015 UTC
# Line 43  Line 43
43        fun field' (k, d, dd) = field(k, Ty.DimConst d, Ty.Shape(List.map Ty.DimConst dd))        fun field' (k, d, dd) = field(k, Ty.DimConst d, Ty.Shape(List.map Ty.DimConst dd))
44        fun tensor ds = Ty.T_Tensor(Ty.Shape ds)        fun tensor ds = Ty.T_Tensor(Ty.Shape ds)
45        fun matrix d = tensor[d,d]        fun matrix d = tensor[d,d]
46          fun dynSeq ty = Ty.T_Sequence(ty, NONE)
47
48        fun monoVar (name, ty) = Var.new (name, AST.BasisVar, ty)        fun monoVar (name, ty) = Var.new (name, Error.UNKNOWN, AST.BasisVar, ty)
49        fun polyVar (name, scheme) = Var.newPoly (name, AST.BasisVar, scheme)        fun polyVar (name, scheme) = Var.newPoly (name, Error.UNKNOWN, AST.BasisVar, scheme)
50      in      in
51
52    (* overloaded operators; the naming convention is to use the operator name followed    (* overloaded operators; the naming convention is to use the operator name followed
# Line 64  Line 65
65    (* concatenation of sequences *)    (* concatenation of sequences *)
66      val at_dT = polyVar (N.op_at, all([TK],      val at_dT = polyVar (N.op_at, all([TK],
67            fn [Ty.TYPE tv] => let            fn [Ty.TYPE tv] => let
68                val seqTyc = Ty.T_DynSequence(Ty.T_Var tv)                val seqTyc = dynSeq(Ty.T_Var tv)
69                in                in
70                  [seqTyc, Ty.T_Var tv] --> seqTyc                  [seqTyc, Ty.T_Var tv] --> seqTyc
71                end))                end))
72      val at_Td = polyVar (N.op_at, all([TK],      val at_Td = polyVar (N.op_at, all([TK],
73            fn [Ty.TYPE tv] => let            fn [Ty.TYPE tv] => let
74                val seqTyc = Ty.T_DynSequence(Ty.T_Var tv)                val seqTyc = dynSeq(Ty.T_Var tv)
75                in                in
76                  [Ty.T_Var tv, seqTyc] --> seqTyc                  [Ty.T_Var tv, seqTyc] --> seqTyc
77                end))                end))
78      val at_dd = polyVar (N.op_at, all([TK],      val at_dd = polyVar (N.op_at, all([TK],
79            fn [Ty.TYPE tv] => let            fn [Ty.TYPE tv] => let
80                val seqTyc = Ty.T_DynSequence(Ty.T_Var tv)                val seqTyc = dynSeq(Ty.T_Var tv)
81                in                in
82                  [seqTyc, seqTyc] --> seqTyc                  [seqTyc, seqTyc] --> seqTyc
83                end))                end))
# Line 231  Line 232
232      in      in
233      val dist2_t  = monoVar (N.fn_dist, vec2Ty)      val dist2_t  = monoVar (N.fn_dist, vec2Ty)
234      val dist3_t  = monoVar (N.fn_dist, vec3Ty)      val dist3_t  = monoVar (N.fn_dist, vec3Ty)
235      end      end (* local *)
236
237    (* 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
238     * as x*x.     * as x*x.
# Line 330  Line 331
332     *)     *)
333      local      local
334        fun evals d = monoVar (N.fn_evals, [matrix d] --> Ty.T_Sequence(Ty.realTy, d))        fun evals d = monoVar (N.fn_evals, [matrix d] --> Ty.T_Sequence(Ty.realTy, SOME d))
335        fun evecs d = monoVar (N.fn_evecs, [matrix d] --> Ty.T_Sequence(tensor[d], d))        fun evecs d = monoVar (N.fn_evecs, [matrix d] --> Ty.T_Sequence(tensor[d], SOME d))
336      in      in
337      val evals2x2 = evals(Ty.DimConst 2)      val evals2x2 = evals(Ty.DimConst 2)
338      val evecs2x2 = evecs(Ty.DimConst 2)      val evecs2x2 = evecs(Ty.DimConst 2)
339      val evals3x3 = evals(Ty.DimConst 3)      val evals3x3 = evals(Ty.DimConst 3)
340      val evecs3x3 = evecs(Ty.DimConst 3)      val evecs3x3 = evecs(Ty.DimConst 3)
341      end      end (* local *)
342
344
(* C math functions *)
val mathFns : (MathFuns.name * Var.var) list = let
fun ty n = List.tabulate(MathFuns.arity n, fn _ => Ty.realTy) --> Ty.realTy
in
List.map (fn n => (n, monoVar(MathFuns.toAtom n, ty n))) MathFuns.allFuns
end

345    (* integer modulo *)    (* integer modulo *)
346      val op_mod = monoVar(N.op_mod, [Ty.T_Int, Ty.T_Int] --> Ty.T_Int)      val op_mod = monoVar(N.op_mod, [Ty.T_Int, Ty.T_Int] --> Ty.T_Int)
347
# Line 424  Line 418
418      in      in
419      val op_cross2_tt = monoVar (N.op_cross, crossTy2)      val op_cross2_tt = monoVar (N.op_cross, crossTy2)
420      val op_cross3_tt = monoVar (N.op_cross, crossTy)      val op_cross3_tt = monoVar (N.op_cross, crossTy)
421      end      end (* local *)
422
423      val op_cross2_ff  = polyVar (N.op_cross, all([DK], fn [Ty.DIFF k] => let      val op_cross2_ff  = polyVar (N.op_cross, all([DK], fn [Ty.DIFF k] => let
424              fun field' (k, d, dd) = field(k, Ty.DimConst d, Ty.Shape(List.map Ty.DimConst dd))              fun field' (k, d, dd) = field(k, Ty.DimConst d, Ty.Shape(List.map Ty.DimConst dd))
# Line 532  Line 526
526                  val d = Ty.DimVar d                  val d = Ty.DimVar d
527                  val dd = Ty.ShapeVar dd                  val dd = Ty.ShapeVar dd
528                  in                  in
529                    [Ty.T_Image{dim=d, shape=dd}] --> Ty.T_Sequence(Ty.T_Int, d)                    [Ty.T_Image{dim=d, shape=dd}] --> Ty.T_Sequence(Ty.T_Int, SOME d)
530                  end))                  end))
531
532    (* functions that handle the boundary behavior of an image *)    (* functions that handle the boundary behavior of an image *)
# Line 579  Line 573
573
574    (* load dynamic sequence from nrrd *)    (* load dynamic sequence from nrrd *)
576              fn [Ty.TYPE tv] => [Ty.T_String] --> Ty.T_DynSequence(Ty.T_Var tv)))              fn [Ty.TYPE tv] => [Ty.T_String] --> dynSeq(Ty.T_Var tv)))
577
578      val fn_length = polyVar (N.fn_length, all([TK],      val fn_length = polyVar (N.fn_length, all([TK],
579              fn [Ty.TYPE tv] => [Ty.T_DynSequence(Ty.T_Var tv)] --> Ty.T_Int))              fn [Ty.TYPE tv] => [dynSeq(Ty.T_Var tv)] --> Ty.T_Int))
580
581      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)
582      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 620  Line 614
614              end              end
615      in      in
616      val op_outer_tt = polyVar (N.op_outer, all([NK, NK], mkOuter))      val op_outer_tt = polyVar (N.op_outer, all([NK, NK], mkOuter))
617      end      end (* local *)
618
619      local      local
620        fun mkOuterField [Ty.DIFF k, Ty.DIM d,Ty.DIM a, Ty.DIM b] = let        fun mkOuterField [Ty.DIFF k, Ty.DIM d,Ty.DIM a, Ty.DIM b] = let
# Line 636  Line 630
630              end              end
631      in      in
632      val op_outer_ff = polyVar (N.op_outer, all([DK,NK,NK,NK], mkOuterField))      val op_outer_ff = polyVar (N.op_outer, all([DK,NK,NK,NK], mkOuterField))
633      end      end (* local *)
634
635      val fn_principleEvec = polyVar (N.fn_principleEvec, all([NK],      val fn_principleEvec = polyVar (N.fn_principleEvec, all([NK],
636              fn [Ty.DIM d] => let              fn [Ty.DIM d] => let
# Line 743  Line 737
737                [f] --> f                [f] --> f
738              end))              end))
739
740      (* Math functions that have not yet been lifted to work on fields *)
741        local
742          fun mk (name, n) =
743                monoVar(Atom.atom name, List.tabulate(n, fn _ => Ty.realTy) --> Ty.realTy)
744        in
745        val fn_atan_t = mk("atan", 1)
746        val fn_atan2_tt = mk("atan2", 2)
747        val fn_ceil_t = mk("ceil", 1)
748        val fn_floor_t = mk("floor", 1)
749        val fn_fmod_tt = mk("fmod", 2)
750        val fn_exp_t = mk("exp", 1)
751        val fn_erf_t = mk("erf", 1)
752        val fn_erfc_t = mk("erfc", 1)
753        val fn_log_t = mk("log", 1)
754        val fn_log10_t = mk("log10", 1)
755        val fn_log2_t = mk("log2", 1)
756        val fn_pow_tt = mk("pow", 2)  (* also used to implement ^ operator *)
757        val fn_tan_t = mk("tan", 1)
758        end (* local *)
759
760    (* Query functions *)    (* Query functions *)
761      local      local
762        val implicit = fn [Ty.TYPE tv] => [Ty.realTy] --> Ty.T_DynSequence(Ty.T_Var tv)        val implicit = fn [Ty.TYPE tv] => [Ty.realTy] --> dynSeq(Ty.T_Var tv)
763        val realTy = fn [Ty.TYPE tv] => [Ty.realTy, Ty.realTy] --> Ty.T_DynSequence(Ty.T_Var tv)        val realTy = fn [Ty.TYPE tv] => [Ty.realTy, Ty.realTy] --> dynSeq(Ty.T_Var tv)
764        val vec2Ty = let        val vec2Ty = let
765              val t = tensor[N2]              val t = tensor[N2]
766              in              in
767                fn [Ty.TYPE tv] => [t, Ty.realTy] --> Ty.T_DynSequence(Ty.T_Var tv)                fn [Ty.TYPE tv] => [t, Ty.realTy] --> dynSeq(Ty.T_Var tv)
768              end              end
769        val vec3Ty = let        val vec3Ty = let
770              val t = tensor[N3]              val t = tensor[N3]
771              in              in
772                fn [Ty.TYPE tv] => [t, Ty.realTy] --> Ty.T_DynSequence(Ty.T_Var tv)                fn [Ty.TYPE tv] => [t, Ty.realTy] --> dynSeq(Ty.T_Var tv)
773              end              end
774      in      in
775      val fn_sphere_im = polyVar (N.fn_sphere, all([TK], implicit))      val fn_sphere_im = polyVar (N.fn_sphere, all([TK], implicit))
# Line 767  Line 781
781    (* reduction operators *)    (* reduction operators *)
782      local      local
783        fun reduction (name, elemTy) =        fun reduction (name, elemTy) =
784              monoVar (name, [Ty.T_DynSequence elemTy] --> elemTy)              monoVar (name, [dynSeq elemTy] --> elemTy)
785      in      in
786      val red_all         = reduction (all, Ty.T_Bool)      val red_all         = reduction (N.fn_all, Ty.T_Bool)
787      val red_exists      = reduction (exists, Ty.T_Bool)      val red_exists      = reduction (N.fn_exists, Ty.T_Bool)
788      val red_max         = reduction (max, Ty.realTy)      val red_max         = reduction (N.fn_max, Ty.realTy)
789      val red_mean        = reduction (mean, Ty.realTy)      val red_mean        = reduction (N.fn_mean, Ty.realTy)
790      val red_min         = reduction (min, Ty.realTy)      val red_min         = reduction (N.fn_min, Ty.realTy)
791      val red_product     = reduction (product, Ty.realTy)      val red_product     = reduction (N.fn_product, Ty.realTy)
792      val red_sum         = reduction (sum, Ty.realTy)      val red_sum         = reduction (N.fn_sum, Ty.realTy)
793      val red_variance    = reduction (variance, Ty.realTy)      val red_variance    = reduction (N.fn_variance, Ty.realTy)
794      end (* local *)      end (* local *)
795
796    (* kernels *)    (* kernels *)
# Line 806  Line 820
820    (* sequence subscript *)    (* sequence subscript *)
821      val subscript = polyVar (Atom.atom "\$sub", all ([TK, NK],      val subscript = polyVar (Atom.atom "\$sub", all ([TK, NK],
822            fn [Ty.TYPE tv, Ty.DIM d] =>            fn [Ty.TYPE tv, Ty.DIM d] =>
823              [Ty.T_Sequence(Ty.T_Var tv, Ty.DimVar d), Ty.T_Int] --> Ty.T_Var tv))              [Ty.T_Sequence(Ty.T_Var tv, SOME(Ty.DimVar d)), Ty.T_Int] --> Ty.T_Var tv))
824
825      val dynSubscript = polyVar (Atom.atom "\$dynsub", all ([TK],      val dynSubscript = polyVar (Atom.atom "\$dynsub", all ([TK],
826            fn [Ty.TYPE tv] => [Ty.T_DynSequence(Ty.T_Var tv), Ty.T_Int] --> Ty.T_Var tv))            fn [Ty.TYPE tv] => [dynSeq(Ty.T_Var tv), Ty.T_Int] --> Ty.T_Var tv))
827
828   (* range expressions *)   (* range expressions *)
829      val range = monoVar (Atom.atom "\$range", [Ty.T_Int, Ty.T_Int] --> Ty.T_DynSequence Ty.T_Int)      val range = monoVar (Atom.atom "\$range", [Ty.T_Int, Ty.T_Int] --> dynSeq Ty.T_Int)
830
831      end (* local *)      end (* local *)
832    end    end

Legend:
 Removed from v.3397 changed lines Added in v.3398