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, []) |
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 |
|
|
89 |
|
fun createTenEin(operator, sv)=S.transform(operator,[len(sv), sv]) |
90 |
|
fun createFldEin(operator, f)=S.transform(operator,[ ]) |
91 |
|
|
92 |
|
fun ScaGenToEin rator(y, [],xs)= assignEin (y,S.transform(rator,[]), xs) |
93 |
|
fun GenToEin rator(y,[sv],xs)= assignEin(y,createTenEin(rator,sv),xs) |
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, ScaGenToEin(EinOp.addScalars)), |
121 |
(BV.equ_ii, simpleOp(Op.EQ Op.IntTy)), |
(BV.add_tt, GenToEin(EinOp.addTensors)), |
122 |
(BV.equ_ss, simpleOp(Op.EQ Op.StringTy)), |
|
123 |
(BV.equ_rr, simpleOp(Op.EQ(Op.TensorTy[]))), |
(*Ein*) |
124 |
(BV.neq_bb, simpleOp(Op.NEQ Op.BoolTy)), |
(BV.add_ff, fn (y, _, [f, g]) |
125 |
(BV.neq_ii, simpleOp(Op.NEQ Op.IntTy)), |
=>assignEin(y, createFldEin(EinOp.addField,f ), [f, g])), |
126 |
(BV.neq_ss, simpleOp(Op.NEQ Op.StringTy)), |
(BV.add_fr, fn (y, _, [f, s]) |
127 |
(BV.neq_rr, simpleOp(Op.NEQ(Op.TensorTy[]))), |
=> assignEin(y, createFldEin(EinOp.addTenField,f ), [f, s])), |
128 |
(BV.neg_i, simpleOp(Op.Neg Op.IntTy)), |
(BV.add_rf, fn (y, _, [s, f]) |
129 |
|
=> assignEin(y, createFldEin(EinOp.addTenField,f ), [f, s])), |
130 |
|
|
131 |
|
(BV.sub_ii, ScaGenToEin(EinOp.subScalars)), (*DstTy.IntTy*) |
132 |
|
(BV.sub_tt, GenToEin(EinOp.subTensor)), |
133 |
|
(BV.sub_ff, fn (y, _, [f, g]) |
134 |
|
=> assignEin(y, createFldEin(EinOp.subField,f), [f, g])), |
135 |
|
|
136 |
|
(* UnChanged*) |
137 |
|
(BV.sub_fr, fn (y, _, [f, s]) => let |
138 |
|
val s' = IL.Var.copy s |
139 |
|
in [ |
140 |
|
IL.ASSGN(s', IL.OP(Op.Neg DstTy.realTy, [s])), |
141 |
|
IL.ASSGN(y, IL.OP(Op.OffsetField, [f, s'])) |
142 |
|
] end), |
143 |
|
|
144 |
|
(BV.sub_rf, fn (y, _, [s, f]) => let |
145 |
|
val f' = IL.Var.copy f |
146 |
|
in [ |
147 |
|
IL.ASSGN(f', IL.OP(Op.NegField, [f])), |
148 |
|
IL.ASSGN(y, IL.OP(Op.OffsetField, [f', s])) |
149 |
|
] end), |
150 |
|
(* Changed*) |
151 |
|
(BV.mul_ii, ScaGenToEin(EinOp.scalarxscalar)), |
152 |
|
(BV.mul_rr, ScaGenToEin(EinOp.scalarxscalar)), |
153 |
|
(BV.mul_rt, GenToEin(EinOp.scaleTensor)), (*tensorOp Op.Scale),*) |
154 |
|
|
155 |
|
(BV.mul_tr, fn (y, sv, [t, r]) |
156 |
|
=>assignEin(y,createTenEin(EinOp.scaleTensor, sv), [r,t]) |
157 |
|
|
158 |
|
|
159 |
|
(BV.mul_rf, fn (y, _, [s, f]) => assignEin(y, createFldEin(EinOp.scaleField,f), [s, f])), |
160 |
|
(BV.mul_fr, fn (y, _, [f, s]) => assignEin(y, createFldEin(EinOp.scaleField,f), [s, f])), |
161 |
|
|
162 |
|
(* UnChanged*) |
163 |
|
|
164 |
|
(BV.div_ii, simpleOp(Op.Div DstTy.IntTy)), |
165 |
|
(BV.div_rr, simpleOp(Op.Div DstTy.realTy)), |
166 |
|
(BV.div_tr, fn (y, [sv], [x, s]) => let |
167 |
|
val one = IL.Var.new("one", DstTy.realTy) |
168 |
|
val s' = IL.Var.new("sInv", DstTy.realTy) |
169 |
|
in [ |
170 |
|
IL.ASSGN(one, IL.LIT(Literal.Float(FloatLit.one))), |
171 |
|
IL.ASSGN(s', IL.OP(Op.Div DstTy.realTy, [one, s])), |
172 |
|
IL.ASSGN(y, IL.OP(Op.Scale(shapeVarToTensor sv), [s', x])) |
173 |
|
] end), |
174 |
|
(BV.div_fr, fn (y, _, [f, s]) => let |
175 |
|
val one = IL.Var.new("one", DstTy.realTy) |
176 |
|
val s' = IL.Var.new("sInv", DstTy.realTy) |
177 |
|
in [ |
178 |
|
IL.ASSGN(one, IL.LIT(Literal.Float(FloatLit.one))), |
179 |
|
IL.ASSGN(s', IL.OP(Op.Div DstTy.realTy, [one, s])), |
180 |
|
IL.ASSGN(y, IL.OP(Op.ScaleField, [s', f])) |
181 |
|
] end), |
182 |
|
(BV.exp_ri, simpleOp(Op.Power)), |
183 |
|
(BV.exp_rr, basisFn MathFuns.pow), |
184 |
|
|
185 |
|
(* Changed*) |
186 |
|
(BV.curl2D, fn (y, _, xs) => assignEin(y, EinOp.Curl2d, xs)), |
187 |
|
(BV.curl3D, fn (y, _, xs) => assignEin(y, EinOp.Curl3d, xs)), |
188 |
|
|
189 |
|
|
190 |
|
(* UnChanged*) |
191 |
|
(BV.convolve_vk, fn (y, [_, dv, _], xs) => |
192 |
|
assign(y, Op.Field(pruneDim(MV.toDim dv)), xs)), |
193 |
|
(BV.convolve_kv, fn (y, [_, dv, _], [k, v]) => |
194 |
|
assign(y, Op.Field(pruneDim(MV.toDim dv)), [v, k])), |
195 |
|
|
196 |
|
|
197 |
|
(BV.neg_i, simpleOp(Op.Neg DstTy.IntTy)), |
198 |
(BV.neg_t, tensorOp Op.Neg), |
(BV.neg_t, tensorOp Op.Neg), |
199 |
(BV.neg_f, fn (y, _, xs) => assign(y, Op.NegField, xs)), |
(BV.neg_f, fn (y, _, xs) => assign(y, Op.NegField, xs)), |
200 |
(BV.op_at, fn (y, _, xs) => assign(y, Op.Probe, xs)), |
(BV.op_probe, fn (y, [_, dv, sv], xs) => |
201 |
(BV.op_D, fn (y, _, xs) => assign(y, Op.DiffField, xs)), |
assign(y, Op.Probe(dimVarToTensor dv, shapeVarToTensor sv), xs)), |
202 |
(BV.op_norm, tensorOp Op.Norm), |
|
203 |
|
(* Changed*) |
204 |
|
(BV.op_D, fn (y, _, xs) => assignEin(y, createFldEin(EinOp.Grad,xs), xs)), |
205 |
|
(BV.op_Dotimes, fn (y, _, xs) => assignEin(y, createFldEin(EinOp.Divergence,xs), xs)), |
206 |
|
|
207 |
|
(* UnChanged*) |
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 |
(* |
|
214 |
(BV.op_subscript, fn (y, [SK, NK], xs) => ??), (*FIXME*) |
(* Changed*) |
215 |
*) |
(BV.op_cross, fn(y, _ , xs )=> assignEin(y,EinOp.crossProductE ,xs) |
216 |
(BV.fn_CL, fn (y, _, xs) => assign(y, Op.CL, xs)), |
(BV.op_outer, fn (y, [dv1, dv2], xs) => let |
217 |
(BV.fn_convolve, fn (y, _, xs) => assign(y, Op.Convolve, xs)), |
val d1 = pruneDim(MV.toDim dv1) |
218 |
(BV.fn_cos, simpleOp Op.Cos), |
val d2 = pruneDim(MV.toDim dv2) |
219 |
(BV.fn_dot, vectorOp Op.Dot), |
in assignEin( y, S.transform(EinOp.outerProduct,[(length(d1),d1), (length(d2),d2)]),xs) |
220 |
(BV.fn_inside, fn (y, _, xs) => assign(y, Op.Inside, xs)), |
end |
221 |
(* |
(*Here, d1, d2 is an int, but we want a list.*) |
222 |
(BV.fn_load, fn (y, [NK, SK], xs) => ??), (*FIXME*) |
|
223 |
*) |
(* Assuming dd1, ddd2 are lists of dimensions*) |
224 |
(BV.fn_max, simpleOp Op.Min), |
(BV.op_inner, fn (y, [sh1, sh2, _], xs) => let |
225 |
(BV.fn_min, simpleOp Op.Max), |
val ty1 as DstTy.TensorTy dd1 = pruneShape sh1 |
226 |
|
val ty2 as DstTy.TensorTy dd2 = pruneShape sh2 |
227 |
|
val ilist= [(length(dd1)-1, List.take(dd1, length(dd1)-1) ) , |
228 |
|
( length(dd2)-1, tl(dd2)), |
229 |
|
( 0, [hd(dd2)]) ] |
230 |
|
in assignEin(y, S.tranform(EinOp.innerProduct, ilist),xs) end), |
231 |
|
|
232 |
|
|
233 |
|
(BV.op_colon, fn (y, [sh1, sh2, _], xs) => let |
234 |
|
val ty1 as DstTy.TensorTy dd1 = pruneShape sh1 |
235 |
|
val ty2 as DstTy.TensorTy dd2 = pruneShape sh2 |
236 |
|
val ilist= [ (length(dd1)-2 , List.take(q, length(q)-2)) , |
237 |
|
( length(dd2)-2 , tl(tl(dd2))), |
238 |
|
(_, List.take(dd2,2))] |
239 |
|
in assignEin(y, S.transform(EinOp.doubleDot, ilist),xs) end), |
240 |
|
|
241 |
|
|
242 |
|
(* UnChanged*) |
243 |
|
(BV.fn_inside, fn (y, [_, dv, _], xs) => |
244 |
|
assign(y, Op.Inside(pruneDim(MV.toDim dv)), 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 |
|
IL.ASSGN(t1, IL.OP(Op.Sub DstTy.realTy, [x, x0])), |
254 |
|
IL.ASSGN(t2, IL.OP(Op.Sub DstTy.realTy, [x1, x0])), |
255 |
|
IL.ASSGN(t3, IL.OP(Op.Div DstTy.realTy, [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), |
263 |
|
(BV.fn_min, simpleOp Op.Min), |
264 |
(BV.fn_modulate, vectorOp Op.Mul), |
(BV.fn_modulate, vectorOp Op.Mul), |
265 |
(BV.fn_pow, simpleOp Op.Pow), |
(BV.fn_normalize, vectorOp Op.Normalize), |
266 |
(BV.fn_principleEvec, vectorOp Op.PrincipleEvec), |
(BV.fn_principleEvec, vectorOp Op.PrincipleEvec), |
267 |
(BV.fn_sin, simpleOp Op.Sin), |
|
268 |
|
(* Changed*) |
269 |
|
(BV.fn_trace, fn (y, [dv], xs) => (let |
270 |
|
val i=pruneDim(MV.toDim dv) (* (dimVarToMatrix dv)*) |
271 |
|
(*we need i to be the dimension n of an n xn matrix*) |
272 |
|
in assignEin(y,S.transform(EinOp.trace, [1,i]),xs) end) |
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], []) =>(let |
288 |
|
val i=pruneDim(MV.toDim dv) |
289 |
|
(*we need i to be the dimension n of an n xn matrix*) |
290 |
|
in assignEin(y, S.transform(EinOp.identity,[(1,i),(1,i)]),[]) end)), |
291 |
|
|
292 |
|
(* UnChanged*) |
293 |
|
(BV.zero, fn (y, [sv], []) => |
294 |
|
assign(y, Op.Zero(shapeVarToTensor sv), [])), |
295 |
|
(BV.subscript, fn (y, [tv, dv], args) => |
296 |
|
assign(y, |
297 |
|
Op.SeqSub(DstTy.SeqTy(pruneTy tv, pruneDim(MV.toDim dv))), |
298 |
|
args)) |
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 |
|
|
305 |
fun translate (y, f, mvs, xs) = (case VTbl.find tbl f |
fun translate (y, f, mvs, xs) = (case VTbl.find tbl f |
306 |
of SOME transFn => transFn(y, mvs, xs) |
of SOME transFn => transFn(y, mvs, xs) |
307 |
| NONE => raise Fail("TranslateBasis.translate: unknown function " ^ Var.nameOf 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 |