1 |
(* translate-basis.sml |
(* translate-basis.sml |
2 |
* |
* |
3 |
* COPYRIGHT (c) 2010 The Diderot Project (http://diderot.cs.uchicago.edu) |
* COPYRIGHT (c) 2010 The Diderot Project (http://diderot-language.cs.uchicago.edu) |
4 |
* All rights reserved. |
* All rights reserved. |
5 |
* |
* |
6 |
* Translation for basis operations in Simple AST to HighIL code |
* Translation for basis operations in Simple AST to HighIL code |
12 |
* to the instantiated meta variables mvs) to a list of SSA assignments in |
* to the instantiated meta variables mvs) to a list of SSA assignments in |
13 |
* reverse order. |
* reverse order. |
14 |
*) |
*) |
15 |
val translate : (HighIL.var * Var.var * Types.meta_var list * HighIL.var list) |
val translate : (HighIL.var * Var.var * SimpleTypes.meta_arg list * HighIL.var list) |
16 |
-> HighIL.assign list |
-> HighIL.assignment list |
17 |
|
|
18 |
end = struct |
end = struct |
19 |
|
|
21 |
structure IL = HighIL |
structure IL = HighIL |
22 |
structure DstTy = HighILTypes |
structure DstTy = HighILTypes |
23 |
structure Op = HighOps |
structure Op = HighOps |
24 |
structure Ty = Types |
structure Ty = SimpleTypes |
|
structure TU = TypeUtil |
|
|
structure MV = MetaVar |
|
25 |
structure VTbl = Var.Tbl |
structure VTbl = Var.Tbl |
26 |
|
|
27 |
fun pruneDim d = (case TU.pruneDim d |
structure mk= mkOperators |
|
of (Ty.DimConst n) => n |
|
|
| d => raise Fail("unresolved dimension " ^ TU.dimToString d) |
|
|
(* end case *)) |
|
28 |
|
|
29 |
fun pruneShape sv = (case TU.pruneShape(MV.toShape sv) |
fun trType (Ty.TY ty) = TranslateTy.tr ty |
30 |
of Ty.Shape dd => DstTy.TensorTy(List.map pruneDim dd) |
| trType _ = raise Fail "expected type" |
31 |
| shp => raise Fail("unresolved shape " ^ TU.shapeToString shp) |
fun dimVarToInt (Ty.DIM d) = d |
32 |
(* end case *)) |
| dimVarToInt _ = raise Fail "expected dim" |
33 |
|
fun dimVarToTensor dv = DstTy.tensorTy[dimVarToInt dv] |
34 |
|
fun dimVarToMatrix dv = let |
35 |
|
val d = dimVarToInt dv |
36 |
|
in |
37 |
|
DstTy.tensorTy[d, d] (* square matrix type *) |
38 |
|
end |
39 |
|
fun shapeVarToTensor (Ty.SHAPE shp) = DstTy.tensorTy shp |
40 |
|
| shapeVarToTensor _ = raise Fail "expected shape" |
41 |
|
|
42 |
fun dimVarToTensor dv = DstTy.TensorTy[pruneDim(MV.toDim dv)] |
fun assign (y, rator, xs) = [IL.ASSGN(y, IL.OP(rator, xs))] |
|
fun shapeVarToTensor sv = pruneShape sv |
|
43 |
|
|
44 |
fun assign (y, rator, xs) = [(y, IL.OP(rator, xs))] |
fun basisFn name (y, [], xs) = [IL.ASSGN(y, IL.APPLY(name, xs))] |
45 |
|
|
46 |
fun simpleOp rator (y, [], xs) = assign (y, rator, xs) |
fun simpleOp rator (y, [], xs) = assign (y, rator, xs) |
47 |
|
|
49 |
|
|
50 |
fun vectorOp rator (y, [dv], xs) = assign (y, rator(dimVarToTensor dv), xs) |
fun vectorOp rator (y, [dv], xs) = assign (y, rator(dimVarToTensor dv), xs) |
51 |
|
|
52 |
fun kernel h (y, [], []) = assign(y, Op.Kernel h, []) |
fun kernel h (y, [], []) = assign(y, Op.Kernel(h, 0), []) |
53 |
|
|
54 |
|
(* utility functions for synthesizing eigenvector/eigenvalue code *) |
55 |
|
fun eigenVec (rator, dim) = let |
56 |
|
val ty = DstTy.SeqTy(DstTy.realTy, dim) |
57 |
|
in |
58 |
|
fn (y, _, [m]) => let |
59 |
|
val v = IL.Var.new("evals", ty) |
60 |
|
in |
61 |
|
[IL.MASSGN([v, y], rator, [m])] |
62 |
|
end |
63 |
|
end |
64 |
|
fun eigenVal (rator, dim) = let |
65 |
|
val ty = DstTy.SeqTy(DstTy.vecTy dim, dim) |
66 |
|
in |
67 |
|
fn (y, _, [m]) => let |
68 |
|
val v = IL.Var.new("evecs", ty) |
69 |
|
in |
70 |
|
[IL.MASSGN([y, v], rator, [m])] |
71 |
|
end |
72 |
|
end |
73 |
|
|
74 |
|
fun assignEin (y, rator, xs) = IL.ASSGN(y, IL.EINAPP(rator, xs)) |
75 |
|
|
76 |
|
fun simpleEOp rator (y, _,xs) = [assignEin(y, rator, xs)] |
77 |
|
|
78 |
|
|
79 |
|
|
80 |
|
|
81 |
|
|
82 |
|
(* shape is an int list, DIM is in int|variable, k-level of differntiation *) |
83 |
|
|
84 |
(* build a table that maps Basis variables to their translation functions *) |
(* build a table that maps Basis variables to their translation functions *) |
85 |
val tbl : ((IL.var * Ty.meta_var list * IL.var list) -> IL.assign list) VTbl.hash_table = let |
val tbl : ((IL.var * Ty.meta_arg list * IL.var list) -> IL.assignment list) VTbl.hash_table = let |
86 |
val tbl = VTbl.mkTable (128, Fail "Translate table") |
val tbl = VTbl.mkTable (128, Fail "Translate table") |
87 |
|
val insert = VTbl.insert tbl |
88 |
in |
in |
89 |
List.app (VTbl.insert tbl) [ |
List.app insert [ |
|
(BV.add_ii, simpleOp(Op.Add DstTy.IntTy)), |
|
|
(BV.add_tt, tensorOp Op.Add), |
|
|
(BV.sub_ii, simpleOp(Op.Sub DstTy.IntTy)), |
|
|
(BV.sub_tt, tensorOp Op.Sub), |
|
|
(BV.mul_ii, simpleOp(Op.Mul DstTy.IntTy)), |
|
|
(BV.mul_rr, simpleOp(Op.Mul(DstTy.TensorTy[]))), |
|
|
(BV.mul_rt, tensorOp Op.Scale), |
|
|
(BV.mul_tr, fn (y, sv, [t, r]) => tensorOp Op.Scale (y, sv, [r, t])), |
|
|
(BV.div_ii, simpleOp(Op.Div DstTy.IntTy)), |
|
|
(BV.div_rr, simpleOp(Op.Div(DstTy.TensorTy[]))), |
|
|
(BV.div_tr, tensorOp Op.InvScale), |
|
90 |
(BV.lt_ii, simpleOp(Op.LT DstTy.IntTy)), |
(BV.lt_ii, simpleOp(Op.LT DstTy.IntTy)), |
91 |
(BV.lt_rr, simpleOp(Op.LT(DstTy.TensorTy[]))), |
(BV.lt_rr, simpleOp(Op.LT DstTy.realTy)), |
92 |
(BV.lte_ii, simpleOp(Op.LTE DstTy.IntTy)), |
(BV.lte_ii, simpleOp(Op.LTE DstTy.IntTy)), |
93 |
(BV.lte_rr, simpleOp(Op.LTE(DstTy.TensorTy[]))), |
(BV.lte_rr, simpleOp(Op.LTE DstTy.realTy)), |
94 |
(BV.gte_ii, simpleOp(Op.GTE DstTy.IntTy)), |
(BV.gte_ii, simpleOp(Op.GTE DstTy.IntTy)), |
95 |
(BV.gte_rr, simpleOp(Op.GTE(DstTy.TensorTy[]))), |
(BV.gte_rr, simpleOp(Op.GTE(DstTy.realTy))), |
96 |
(BV.gt_ii, simpleOp(Op.GT DstTy.IntTy)), |
(BV.gt_ii, simpleOp(Op.GT DstTy.IntTy)), |
97 |
(BV.gt_rr, simpleOp(Op.GT(DstTy.TensorTy[]))), |
(BV.gt_rr, simpleOp(Op.GT(DstTy.realTy))), |
98 |
(BV.equ_bb, simpleOp(Op.EQ DstTy.BoolTy)), |
(BV.equ_bb, simpleOp(Op.EQ DstTy.BoolTy)), |
99 |
(BV.equ_ii, simpleOp(Op.EQ DstTy.IntTy)), |
(BV.equ_ii, simpleOp(Op.EQ DstTy.IntTy)), |
100 |
(BV.equ_ss, simpleOp(Op.EQ DstTy.StringTy)), |
(BV.equ_ss, simpleOp(Op.EQ DstTy.StringTy)), |
101 |
(BV.equ_rr, simpleOp(Op.EQ(DstTy.TensorTy[]))), |
(BV.equ_rr, simpleOp(Op.EQ(DstTy.realTy))), |
102 |
(BV.neq_bb, simpleOp(Op.NEQ DstTy.BoolTy)), |
(BV.neq_bb, simpleOp(Op.NEQ DstTy.BoolTy)), |
103 |
(BV.neq_ii, simpleOp(Op.NEQ DstTy.IntTy)), |
(BV.neq_ii, simpleOp(Op.NEQ DstTy.IntTy)), |
104 |
(BV.neq_ss, simpleOp(Op.NEQ DstTy.StringTy)), |
(BV.neq_ss, simpleOp(Op.NEQ DstTy.StringTy)), |
105 |
(BV.neq_rr, simpleOp(Op.NEQ(DstTy.TensorTy[]))), |
(BV.neq_rr, simpleOp(Op.NEQ(DstTy.realTy))), |
106 |
(BV.neg_i, simpleOp(Op.Neg DstTy.IntTy)), |
(BV.add_ii, simpleOp Op.IAdd), |
107 |
(BV.neg_t, tensorOp Op.Neg), |
(BV.add_tt, fn (y, [shp], xs) => let |
108 |
(BV.neg_f, fn (y, _, xs) => assign(y, Op.NegField, xs)), |
val ty1 as DstTy.TensorTy dd1 = shapeVarToTensor shp |
109 |
(BV.op_at, fn (y, [_, dv, sv], xs) => |
val rator =mk.addTen(dd1) |
110 |
assign(y, Op.Probe(shapeVarToTensor sv, dimVarToTensor dv), xs)), |
in |
111 |
(BV.op_convolve, fn (y, _, xs) => assign(y, Op.Convolve, xs)), |
[assignEin(y, rator,xs)] |
112 |
(BV.op_D, fn (y, _, xs) => assign(y, Op.DiffField, xs)), |
end), |
113 |
(BV.op_norm, tensorOp Op.Norm), |
(BV.add_ff, fn (y, [_,Ty.DIM d, Ty.SHAPE dd], xs) => |
114 |
|
[assignEin(y, mk.addField(d, dd),xs)]), |
115 |
|
|
116 |
|
(BV.add_fr, fn (y, [_,Ty.DIM d], [f,s]) => |
117 |
|
[assignEin(y, mk.addTenField(d),[s,f])]), |
118 |
|
|
119 |
|
(BV.add_rf, fn (y, [_,Ty.DIM d], xs) => |
120 |
|
[assignEin(y, mk.addTenField(d),xs)]), |
121 |
|
|
122 |
|
|
123 |
|
(BV.sub_ii, simpleOp Op.ISub), |
124 |
|
(BV.sub_tt, fn (y, [shp], xs) => let |
125 |
|
val ty1 as DstTy.TensorTy dd1 = shapeVarToTensor shp |
126 |
|
val rator =mk.subTen(dd1) |
127 |
|
in |
128 |
|
[assignEin(y, rator,xs)] |
129 |
|
end), |
130 |
|
(BV.sub_ff, fn (y, [_,Ty.DIM d, Ty.SHAPE dd], xs) => |
131 |
|
[assignEin(y, mk.subField(d, dd),xs)]), |
132 |
|
|
133 |
|
|
134 |
|
(BV.sub_fr, fn (y, [_,Ty.DIM d], xs) => |
135 |
|
[assignEin(y, mk.subFieldTen(d),xs)]), |
136 |
|
|
137 |
|
(BV.sub_rf, fn (y, [_,Ty.DIM d], xs) => |
138 |
|
[assignEin(y, mk.subTenField(d),xs)]), |
139 |
|
|
140 |
|
(BV.mul_ii, simpleOp Op.IMul), |
141 |
|
(BV.mul_rr, fn (y,_,args) => [assignEin(y, mk.prodScalar,args)]), |
142 |
|
(BV.mul_rt, fn (y, [shp], xs) => let |
143 |
|
val ty1 as DstTy.TensorTy dd1 = shapeVarToTensor shp |
144 |
|
val rator =mk.scaleTen(dd1) |
145 |
|
in |
146 |
|
[assignEin(y, rator,xs)] |
147 |
|
end), |
148 |
|
(BV.mul_tr, fn (y, [shp], [t, r]) => let |
149 |
|
val ty1 as DstTy.TensorTy dd1 = shapeVarToTensor shp |
150 |
|
val rator = mk.scaleTen dd1 |
151 |
|
in |
152 |
|
[assignEin(y, rator,[r,t])] |
153 |
|
end), |
154 |
|
(BV.mul_rf, fn (y, [_,Ty.DIM d, Ty.SHAPE dd], xs) => |
155 |
|
[assignEin(y, mk.scaleField(d, dd),xs)]), |
156 |
|
(BV.mul_fr, fn (y, [_,Ty.DIM d, Ty.SHAPE dd], [f, s]) => |
157 |
|
[assignEin(y, mk.scaleField(d, dd),[s,f])]), |
158 |
|
(*MARK-mul_ff*) |
159 |
|
(BV.mul_ss, fn (y, [_,Ty.DIM d], xs) => |
160 |
|
[assignEin(y, mk.mulFieldss d,xs)]), |
161 |
|
(BV.mul_sf, fn (y, [_,Ty.DIM d, Ty.SHAPE dd], xs) => |
162 |
|
[assignEin(y, mk.mulFieldsf(d,dd),xs)]), |
163 |
|
(BV.mul_fs, fn (y, [_,Ty.DIM d, Ty.SHAPE dd], [f,s]) => |
164 |
|
[assignEin(y, mk.mulFieldsf(d,dd),[s,f])]), |
165 |
|
|
166 |
|
(BV.div_ii, simpleOp Op.IDiv), |
167 |
|
(BV.div_rr, fn (y,_,args) => [assignEin(y, mk.divScalar,args)]), |
168 |
|
(BV.div_tr, fn (y, [shp], xs) => let |
169 |
|
val ty1 as DstTy.TensorTy dd1 = shapeVarToTensor shp |
170 |
|
val rator =mk.divTen(dd1) |
171 |
|
in |
172 |
|
[assignEin(y, rator,xs)] |
173 |
|
end), |
174 |
|
(BV.div_fr, fn (y, [_,Ty.DIM d, Ty.SHAPE dd], xs) => |
175 |
|
[assignEin(y, mk.divideField(d, dd),xs)]), |
176 |
|
(BV.exp_ri, simpleOp(Op.Power)), |
177 |
|
(BV.exp_rr, basisFn MathFuns.pow), |
178 |
|
(BV.curl2D, simpleEOp mk.curl2d), |
179 |
|
(BV.curl3D, simpleEOp mk.curl3d), |
180 |
|
(BV.convolve_vk, fn (y, [_, Ty.DIM d, Ty.SHAPE dd], xs) => |
181 |
|
[assignEin(y, mk.conv(d, dd),xs)]), |
182 |
|
(BV.convolve_kv, fn (y, [_, Ty.DIM d, Ty.SHAPE dd], [k, v]) => |
183 |
|
[assignEin(y, mk.conv(d, dd),[v,k])]), |
184 |
|
(BV.neg_i, simpleOp Op.INeg), |
185 |
|
(BV.neg_t, fn (y, [shp], xs) => let |
186 |
|
val ty1 as DstTy.TensorTy dd1 = shapeVarToTensor shp |
187 |
|
val rator =mk.negTen(dd1) |
188 |
|
in |
189 |
|
[assignEin(y, rator,xs)] |
190 |
|
end), |
191 |
|
(BV.neg_f, fn (y, [_,Ty.DIM d, Ty.SHAPE dd], xs) => |
192 |
|
[assignEin(y, mk.negField(d, dd),xs)]), |
193 |
|
(BV.op_probe, fn (y, [_, Ty.DIM d, Ty.SHAPE dd], xs) => |
194 |
|
[assignEin(y, (mk.probe(dd,d)),xs)]), |
195 |
|
(BV.op_D, fn (y, [_, Ty.DIM d], xs) => [assignEin(y, mk.grad([d]),xs)]), |
196 |
|
|
197 |
|
(BV.op_Dotimes, fn (y, [_, Ty.DIM d1, Ty.SHAPE dd, Ty.DIM d2], xs) => let |
198 |
|
val x= print (String.concat[" d1:",Int.toString(d1)," d2:",Int.toString(d2), |
199 |
|
" shape:",Int.toString(length(dd)), "\n"]) |
200 |
|
val g=print "*******\n" |
201 |
|
val gg2=print(Int.toString(length(xs))) |
202 |
|
in |
203 |
|
[assignEin(y, mk.dotimes(d1, dd@[d2]),xs)] end ), |
204 |
|
(BV.op_Ddot, fn (y, [_, Ty.DIM d1, Ty.SHAPE dd, Ty.DIM d2], xs) => |
205 |
|
[assignEin(y, mk.divergence(d1, dd),xs)] ), |
206 |
|
|
207 |
|
|
208 |
|
(BV.op_norm, fn (y, [sv], xs) => (case shapeVarToTensor sv |
209 |
|
of DstTy.TensorTy[] => assign(y, Op.Abs DstTy.realTy, xs) |
210 |
|
| ty => assign(y, Op.Norm ty, xs) |
211 |
|
(* end case *))), |
212 |
(BV.op_not, simpleOp Op.Not), |
(BV.op_not, simpleOp Op.Not), |
213 |
(BV.fn_CL, fn (y, _, xs) => assign(y, Op.CL, xs)), |
(BV.op_cross, simpleEOp mk.crossProduct), |
214 |
(BV.fn_convolve, fn (y, _, [h, img]) => assign(y, Op.Convolve, [img, h])), |
(BV.op_crossField, simpleEOp mk.crossProductField), |
215 |
(BV.fn_cos, simpleOp Op.Cos), |
(BV.op_outer, fn (y, [Ty.DIM d1, Ty.DIM d2], xs) => |
216 |
(BV.fn_dot, vectorOp Op.Dot), |
[assignEin(y, (mk.outerProduct(d1, d2)), xs)]), |
217 |
(BV.fn_inside, fn (y, [_, dv, _], xs) => |
(* Any Shape fields |
218 |
assign(y, Op.Inside(dimVarToTensor dv), xs)), |
(BV.op_outerField, fn (y, [_, Ty.DIM d1, Ty.SHAPE dd1, Ty.SHAPE dd2], xs)=> |
219 |
|
[assignEin(y, mk.outerField(d1, dd1, dd2), xs)]), |
220 |
|
*) |
221 |
|
(BV.op_outerField, fn (y, [_, Ty.DIM d1], xs)=> |
222 |
|
[assignEin(y, mk.outerField(d1), xs)]), |
223 |
|
|
224 |
|
|
225 |
|
(BV.op_inner, fn (y, [sh1, sh2, _], xs) => let |
226 |
|
val ty1 as DstTy.TensorTy dd1 = shapeVarToTensor sh1 |
227 |
|
val ty2 as DstTy.TensorTy dd2 = shapeVarToTensor sh2 |
228 |
|
in |
229 |
|
[assignEin(y, (mk.innerProduct(dd1,dd2)),xs)] |
230 |
|
end), |
231 |
|
|
232 |
|
(BV.op_innerField, fn (y, [_,Ty.SHAPE dd1,Ty.DIM d,Ty.SHAPE dd2,_], xs) => |
233 |
|
let |
234 |
|
val _=print(String.concat["Translate Inner product Field. "]) |
235 |
|
in |
236 |
|
[assignEin(y, mk.innerProductField(dd1,d,dd2),xs)] end ), |
237 |
|
|
238 |
|
(BV.op_colon, fn (y, [sh1, sh2, _], xs) => let |
239 |
|
val ty1 as DstTy.TensorTy dd1 = shapeVarToTensor sh1 |
240 |
|
val ty2 as DstTy.TensorTy dd2 = shapeVarToTensor sh2 |
241 |
|
in |
242 |
|
[assignEin(y, (mk.doubleDot(dd1,dd2)),xs)] |
243 |
|
end), |
244 |
|
(BV.fn_inside, fn (y, [_, Ty.DIM d, _], xs) => assign(y, Op.Inside d, xs)), |
245 |
|
(BV.clamp_rrr, simpleOp (Op.Clamp DstTy.realTy)), |
246 |
|
(BV.clamp_vvv, vectorOp Op.Clamp), |
247 |
|
(BV.lerp3, tensorOp Op.Lerp), |
248 |
|
(BV.lerp5, fn (y, [sv], [a, b, x0, x, x1]) => let |
249 |
|
val t1 = IL.Var.new("t1", DstTy.realTy) |
250 |
|
val t2 = IL.Var.new("t2", DstTy.realTy) |
251 |
|
val t3 = IL.Var.new("t3", DstTy.realTy) |
252 |
|
in [ |
253 |
|
assignEin(t1, mk.subScalar,[x,x0]), |
254 |
|
assignEin(t2, mk.subScalar,[x1,x0]), |
255 |
|
assignEin(t3, mk.divScalar,[t1,t2]), |
256 |
|
IL.ASSGN(y, IL.OP(Op.Lerp(shapeVarToTensor sv), [a, b, t3])) |
257 |
|
] end), |
258 |
|
(BV.evals2x2, eigenVal (Op.Eigen2x2, 2)), |
259 |
|
(BV.evals3x3, eigenVal (Op.Eigen3x3, 3)), |
260 |
|
(BV.evecs2x2, eigenVec (Op.Eigen2x2, 2)), |
261 |
|
(BV.evecs3x3, eigenVec (Op.Eigen3x3, 3)), |
262 |
(BV.fn_max, simpleOp Op.Max), |
(BV.fn_max, simpleOp Op.Max), |
263 |
(BV.fn_min, simpleOp Op.Min), |
(BV.fn_min, simpleOp Op.Min), |
264 |
(BV.fn_modulate, vectorOp Op.Mul), |
|
265 |
(BV.fn_pow, simpleOp Op.Pow), |
(* modulate is vector * vector pointwise multiplication *) |
266 |
|
(BV.fn_modulate, fn (y,[Ty.DIM dd1], xs) => |
267 |
|
[assignEin(y, (mk.modulate dd1),xs)]), |
268 |
|
(BV.fn_normalize, vectorOp Op.Normalize), |
269 |
(BV.fn_principleEvec, vectorOp Op.PrincipleEvec), |
(BV.fn_principleEvec, vectorOp Op.PrincipleEvec), |
270 |
(BV.fn_sin, simpleOp Op.Sin), |
(BV.fn_trace, fn (y, [Ty.DIM d], xs) => |
271 |
|
[assignEin(y,(mk.trace d), xs)]), |
272 |
|
(BV.fn_traceField, fn (y, [_,Ty.DIM d,Ty.SHAPE dd], xs) => |
273 |
|
[assignEin(y,mk.traceField(d,dd), xs)]), |
274 |
|
|
275 |
|
(BV.fn_transpose, fn (y, [Ty.DIM d1, Ty.DIM d2], xs) => |
276 |
|
[assignEin(y, (mk.transpose [d1,d2]), xs)]), |
277 |
|
|
278 |
|
(BV.fn_transposeField, fn (y, [_,Ty.DIM d1, Ty.DIM d2,Ty.DIM d3], xs) => |
279 |
|
[assignEin(y, (mk.transposeField (d1,d2,d3)), xs)]), |
280 |
|
|
281 |
(BV.kn_bspln3, kernel Kernel.bspln3), |
(BV.kn_bspln3, kernel Kernel.bspln3), |
282 |
(BV.kn_bspln5, kernel Kernel.bspln5), |
(BV.kn_bspln5, kernel Kernel.bspln5), |
283 |
(BV.kn_ctmr, kernel Kernel.ctmr), |
(BV.kn_ctmr, kernel Kernel.ctmr), |
284 |
|
(BV.kn_c2ctmr, kernel Kernel.ctmr), |
285 |
|
(BV.kn_c4hexic, kernel Kernel.c4hexic), |
286 |
(BV.kn_tent, kernel Kernel.tent), |
(BV.kn_tent, kernel Kernel.tent), |
287 |
(BV.i2r, simpleOp Op.IntToReal) |
(BV.kn_c1tent, kernel Kernel.tent), |
288 |
|
(BV.i2r, simpleOp Op.IntToReal), |
289 |
|
(BV.identity, fn (y, [Ty.DIM d], xs) => |
290 |
|
[assignEin(y, (mk.identity d), xs)]), |
291 |
|
(* (BV.zero, fn (y, [sv], []) => |
292 |
|
assign(y, Op.Zero(shapeVarToTensor sv), [])),*) |
293 |
|
(BV.subscript, fn (y, [ty, Ty.DIM d], xs) => |
294 |
|
assign (y, Op.SeqSub(DstTy.SeqTy(trType ty, d)), xs)) |
295 |
|
(*, |
296 |
|
(BV.dynSubscript, fn (y, [tv], args) => |
297 |
|
assign(y, Op.SeqSub(DstTy.DynSeqTy(pruneTy tv)), args)) |
298 |
|
*) |
299 |
]; |
]; |
300 |
|
(* add C math functions *) |
301 |
|
List.app (fn (n, x) => insert(x, basisFn n)) BV.mathFns; |
302 |
tbl |
tbl |
303 |
end |
end |
304 |
|
|
306 |
of SOME transFn => transFn(y, mvs, xs) |
of SOME transFn => transFn(y, mvs, xs) |
307 |
| NONE => raise Fail("TranslateBasis.translate: unknown basis function " ^ Var.uniqueNameOf f) |
| NONE => raise Fail("TranslateBasis.translate: unknown basis function " ^ Var.uniqueNameOf f) |
308 |
(* end case *)) |
(* end case *)) |
309 |
|
handle ex => (print(concat["translate (", IL.Var.toString y, ", ", |
310 |
|
Var.uniqueNameOf f, ", ...)\n"]); raise ex) |
311 |
|
|
312 |
end |
end |