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 |
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 * Types.meta_var list * HighIL.var list) |
16 |
-> HighIL.assign list |
-> HighIL.assignment list |
17 |
|
|
18 |
end = struct |
end = struct |
19 |
|
|
20 |
structure BV = BasisVars |
structure BV = BasisVars |
21 |
structure IL = HighIL |
structure IL = HighIL |
22 |
|
structure DstTy = HighILTypes |
23 |
structure Op = HighOps |
structure Op = HighOps |
24 |
structure Ty = Types |
structure Ty = Types |
25 |
structure TU = TypeUtil |
structure TU = TypeUtil |
26 |
structure MV = MetaVar |
structure MV = MetaVar |
27 |
structure VTbl = Var.Tbl |
structure VTbl = Var.Tbl |
28 |
|
structure EinOp= Examples |
29 |
|
|
30 |
fun assign (y, rator, xs) = [(y, IL.OP(rator, xs))] |
fun pruneTy tv = (case TU.prune(MV.toType tv) |
31 |
|
of (ty as Ty.T_Var _) => raise Fail("unresolved type " ^ TU.toString ty) |
32 |
fun simpleOp rator (y, [], xs) = assign (y, rator, xs) |
| ty => TranslateTy.tr ty |
33 |
|
(* end case *)) |
34 |
|
|
35 |
fun pruneDim d = (case TU.pruneDim d |
fun pruneDim d = (case TU.pruneDim d |
36 |
of (Ty.DimConst n) => n |
of (Ty.DimConst n) => n |
37 |
| d => raise Fail("unresolved dimension " ^ TU.dimToString d) |
| d => raise Fail("unresolved dimension " ^ TU.dimToString d) |
38 |
(* end case *)) |
(* end case *)) |
39 |
|
|
40 |
fun tensorOp rator (y, [sv], xs) = (case TU.pruneShape(MV.toShape sv) |
fun pruneShape sv = (case TU.pruneShape(MV.toShape sv) |
41 |
of Ty.Shape dd => |
of Ty.Shape dd => DstTy.tensorTy(List.map pruneDim dd) |
|
assign (y, rator(Op.TensorTy(List.map pruneDim dd)), xs) |
|
42 |
| shp => raise Fail("unresolved shape " ^ TU.shapeToString shp) |
| shp => raise Fail("unresolved shape " ^ TU.shapeToString shp) |
43 |
(* end case *)) |
(* end case *)) |
44 |
|
|
45 |
fun vectorOp rator (y, [dv], xs) = |
fun dimVarToInt dv = pruneDim(MV.toDim dv) |
46 |
assign (y, rator(Op.TensorTy[pruneDim(MV.toDim dv)]), xs) |
fun dimVarToTensor dv = DstTy.tensorTy[dimVarToInt dv] |
47 |
|
fun dimVarToMatrix dv = let |
48 |
|
val d = dimVarToInt dv |
49 |
|
in |
50 |
|
DstTy.tensorTy[d, d] (* square matrix type *) |
51 |
|
end |
52 |
|
fun shapeVarToTensor sv = pruneShape sv |
53 |
|
|
54 |
|
fun assign (y, rator, xs) = [IL.ASSGN(y, IL.OP(rator, xs))] |
55 |
|
|
56 |
|
fun basisFn name (y, [], xs) = [IL.ASSGN(y, IL.APPLY(name, xs))] |
57 |
|
|
58 |
|
fun simpleOp rator (y, [], xs) = assign (y, rator, xs) |
59 |
|
|
60 |
|
fun tensorOp rator (y, [sv], xs) = assign (y, rator(shapeVarToTensor sv), xs) |
61 |
|
|
62 |
|
fun vectorOp rator (y, [dv], xs) = assign (y, rator(dimVarToTensor dv), xs) |
63 |
|
|
64 |
|
fun kernel h (y, [], []) = assign(y, Op.Kernel(h, 0), []) |
65 |
|
|
66 |
|
(* utility functions for synthesizing eigenvector/eigenvalue code *) |
67 |
|
fun eigenVec (rator, dim) = let |
68 |
|
val ty = DstTy.SeqTy(DstTy.realTy, dim) |
69 |
|
in |
70 |
|
fn (y, _, [m]) => let |
71 |
|
val v = IL.Var.new("evals", ty) |
72 |
|
in |
73 |
|
[IL.MASSGN([v, y], rator, [m])] |
74 |
|
end |
75 |
|
end |
76 |
|
fun eigenVal (rator, dim) = let |
77 |
|
val ty = DstTy.SeqTy(DstTy.vecTy dim, dim) |
78 |
|
in |
79 |
|
fn (y, _, [m]) => let |
80 |
|
val v = IL.Var.new("evecs", ty) |
81 |
|
in |
82 |
|
[IL.MASSGN([y, v], rator, [m])] |
83 |
|
end |
84 |
|
end |
85 |
|
|
86 |
|
fun assignEin(*hmm*) |
87 |
|
|
88 |
|
fun createScalarEin rator(y, [],xs)= assignEin (y,rator, xs) |
89 |
|
|
90 |
|
fun createTenEin rator(y, [sv], xs)= assignEin(y, rator(shapeVarToTensor sv), xs) |
91 |
|
|
92 |
|
|
93 |
|
|
|
fun kernel h (y, [], []) = assign(y, Op.Kernel h, []) |
|
94 |
|
|
95 |
(* build a table that maps Basis variables to their translation functions *) |
(* build a table that maps Basis variables to their translation functions *) |
96 |
val tbl : ((IL.var * Ty.meta_var list * IL.var list) -> IL.assign list) VTbl.hash_table = let |
val tbl : ((IL.var * Ty.meta_var list * IL.var list) -> IL.assignment list) VTbl.hash_table = let |
97 |
val tbl = VTbl.mkTable (128, Fail "Translate table") |
val tbl = VTbl.mkTable (128, Fail "Translate table") |
98 |
|
val insert = VTbl.insert tbl |
99 |
in |
in |
100 |
List.app (VTbl.insert tbl) [ |
List.app insert [ |
101 |
(BV.add_ii, simpleOp(Op.Add Op.IntTy)), |
(BV.lt_ii, simpleOp(Op.LT DstTy.IntTy)), |
102 |
(BV.add_tt, tensorOp Op.Add), |
(BV.lt_rr, simpleOp(Op.LT DstTy.realTy)), |
103 |
(BV.sub_ii, simpleOp(Op.Sub Op.IntTy)), |
(BV.lte_ii, simpleOp(Op.LTE DstTy.IntTy)), |
104 |
(BV.sub_tt, tensorOp Op.Sub), |
(BV.lte_rr, simpleOp(Op.LTE DstTy.realTy)), |
105 |
(BV.mul_ii, simpleOp(Op.Mul Op.IntTy)), |
(BV.gte_ii, simpleOp(Op.GTE DstTy.IntTy)), |
106 |
(BV.mul_rr, simpleOp(Op.Mul(Op.TensorTy[]))), |
(BV.gte_rr, simpleOp(Op.GTE(DstTy.realTy))), |
107 |
(BV.mul_rt, tensorOp Op.Scale), |
(BV.gt_ii, simpleOp(Op.GT DstTy.IntTy)), |
108 |
(BV.mul_tr, fn (y, sv, [t, r]) => tensorOp Op.Scale (y, sv, [r, t])), |
(BV.gt_rr, simpleOp(Op.GT(DstTy.realTy))), |
109 |
(BV.div_ii, simpleOp(Op.Div Op.IntTy)), |
(BV.equ_bb, simpleOp(Op.EQ DstTy.BoolTy)), |
110 |
(BV.div_rr, simpleOp(Op.Div(Op.TensorTy[]))), |
(BV.equ_ii, simpleOp(Op.EQ DstTy.IntTy)), |
111 |
(BV.div_tr, tensorOp Op.InvScale), |
(BV.equ_ss, simpleOp(Op.EQ DstTy.StringTy)), |
112 |
(BV.lt_ii, simpleOp(Op.LT Op.IntTy)), |
(BV.equ_rr, simpleOp(Op.EQ(DstTy.realTy))), |
113 |
(BV.lt_rr, simpleOp(Op.LT(Op.TensorTy[]))), |
(BV.neq_bb, simpleOp(Op.NEQ DstTy.BoolTy)), |
114 |
(BV.lte_ii, simpleOp(Op.LTE Op.IntTy)), |
(BV.neq_ii, simpleOp(Op.NEQ DstTy.IntTy)), |
115 |
(BV.lte_rr, simpleOp(Op.LTE(Op.TensorTy[]))), |
(BV.neq_ss, simpleOp(Op.NEQ DstTy.StringTy)), |
116 |
(BV.gte_ii, simpleOp(Op.GTE Op.IntTy)), |
(BV.neq_rr, simpleOp(Op.NEQ(DstTy.realTy))), |
117 |
(BV.gte_rr, simpleOp(Op.GTE(Op.TensorTy[]))), |
|
118 |
(BV.gt_ii, simpleOp(Op.GT Op.IntTy)), |
(* Changed*) |
119 |
(BV.gt_rr, simpleOp(Op.GT(Op.TensorTy[]))), |
|
120 |
(BV.equ_bb, simpleOp(Op.EQ Op.BoolTy)), |
(BV.add_ii, createScalarEin(EinOp.addScalars)), (* DstTy.IntTy*) |
121 |
(BV.equ_ii, simpleOp(Op.EQ Op.IntTy)), |
(BV.add_tt, createTenEin(EinOp.addTensors)), |
122 |
(BV.equ_ss, simpleOp(Op.EQ Op.StringTy)), |
(BV.add_ff, fn (y, _, [f, g]) => assignEin(y, EinOp.addField, [f, g])), |
123 |
(BV.equ_rr, simpleOp(Op.EQ(Op.TensorTy[]))), |
(BV.add_fr, fn (y, _, [f, s]) => assignEin(y, EinOp.addTenField, [f, s])), |
124 |
(BV.neq_bb, simpleOp(Op.NEQ Op.BoolTy)), |
(BV.add_rf, fn (y, _, [s, f]) => assignEin(y, EinOp.addTenField, [f, s])), |
125 |
(BV.neq_ii, simpleOp(Op.NEQ Op.IntTy)), |
|
126 |
(BV.neq_ss, simpleOp(Op.NEQ Op.StringTy)), |
(BV.sub_ii, createScalarEin(EinOp.subScalars)), (*DstTy.IntTy*) |
127 |
(BV.neq_rr, simpleOp(Op.NEQ(Op.TensorTy[]))), |
(BV.sub_tt, createTenEin(EinOp.subTensor)), |
128 |
(BV.neg_i, simpleOp(Op.Neg Op.IntTy)), |
(BV.sub_ff, fn (y, _, [f, g]) => assignEin(y, EinOp.subField, [f, g])), |
129 |
|
|
130 |
|
(* UnChanged*) |
131 |
|
(BV.sub_fr, fn (y, _, [f, s]) => let |
132 |
|
val s' = IL.Var.copy s |
133 |
|
in [ |
134 |
|
IL.ASSGN(s', IL.OP(Op.Neg DstTy.realTy, [s])), |
135 |
|
IL.ASSGN(y, IL.OP(Op.OffsetField, [f, s'])) |
136 |
|
] end), |
137 |
|
|
138 |
|
(BV.sub_rf, fn (y, _, [s, f]) => let |
139 |
|
val f' = IL.Var.copy f |
140 |
|
in [ |
141 |
|
IL.ASSGN(f', IL.OP(Op.NegField, [f])), |
142 |
|
IL.ASSGN(y, IL.OP(Op.OffsetField, [f', s])) |
143 |
|
] end), |
144 |
|
(* Changed*) |
145 |
|
(BV.mul_ii, createScalarEin(EinOp.scalarxscalar)), (* DstTy.IntTy)),*) |
146 |
|
(BV.mul_rr, createScalarEin(EinOp.scalarxscalar)), (*(DstTy.realTy))),*) |
147 |
|
(BV.mul_rt, createTenEin(EinOp.scaleTensor)), (*tensorOp Op.Scale),*) |
148 |
|
(BV.mul_tr, fn (y, sv, [t, r]) => createTenEin EinOp.scaleTensor (y, sv, [r, t])), |
149 |
|
(BV.mul_rf, fn (y, _, [s, f]) => assignEin(y, EinOp.scaleField, [s, f])), |
150 |
|
(BV.mul_fr, fn (y, _, [f, s]) => assignEin(y, EinOp.scaleField, [s, f])), |
151 |
|
|
152 |
|
(* UnChanged*) |
153 |
|
|
154 |
|
(BV.div_ii, simpleOp(Op.Div DstTy.IntTy)), |
155 |
|
(BV.div_rr, simpleOp(Op.Div DstTy.realTy)), |
156 |
|
(BV.div_tr, fn (y, [sv], [x, s]) => let |
157 |
|
val one = IL.Var.new("one", DstTy.realTy) |
158 |
|
val s' = IL.Var.new("sInv", DstTy.realTy) |
159 |
|
in [ |
160 |
|
IL.ASSGN(one, IL.LIT(Literal.Float(FloatLit.one))), |
161 |
|
IL.ASSGN(s', IL.OP(Op.Div DstTy.realTy, [one, s])), |
162 |
|
IL.ASSGN(y, IL.OP(Op.Scale(shapeVarToTensor sv), [s', x])) |
163 |
|
] end), |
164 |
|
(BV.div_fr, fn (y, _, [f, s]) => let |
165 |
|
val one = IL.Var.new("one", DstTy.realTy) |
166 |
|
val s' = IL.Var.new("sInv", DstTy.realTy) |
167 |
|
in [ |
168 |
|
IL.ASSGN(one, IL.LIT(Literal.Float(FloatLit.one))), |
169 |
|
IL.ASSGN(s', IL.OP(Op.Div DstTy.realTy, [one, s])), |
170 |
|
IL.ASSGN(y, IL.OP(Op.ScaleField, [s', f])) |
171 |
|
] end), |
172 |
|
(BV.exp_ri, simpleOp(Op.Power)), |
173 |
|
(BV.exp_rr, basisFn MathFuns.pow), |
174 |
|
|
175 |
|
(* Changed*) |
176 |
|
(BV.curl2D, fn (y, _, xs) => assignEin(y, EinOp.Curl2d, xs)), |
177 |
|
(BV.curl3D, fn (y, _, xs) => assignEin(y, EinOp.Curl3d, xs)), |
178 |
|
|
179 |
|
|
180 |
|
(* UnChanged*) |
181 |
|
(BV.convolve_vk, fn (y, [_, dv, _], xs) => |
182 |
|
assign(y, Op.Field(pruneDim(MV.toDim dv)), xs)), |
183 |
|
(BV.convolve_kv, fn (y, [_, dv, _], [k, v]) => |
184 |
|
assign(y, Op.Field(pruneDim(MV.toDim dv)), [v, k])), |
185 |
|
|
186 |
|
|
187 |
|
(BV.neg_i, simpleOp(Op.Neg DstTy.IntTy)), |
188 |
(BV.neg_t, tensorOp Op.Neg), |
(BV.neg_t, tensorOp Op.Neg), |
189 |
(BV.neg_f, fn (y, _, xs) => assign(y, Op.NegField, xs)), |
(BV.neg_f, fn (y, _, xs) => assign(y, Op.NegField, xs)), |
190 |
(BV.op_at, fn (y, _, xs) => assign(y, Op.Probe, xs)), |
(BV.op_probe, fn (y, [_, dv, sv], xs) => |
191 |
(BV.op_convolve, fn (y, _, xs) => assign(y, Op.Convolve, xs)), |
assign(y, Op.Probe(dimVarToTensor dv, shapeVarToTensor sv), xs)), |
192 |
(BV.op_D, fn (y, _, xs) => assign(y, Op.DiffField, xs)), |
|
193 |
(BV.op_norm, tensorOp Op.Norm), |
(* Changed*) |
194 |
|
(BV.op_D, fn (y, _, xs) => assignEin(y, EinOp.Grad, xs)), |
195 |
|
(BV.op_Dotimes, fn (y, _, xs) => assignEin(y, EinOp.Divergence, xs)), |
196 |
|
|
197 |
|
(* UnChanged*) |
198 |
|
(BV.op_norm, fn (y, [sv], xs) => (case shapeVarToTensor sv |
199 |
|
of DstTy.TensorTy[] => assign(y, Op.Abs DstTy.realTy, xs) |
200 |
|
| ty => assign(y, Op.Norm ty, xs) |
201 |
|
(* end case *))), |
202 |
(BV.op_not, simpleOp Op.Not), |
(BV.op_not, simpleOp Op.Not), |
203 |
(* |
|
204 |
(BV.op_subscript, fn (y, [SK, NK], xs) => ??), (*FIXME*) |
(* Changed*) |
205 |
*) |
(BV.op_cross, createScalarEin EinOp.crossProduct), |
206 |
(BV.fn_CL, fn (y, _, xs) => assign(y, Op.CL, xs)), |
(BV.op_outer, assignEin (y, EinOp.outerProduct, xs) |
207 |
(BV.fn_convolve, fn (y, _, [h, img]) => assign(y, Op.Convolve, [img, h])), |
(* fn (y, [dv1, dv2], xs) => let |
208 |
(BV.fn_cos, simpleOp Op.Cos), |
val d1 = pruneDim(MV.toDim dv1) |
209 |
(BV.fn_dot, vectorOp Op.Dot), |
val d2 = pruneDim(MV.toDim dv2) |
210 |
(BV.fn_inside, fn (y, _, xs) => assign(y, Op.Inside, xs)), |
in |
211 |
(* |
(DstTy.tensorTy[d1, d2]), xs) |
212 |
(BV.fn_load, fn (y, [NK, SK], xs) => ??), (*FIXME*) |
end),*) |
213 |
|
|
214 |
|
|
215 |
|
(BV.op_inner, fn (y,_,xs)=assignEin(y,EinOp.innerProduct ,xs)), |
216 |
|
|
217 |
|
(* fn (y, [sh1, sh2, _], xs) => let |
218 |
|
val ty1 as DstTy.TensorTy dd1 = pruneShape sh1 |
219 |
|
val ty2 as DstTy.TensorTy dd2 = pruneShape sh2 |
220 |
|
val rator = (case (dd1, dd2) |
221 |
|
of ([d], [d']) => Op.Dot ty1 |
222 |
|
| ([d1], [d1', d2]) => Op.MulVecMat ty2 |
223 |
|
| ([d1, d2], [d2']) => Op.MulMatVec ty1 |
224 |
|
| ([d1, d2], [d2', d3]) => Op.MulMatMat(ty1, ty2) |
225 |
|
| ([d1], [d1', d2, d3]) => Op.MulVecTen3 ty2 |
226 |
|
| ([d1, d2, d3], [d3']) => Op.MulTen3Vec ty1 |
227 |
|
| _ => raise Fail(concat[ |
228 |
|
"unsupported inner-product: ", |
229 |
|
DstTy.toString ty1, " * ", DstTy.toString ty2 |
230 |
|
]) |
231 |
|
(* end case *)) |
232 |
|
in |
233 |
|
assign (y, rator, xs) |
234 |
|
end), |
235 |
*) |
*) |
236 |
(BV.fn_max, simpleOp Op.Min), |
(BV.op_colon, fn (y,_, xs)=>assignEin (EinOp.doubleDot, xs)), |
237 |
(BV.fn_min, simpleOp Op.Max), |
|
238 |
|
(*fn (y, [sh1, sh2, _], xs) => let |
239 |
|
val ty1 as DstTy.TensorTy dd1 = pruneShape sh1 |
240 |
|
val ty2 as DstTy.TensorTy dd2 = pruneShape sh2 |
241 |
|
in |
242 |
|
assign (y, Op.ColonMul(ty1, ty2), xs) |
243 |
|
end),*) |
244 |
|
(* UnChanged*) |
245 |
|
(BV.fn_inside, fn (y, [_, dv, _], xs) => |
246 |
|
assign(y, Op.Inside(pruneDim(MV.toDim dv)), xs)), |
247 |
|
(BV.clamp_rrr, simpleOp (Op.Clamp DstTy.realTy)), |
248 |
|
(BV.clamp_vvv, vectorOp Op.Clamp), |
249 |
|
(BV.lerp3, tensorOp Op.Lerp), |
250 |
|
(BV.lerp5, fn (y, [sv], [a, b, x0, x, x1]) => let |
251 |
|
val t1 = IL.Var.new("t1", DstTy.realTy) |
252 |
|
val t2 = IL.Var.new("t2", DstTy.realTy) |
253 |
|
val t3 = IL.Var.new("t3", DstTy.realTy) |
254 |
|
in [ |
255 |
|
IL.ASSGN(t1, IL.OP(Op.Sub DstTy.realTy, [x, x0])), |
256 |
|
IL.ASSGN(t2, IL.OP(Op.Sub DstTy.realTy, [x1, x0])), |
257 |
|
IL.ASSGN(t3, IL.OP(Op.Div DstTy.realTy, [t1, t2])), |
258 |
|
IL.ASSGN(y, IL.OP(Op.Lerp(shapeVarToTensor sv), [a, b, t3])) |
259 |
|
] end), |
260 |
|
(BV.evals2x2, eigenVal (Op.Eigen2x2, 2)), |
261 |
|
(BV.evals3x3, eigenVal (Op.Eigen3x3, 3)), |
262 |
|
(BV.evecs2x2, eigenVec (Op.Eigen2x2, 2)), |
263 |
|
(BV.evecs3x3, eigenVec (Op.Eigen3x3, 3)), |
264 |
|
(BV.fn_max, simpleOp Op.Max), |
265 |
|
(BV.fn_min, simpleOp Op.Min), |
266 |
(BV.fn_modulate, vectorOp Op.Mul), |
(BV.fn_modulate, vectorOp Op.Mul), |
267 |
(BV.fn_pow, simpleOp Op.Pow), |
(BV.fn_normalize, vectorOp Op.Normalize), |
268 |
(BV.fn_principleEvec, vectorOp Op.PrincipleEvec), |
(BV.fn_principleEvec, vectorOp Op.PrincipleEvec), |
269 |
(BV.fn_sin, simpleOp Op.Sin), |
|
270 |
|
(* Changed*) |
271 |
|
(BV.fn_trace, fn (y, [dv], xs) => assignEin(y, EinOp.Trace,xs)), |
272 |
|
(*(dimVarToMatrix dv), xs)),*) |
273 |
|
|
274 |
|
(* UnChanged*) |
275 |
|
(BV.fn_transpose, fn (y, [dv1, dv2], xs) => |
276 |
|
assign(y, Op.Transpose(dimVarToInt dv1, dimVarToInt dv2), xs)), |
277 |
(BV.kn_bspln3, kernel Kernel.bspln3), |
(BV.kn_bspln3, kernel Kernel.bspln3), |
278 |
(BV.kn_bspln5, kernel Kernel.bspln5), |
(BV.kn_bspln5, kernel Kernel.bspln5), |
279 |
(BV.kn_ctmr, kernel Kernel.ctmr), |
(BV.kn_ctmr, kernel Kernel.ctmr), |
280 |
|
(BV.kn_c2ctmr, kernel Kernel.ctmr), |
281 |
|
(BV.kn_c4hexic, kernel Kernel.c4hexic), |
282 |
(BV.kn_tent, kernel Kernel.tent), |
(BV.kn_tent, kernel Kernel.tent), |
283 |
(BV.i2r, simpleOp Op.IntToReal)(*, |
(BV.kn_c1tent, kernel Kernel.tent), |
284 |
(BV.input, fn (y, [TK], xs) => ??), (*FIXME*) |
(BV.i2r, simpleOp Op.IntToReal), |
285 |
(BV.optInput, fn (y, [TK], xs) => ??) (*FIXME*) |
|
286 |
*) |
(* Changed*) |
287 |
|
(BV.identity, fn (y, [dv], []) =>assignEin(y, EinOp.identity,[])), |
288 |
|
(* assign(y, Op.Identity(pruneDim(MV.toDim dv)), [])),*) |
289 |
|
(* UnChanged*) |
290 |
|
(BV.zero, fn (y, [sv], []) => |
291 |
|
assign(y, Op.Zero(shapeVarToTensor sv), [])), |
292 |
|
(BV.subscript, fn (y, [tv, dv], args) => |
293 |
|
assign(y, |
294 |
|
Op.SeqSub(DstTy.SeqTy(pruneTy tv, pruneDim(MV.toDim dv))), |
295 |
|
args)) |
296 |
]; |
]; |
297 |
|
(* add C math functions *) |
298 |
|
List.app (fn (n, x) => insert(x, basisFn n)) BV.mathFns; |
299 |
tbl |
tbl |
300 |
end |
end |
301 |
|
|
302 |
fun translate (y, f, mvs, xs) = (case VTbl.find tbl f |
fun translate (y, f, mvs, xs) = (case VTbl.find tbl f |
303 |
of SOME transFn => transFn(y, mvs, xs) |
of SOME transFn => transFn(y, mvs, xs) |
304 |
| NONE => raise Fail("TranslateBasis.translate: unknown function " ^ Var.uniqueNameOf f) |
| NONE => raise Fail("TranslateBasis.translate: unknown basis function " ^ Var.uniqueNameOf f) |
305 |
(* end case *)) |
(* end case *)) |
306 |
|
handle ex => (print(concat["translate (", IL.Var.toString y, ", ", |
307 |
|
Var.uniqueNameOf f, ", ...)\n"]); raise ex) |
308 |
|
|
309 |
end |
end |