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

SCM Repository

[diderot] Annotation of /branches/charisee/src/compiler/translate/translate-basis.sml
ViewVC logotype

Annotation of /branches/charisee/src/compiler/translate/translate-basis.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3528 - (view) (download)

1 : jhr 180 (* translate-basis.sml
2 :     *
3 : jhr 3349 * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu)
4 :     *
5 :     * COPYRIGHT (c) 2015 The University of Chicago
6 : jhr 180 * All rights reserved.
7 :     *
8 :     * Translation for basis operations in Simple AST to HighIL code
9 :     *)
10 :    
11 :     structure TranslateBasis : sig
12 :    
13 : jhr 189 (* translate(lhs, f, mvs, args) translates the application of f (specialized
14 :     * to the instantiated meta variables mvs) to a list of SSA assignments in
15 :     * reverse order.
16 :     *)
17 : jhr 2490 val translate : (HighIL.var * Var.var * SimpleTypes.meta_arg list * HighIL.var list)
18 : jhr 2356 -> HighIL.assignment list
19 : jhr 180
20 :     end = struct
21 :    
22 : jhr 194 structure BV = BasisVars
23 : jhr 180 structure IL = HighIL
24 : jhr 392 structure DstTy = HighILTypes
25 : jhr 180 structure Op = HighOps
26 : jhr 2490 structure Ty = SimpleTypes
27 : jhr 194 structure VTbl = Var.Tbl
28 : jhr 3060 structure Mk = MkOperators
29 : cchiw 2499
30 : jhr 2490 fun trType (Ty.TY ty) = TranslateTy.tr ty
31 :     | trType _ = raise Fail "expected type"
32 :     fun dimVarToInt (Ty.DIM d) = d
33 :     | dimVarToInt _ = raise Fail "expected dim"
34 : jhr 2358 fun dimVarToTensor dv = DstTy.tensorTy[dimVarToInt dv]
35 : jhr 1116 fun dimVarToMatrix dv = let
36 : jhr 2358 val d = dimVarToInt dv
37 : jhr 2356 in
38 :     DstTy.tensorTy[d, d] (* square matrix type *)
39 :     end
40 : jhr 2490 fun shapeVarToTensor (Ty.SHAPE shp) = DstTy.tensorTy shp
41 :     | shapeVarToTensor _ = raise Fail "expected shape"
42 : jhr 197
43 : jhr 1640 fun assign (y, rator, xs) = [IL.ASSGN(y, IL.OP(rator, xs))]
44 : jhr 407
45 : jhr 1640 fun basisFn name (y, [], xs) = [IL.ASSGN(y, IL.APPLY(name, xs))]
46 : jhr 1116
47 : jhr 407 fun simpleOp rator (y, [], xs) = assign (y, rator, xs)
48 :    
49 :     fun tensorOp rator (y, [sv], xs) = assign (y, rator(shapeVarToTensor sv), xs)
50 :    
51 :     fun vectorOp rator (y, [dv], xs) = assign (y, rator(dimVarToTensor dv), xs)
52 :    
53 : jhr 1116 fun kernel h (y, [], []) = assign(y, Op.Kernel(h, 0), [])
54 : jhr 197
55 : jhr 1640 (* utility functions for synthesizing eigenvector/eigenvalue code *)
56 :     fun eigenVec (rator, dim) = let
57 :     val ty = DstTy.SeqTy(DstTy.realTy, dim)
58 :     in
59 :     fn (y, _, [m]) => let
60 :     val v = IL.Var.new("evals", ty)
61 :     in
62 :     [IL.MASSGN([v, y], rator, [m])]
63 :     end
64 :     end
65 :     fun eigenVal (rator, dim) = let
66 :     val ty = DstTy.SeqTy(DstTy.vecTy dim, dim)
67 :     in
68 :     fn (y, _, [m]) => let
69 :     val v = IL.Var.new("evecs", ty)
70 :     in
71 :     [IL.MASSGN([y, v], rator, [m])]
72 :     end
73 :     end
74 :    
75 : cchiw 2496 fun assignEin (y, rator, xs) = IL.ASSGN(y, IL.EINAPP(rator, xs))
76 : cchiw 2382
77 : cchiw 2499 fun simpleEOp rator (y, _,xs) = [assignEin(y, rator, xs)]
78 : cchiw 2485
79 : cchiw 2414 (* shape is an int list, DIM is in int|variable, k-level of differntiation *)
80 :    
81 : cchiw 2412 (* build a table that maps Basis variables to their translation functions *)
82 : jhr 2490 val tbl : ((IL.var * Ty.meta_arg list * IL.var list) -> IL.assignment list) VTbl.hash_table = let
83 : jhr 2356 val tbl = VTbl.mkTable (128, Fail "Translate table")
84 :     val insert = VTbl.insert tbl
85 :     in
86 :     List.app insert [
87 :     (BV.lt_ii, simpleOp(Op.LT DstTy.IntTy)),
88 :     (BV.lt_rr, simpleOp(Op.LT DstTy.realTy)),
89 :     (BV.lte_ii, simpleOp(Op.LTE DstTy.IntTy)),
90 :     (BV.lte_rr, simpleOp(Op.LTE DstTy.realTy)),
91 :     (BV.gte_ii, simpleOp(Op.GTE DstTy.IntTy)),
92 :     (BV.gte_rr, simpleOp(Op.GTE(DstTy.realTy))),
93 :     (BV.gt_ii, simpleOp(Op.GT DstTy.IntTy)),
94 :     (BV.gt_rr, simpleOp(Op.GT(DstTy.realTy))),
95 :     (BV.equ_bb, simpleOp(Op.EQ DstTy.BoolTy)),
96 :     (BV.equ_ii, simpleOp(Op.EQ DstTy.IntTy)),
97 :     (BV.equ_ss, simpleOp(Op.EQ DstTy.StringTy)),
98 :     (BV.equ_rr, simpleOp(Op.EQ(DstTy.realTy))),
99 :     (BV.neq_bb, simpleOp(Op.NEQ DstTy.BoolTy)),
100 :     (BV.neq_ii, simpleOp(Op.NEQ DstTy.IntTy)),
101 :     (BV.neq_ss, simpleOp(Op.NEQ DstTy.StringTy)),
102 :     (BV.neq_rr, simpleOp(Op.NEQ(DstTy.realTy))),
103 : jhr 2492 (BV.add_ii, simpleOp Op.IAdd),
104 : cchiw 2499 (BV.add_tt, fn (y, [shp], xs) => let
105 :     val ty1 as DstTy.TensorTy dd1 = shapeVarToTensor shp
106 : jhr 3060 val rator = Mk.addTT(dd1)
107 : cchiw 2499 in
108 :     [assignEin(y, rator,xs)]
109 :     end),
110 : cchiw 2496 (BV.add_ff, fn (y, [_,Ty.DIM d, Ty.SHAPE dd], xs) =>
111 : jhr 3060 [assignEin(y, Mk.addFF(d, dd),xs)]),
112 : cchiw 2499
113 : cchiw 2906 (BV.add_ft, fn (y, [_,Ty.DIM d, Ty.SHAPE dd], [f,s]) =>
114 : jhr 3060 [assignEin(y, Mk.addTF(d,dd),[s,f])]),
115 : cchiw 2499
116 : cchiw 2906 (BV.add_tf, fn (y, [_,Ty.DIM d, Ty.SHAPE dd], xs) =>
117 : jhr 3060 [assignEin(y, Mk.addTF(d,dd),xs)]),
118 : jhr 2492 (BV.sub_ii, simpleOp Op.ISub),
119 : cchiw 2499 (BV.sub_tt, fn (y, [shp], xs) => let
120 :     val ty1 as DstTy.TensorTy dd1 = shapeVarToTensor shp
121 : jhr 3060 val rator = Mk.subTT dd1
122 : cchiw 2499 in
123 :     [assignEin(y, rator,xs)]
124 :     end),
125 : cchiw 2496 (BV.sub_ff, fn (y, [_,Ty.DIM d, Ty.SHAPE dd], xs) =>
126 : jhr 3060 [assignEin(y, Mk.subFF(d, dd),xs)]),
127 : cchiw 2906 (BV.sub_ft, fn (y, [_,Ty.DIM d, Ty.SHAPE dd], [x1,x2]) =>
128 : jhr 3060 [assignEin(y, Mk.subFT(d,dd),[x2,x1])]),
129 : cchiw 2906 (BV.sub_tf, fn (y, [_,Ty.DIM d, Ty.SHAPE dd], xs) =>
130 : jhr 3060 [assignEin(y, Mk.subTF(d,dd),xs)]),
131 : cchiw 2447 (BV.mul_ii, simpleOp Op.IMul),
132 : jhr 3060 (BV.mul_rr, fn (y,_,args) => [assignEin(y, Mk.mulRR,args)]),
133 : cchiw 2499 (BV.mul_rt, fn (y, [shp], xs) => let
134 :     val ty1 as DstTy.TensorTy dd1 = shapeVarToTensor shp
135 : jhr 3060 val rator = Mk.mulRT(dd1)
136 : cchiw 2499 in
137 :     [assignEin(y, rator,xs)]
138 :     end),
139 : jhr 2492 (BV.mul_tr, fn (y, [shp], [t, r]) => let
140 :     val ty1 as DstTy.TensorTy dd1 = shapeVarToTensor shp
141 : jhr 3060 val rator = Mk.mulRT dd1
142 : jhr 2492 in
143 : cchiw 2496 [assignEin(y, rator,[r,t])]
144 : jhr 2492 end),
145 : cchiw 2496 (BV.mul_rf, fn (y, [_,Ty.DIM d, Ty.SHAPE dd], xs) =>
146 : jhr 3060 [assignEin(y, Mk.mulRF(d, dd),xs)]),
147 : cchiw 2496 (BV.mul_fr, fn (y, [_,Ty.DIM d, Ty.SHAPE dd], [f, s]) =>
148 : jhr 3060 [assignEin(y, Mk.mulRF(d, dd),[s,f])]),
149 : cchiw 2576 (BV.mul_ss, fn (y, [_,Ty.DIM d], xs) =>
150 : jhr 3060 [assignEin(y, Mk.mulSS d,xs)]),
151 : cchiw 2576 (BV.mul_sf, fn (y, [_,Ty.DIM d, Ty.SHAPE dd], xs) =>
152 : jhr 3060 [assignEin(y, Mk.mulSF(d,dd),xs)]),
153 : cchiw 2867 (BV.mul_fs, fn (y, [_,Ty.DIM d, Ty.SHAPE dd], [s,f]) =>
154 : jhr 3060 [assignEin(y, Mk.mulSF(d,dd),[f,s])]),
155 : cchiw 3066 (BV.mul_st, fn (y, [_,Ty.DIM d, Ty.SHAPE dd], xs) =>
156 :     [assignEin(y, Mk.mulST(d,dd),List.rev xs)]),
157 :     (BV.mul_ts, fn (y, [_,Ty.DIM d, Ty.SHAPE dd], xs) =>
158 :     [assignEin(y, Mk.mulST(d,dd),xs)]),
159 : cchiw 2447 (BV.div_ii, simpleOp Op.IDiv),
160 : jhr 3060 (BV.div_rr, fn (y,_,args) => [assignEin(y, Mk.divRR,args)]),
161 : cchiw 2499 (BV.div_tr, fn (y, [shp], xs) => let
162 :     val ty1 as DstTy.TensorTy dd1 = shapeVarToTensor shp
163 : jhr 3060 val rator = Mk.divTR dd1
164 : cchiw 2499 in
165 :     [assignEin(y, rator,xs)]
166 :     end),
167 :     (BV.div_fr, fn (y, [_,Ty.DIM d, Ty.SHAPE dd], xs) =>
168 : jhr 3060 [assignEin(y, Mk.divFR(d, dd),xs)]),
169 : cchiw 2867 (BV.div_fs, fn (y, [_,_,Ty.DIM d, Ty.SHAPE dd], xs) =>
170 : jhr 3060 [assignEin(y, Mk.divFS(d, dd),xs)]),
171 : cchiw 2608 (BV.div_ss, fn (y, [_,Ty.DIM d], xs) =>
172 : jhr 3060 [assignEin(y, Mk.divSS d,xs)]),
173 : cchiw 2445 (BV.exp_ri, simpleOp(Op.Power)),
174 :     (BV.exp_rr, basisFn MathFuns.pow),
175 : jhr 3060 (BV.curl2D, simpleEOp Mk.curl2d),
176 :     (BV.curl3D, simpleEOp Mk.curl3d),
177 : cchiw 2496 (BV.convolve_vk, fn (y, [_, Ty.DIM d, Ty.SHAPE dd], xs) =>
178 : jhr 3060 [assignEin(y, Mk.conv(d, dd),xs)]),
179 : cchiw 2496 (BV.convolve_kv, fn (y, [_, Ty.DIM d, Ty.SHAPE dd], [k, v]) =>
180 : jhr 3060 [assignEin(y, Mk.conv(d, dd),[v,k])]),
181 : cchiw 2447 (BV.neg_i, simpleOp Op.INeg),
182 : cchiw 2499 (BV.neg_t, fn (y, [shp], xs) => let
183 :     val ty1 as DstTy.TensorTy dd1 = shapeVarToTensor shp
184 : jhr 3060 val rator = Mk.negTT dd1
185 : cchiw 2499 in
186 :     [assignEin(y, rator,xs)]
187 :     end),
188 :     (BV.neg_f, fn (y, [_,Ty.DIM d, Ty.SHAPE dd], xs) =>
189 : jhr 3060 [assignEin(y, Mk.negFF(d, dd),xs)]),
190 : cchiw 2499 (BV.op_probe, fn (y, [_, Ty.DIM d, Ty.SHAPE dd], xs) =>
191 : jhr 3060 [assignEin(y, (Mk.probe(dd,d)),xs)]),
192 : cchiw 2847 (BV.op_D, fn (y, [_, Ty.DIM d], xs) => (case d
193 : jhr 3060 of 2=>[assignEin(y, Mk.grad([d]),xs)]
194 :     | 3=>[assignEin(y, Mk.grad([d]),xs)]
195 : cchiw 2847 | _ => raise Fail "unsupported gradient"
196 :     (*end case*))),
197 : cchiw 2906 (BV.op_Dotimes, fn (y, [_, Ty.DIM d1, Ty.SHAPE dd, Ty.DIM d2], xs) =>
198 : jhr 3060 [assignEin(y, Mk.dotimes(d1, dd@[d2]),xs)]),
199 : cchiw 2585 (BV.op_Ddot, fn (y, [_, Ty.DIM d1, Ty.SHAPE dd, Ty.DIM d2], xs) =>
200 : jhr 3060 [assignEin(y, Mk.divergence(d1, dd),xs)] ),
201 : cchiw 3048 (BV.op_norm_t, fn (y, [sv], xs) => assign(y, Op.Norm(shapeVarToTensor sv), xs)),
202 :     (BV.op_norm_f, fn (y, [ _,Ty.DIM d1, Ty.SHAPE dd], xs) =>
203 : jhr 3060 [assignEin(y, Mk.magnitudeFF(d1, dd),xs@xs)]),
204 : jhr 2492 (BV.op_not, simpleOp Op.Not),
205 : jhr 3060 (BV.op_cross3_tt, simpleEOp Mk.cross3TT),
206 :     (BV.op_cross2_tt, simpleEOp Mk.cross2TT),
207 :     (BV.op_cross2_ff, simpleEOp Mk.cross2FF),
208 :     (BV.op_cross3_ff, simpleEOp Mk.cross3FF),
209 : cchiw 2906 (BV.op_outer_tt, fn (y, [Ty.DIM d1, Ty.DIM d2], xs) =>
210 : jhr 3060 [assignEin(y, (Mk.outerTT(d1, d2)), xs)]),
211 : cchiw 3450 (BV.op_outer_mt, fn (y, [Ty.DIM d1, Ty.DIM d2,Ty.DIM d3], xs) =>
212 :     [assignEin(y, (Mk.outerMT([d1, d2],d3)), xs)]),
213 :     (BV.op_outer_tm, fn (y, [Ty.DIM d1, Ty.DIM d2,Ty.DIM d3], xs) =>
214 :     [assignEin(y, (Mk.outerTM(d1,[ d2,d3])), xs)]),
215 : cchiw 3017 (BV.op_outer_ff, fn (y, [_, Ty.DIM d1,Ty.DIM i,Ty.DIM j], xs)=>
216 : jhr 3060 [assignEin(y, Mk.outerFF(d1,i,j), xs)]),
217 : cchiw 2906 (BV.op_inner_tt, fn (y, [sh1, sh2, _], xs) => let
218 : cchiw 2499 val ty1 as DstTy.TensorTy dd1 = shapeVarToTensor sh1
219 :     val ty2 as DstTy.TensorTy dd2 = shapeVarToTensor sh2
220 :     in
221 : jhr 3060 [assignEin(y, (Mk.innerTT(dd1,dd2)),xs)]
222 : cchiw 2499 end),
223 : cchiw 2584
224 : cchiw 2929 (BV.op_inner_tf, fn (y, [_,Ty.DIM d,sh1,Ty.SHAPE dd2,_], xs) =>let
225 :     val ty1 as DstTy.TensorTy dd1 = shapeVarToTensor sh1
226 :     in
227 : jhr 3060 [assignEin(y, Mk.innerTF(dd1,d,dd2),xs)]
228 : cchiw 2929 end ),
229 :     (BV.op_inner_ft, fn (y, [_,Ty.DIM d,Ty.SHAPE dd1,sh2,_], xs) =>let
230 :     val ty1 as DstTy.TensorTy dd2 = shapeVarToTensor sh2
231 :     in
232 : jhr 3060 [assignEin(y, Mk.innerFT(dd1,d,dd2),xs)]
233 : cchiw 2929 end ),
234 : cchiw 2906
235 : cchiw 2955 (BV.op_inner_ff, fn (y, [_,_,Ty.DIM d,Ty.SHAPE dd1,Ty.SHAPE dd2,_], xs) =>
236 : jhr 3060 [assignEin(y, Mk.innerFF(dd1,d,dd2),xs)]),
237 : jhr 2926
238 : cchiw 2906 (BV.op_colon_tt, fn (y, [sh1, sh2, _], xs) => let
239 : cchiw 2499 val ty1 as DstTy.TensorTy dd1 = shapeVarToTensor sh1
240 :     val ty2 as DstTy.TensorTy dd2 = shapeVarToTensor sh2
241 :     in
242 : jhr 3060 [assignEin(y, (Mk.colonTT(dd1,dd2)),xs)]
243 : cchiw 2499 end),
244 : cchiw 3229 (BV.op_colon_ft, fn (y, [_,Ty.SHAPE dd1,Ty.DIM d,Ty.SHAPE dd2, _], xs) =>
245 :     [assignEin(y, (Mk.colonFT(d,dd1,dd2)),xs)]),
246 :     (BV.op_colon_tf, fn (y, [_,Ty.SHAPE dd1,Ty.DIM d,Ty.SHAPE dd2, _], xs) =>
247 :     [assignEin(y, (Mk.colonTF(d,dd1,dd2)),xs)]),
248 :     (BV.op_colon_ff, fn (y, [_,Ty.SHAPE dd1,Ty.DIM d,Ty.SHAPE dd2, _], xs) =>
249 :     [assignEin(y, (Mk.colonFF(d,dd1,dd2)),xs)]),
250 : jhr 2492 (BV.fn_inside, fn (y, [_, Ty.DIM d, _], xs) => assign(y, Op.Inside d, xs)),
251 : jhr 2356 (BV.clamp_rrr, simpleOp (Op.Clamp DstTy.realTy)),
252 :     (BV.clamp_vvv, vectorOp Op.Clamp),
253 :     (BV.lerp3, tensorOp Op.Lerp),
254 : jhr 3060 (BV.lerp5, fn (y, [sv], [a, b, x0, x, x1]) => let
255 : jhr 2356 val t1 = IL.Var.new("t1", DstTy.realTy)
256 :     val t2 = IL.Var.new("t2", DstTy.realTy)
257 :     val t3 = IL.Var.new("t3", DstTy.realTy)
258 :     in [
259 : jhr 3060 assignEin(t1, Mk.subRR,[x,x0]),
260 :     assignEin(t2, Mk.subRR,[x1,x0]),
261 :     assignEin(t3, Mk.divRR,[t1,t2]),
262 : jhr 2356 IL.ASSGN(y, IL.OP(Op.Lerp(shapeVarToTensor sv), [a, b, t3]))
263 :     ] end),
264 :     (BV.evals2x2, eigenVal (Op.Eigen2x2, 2)),
265 :     (BV.evals3x3, eigenVal (Op.Eigen3x3, 3)),
266 :     (BV.evecs2x2, eigenVec (Op.Eigen2x2, 2)),
267 :     (BV.evecs3x3, eigenVec (Op.Eigen3x3, 3)),
268 :     (BV.fn_max, simpleOp Op.Max),
269 :     (BV.fn_min, simpleOp Op.Min),
270 : cchiw 2496 (* modulate is vector * vector pointwise multiplication *)
271 : cchiw 2499 (BV.fn_modulate, fn (y,[Ty.DIM dd1], xs) =>
272 : jhr 3060 [assignEin(y, (Mk.modulate dd1),xs)]),
273 : cchiw 3189 (BV.fn_normalize_t, fn (y, [shp], xs) =>let
274 :     val DstTy.TensorTy dd1 = shapeVarToTensor shp
275 :     in (case dd1
276 :     of [_]=> [IL.ASSGN(y, IL.OP(Op.Normalize(DstTy.TensorTy dd1),xs))]
277 :     (*looks right but causes precision error for regresstion tests. change later*)
278 :     | _ => [assignEin(y, (Mk.normalizeTT dd1), xs@xs)]) end
279 :     ),
280 :     (BV.fn_normalize_f, fn (y, [ _,Ty.DIM d1, Ty.SHAPE dd], xs) =>
281 : cchiw 2870 (case dd
282 : cchiw 3189 of [] => [assignEin(y, Mk.normalizeFF(d1, []),xs)]
283 : jhr 3060 | _ => [assignEin(y, Mk.normalizeFF(d1, dd),xs@xs)]
284 : cchiw 2870 (* end case *))),
285 : jhr 2356 (BV.fn_principleEvec, vectorOp Op.PrincipleEvec),
286 : cchiw 2906 (BV.fn_trace_t, fn (y, [Ty.DIM d], xs) =>
287 : jhr 3060 [assignEin(y,(Mk.traceT d), xs)]),
288 : cchiw 2906 (BV.fn_trace_f, fn (y, [_,Ty.DIM d,Ty.SHAPE dd], xs) =>
289 : jhr 3060 [assignEin(y,Mk.traceF(d,dd), xs)]),
290 : cchiw 2906 (BV.fn_transpose_t, fn (y, [Ty.DIM d1, Ty.DIM d2], xs) =>
291 : jhr 3060 [assignEin(y, (Mk.transposeT [d1,d2]), xs)]),
292 : cchiw 2906 (BV.fn_transpose_f, fn (y, [_,Ty.DIM d1, Ty.DIM d2,Ty.DIM d3], xs) =>
293 : jhr 3060 [assignEin(y, (Mk.transposeF (d1,d2,d3)), xs)]),
294 : cchiw 3066 (BV.fn_det_t2, simpleEOp (Mk.detT2)),
295 : cchiw 3189 (BV.fn_det_t3, simpleEOp (Mk.detT3)),
296 : cchiw 3066 (BV.fn_det_f2, simpleEOp (Mk.detF2)),
297 :     (BV.fn_det_f3, simpleEOp (Mk.detF3)),
298 : cchiw 3112 (BV.fn_sqrt_f, fn (y, [_,Ty.DIM d1], xs) =>
299 : cchiw 3138 [assignEin(y, Mk.sqrtF d1, xs)]),
300 : cchiw 3112 (BV.fn_sqrt_t, fn (y, _, xs) =>
301 :     assign(y, Op.Sqrt,xs)),
302 : cchiw 3138 (BV.fn_cos_f, fn (y, [_,Ty.DIM d1], xs) =>
303 :     [assignEin(y, Mk.cosF d1, xs)]),
304 :     (BV.fn_acos_f, fn (y, [_,Ty.DIM d1], xs) =>
305 :     [assignEin(y, Mk.acosF d1, xs)]),
306 :     (BV.fn_sin_f, fn (y, [_,Ty.DIM d1], xs) =>
307 :     [assignEin(y, Mk.sinF d1, xs)]),
308 :     (BV.fn_asin_f, fn (y, [_,Ty.DIM d1], xs) =>
309 : cchiw 3450 [assignEin(y, Mk.asinF d1, xs)]),
310 :     (BV.fn_tan_f, fn (y, [_,Ty.DIM d1], xs) =>
311 :     [assignEin(y, Mk.tanF d1, xs)]),
312 :     (BV.fn_atan_f, fn (y, [_,Ty.DIM d1], xs) =>
313 :     [assignEin(y, Mk.atanF d1, xs)]),
314 :     (BV.fn_exp_f, fn (y, [_,Ty.DIM d1], xs) =>
315 :     [assignEin(y, Mk.expF d1, xs)]),
316 :     (BV.fn_exp_t, fn (y, _, xs) =>
317 :     [assignEin(y, Mk.expT, xs)]),
318 :     (BV.fn_pow_f, fn (y, [_,Ty.DIM d1], [f,n]) =>let
319 :     fun getN x = (case IL.Var.binding x
320 :     of IL.VB_RHS(IL.LIT(Literal.Int n))=> IntInf.toInt n
321 :     | vb => raise Fail (String.concat["\n -- Not an Int, ", IL.Var.toString x," found ",IL.vbToString vb,"\n"])
322 :     (* end case *))
323 :     val e1= Mk.powF(d1 ,getN n)
324 :     in
325 :     [assignEin(y, e1, [f])]
326 :     end),
327 : jhr 2356 (BV.kn_bspln3, kernel Kernel.bspln3),
328 :     (BV.kn_bspln5, kernel Kernel.bspln5),
329 :     (BV.kn_ctmr, kernel Kernel.ctmr),
330 :     (BV.kn_c2ctmr, kernel Kernel.ctmr),
331 : jhr 2358 (BV.kn_c4hexic, kernel Kernel.c4hexic),
332 : jhr 2356 (BV.kn_tent, kernel Kernel.tent),
333 :     (BV.kn_c1tent, kernel Kernel.tent),
334 :     (BV.i2r, simpleOp Op.IntToReal),
335 : cchiw 2496 (BV.identity, fn (y, [Ty.DIM d], xs) =>
336 : jhr 3060 [assignEin(y, (Mk.identity d), xs)]),
337 :     (BV.zero, fn (y, [sv], []) =>
338 : cchiw 2628 assign(y, Op.Zero(shapeVarToTensor sv), [])),
339 : jhr 3286 (BV.nan, fn (y, [Ty.SHAPE dd], []) => let
340 :     val nan = IL.LIT(Literal.Float(FloatLit.nan))
341 :     fun mk (y, [], stms) = IL.ASSGN(y, nan) :: stms
342 :     | mk (y, d::dd, stms) = let
343 :     val ty = shapeVarToTensor(Ty.SHAPE dd)
344 :     val zs = List.tabulate(d, fn _ => IL.Var.new("_nan", ty))
345 :     in
346 :     IL.ASSGN(y, IL.CONS(IL.Var.ty y, zs)) ::
347 :     List.foldl (fn (z, stms) => mk(z, dd, stms)) stms zs
348 :     end
349 :     in
350 :     List.rev (mk (y, dd, []))
351 :     end),
352 : jhr 2492 (BV.subscript, fn (y, [ty, Ty.DIM d], xs) =>
353 :     assign (y, Op.SeqSub(DstTy.SeqTy(trType ty, d)), xs))
354 : jhr 2490 (*,
355 :     (BV.dynSubscript, fn (y, [tv], args) =>
356 :     assign(y, Op.SeqSub(DstTy.DynSeqTy(pruneTy tv)), args))
357 :     *)
358 : cchiw 2388 ];
359 : jhr 2356 (* add C math functions *)
360 :     List.app (fn (n, x) => insert(x, basisFn n)) BV.mathFns;
361 :     tbl
362 :     end
363 : jhr 180
364 : jhr 194 fun translate (y, f, mvs, xs) = (case VTbl.find tbl f
365 : jhr 2356 of SOME transFn => transFn(y, mvs, xs)
366 :     | NONE => raise Fail("TranslateBasis.translate: unknown basis function " ^ Var.uniqueNameOf f)
367 :     (* end case *))
368 : jhr 1116 handle ex => (print(concat["translate (", IL.Var.toString y, ", ",
369 :     Var.uniqueNameOf f, ", ...)\n"]); raise ex)
370 : jhr 180
371 :     end

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