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 |
|
|
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= Operators |
29 |
|
structure S=Specialize |
30 |
|
|
31 |
|
fun pruneTy tv = (case TU.prune(MV.toType tv) |
32 |
|
of (ty as Ty.T_Var _) => raise Fail("unresolved type " ^ TU.toString ty) |
33 |
|
| ty => TranslateTy.tr ty |
34 |
|
(* end case *)) |
35 |
|
|
36 |
fun pruneDim d = (case TU.pruneDim d |
fun pruneDim d = (case TU.pruneDim d |
37 |
of (Ty.DimConst n) => n |
of (Ty.DimConst n) => n |
38 |
| d => raise Fail("unresolved dimension " ^ TU.dimToString d) |
| d => raise Fail("unresolved dimension " ^ TU.dimToString d) |
39 |
(* end case *)) |
(* end case *)) |
40 |
|
|
41 |
|
|
42 |
|
|
43 |
fun pruneShape sv = (case TU.pruneShape(MV.toShape sv) |
fun pruneShape sv = (case TU.pruneShape(MV.toShape sv) |
44 |
of Ty.Shape dd => DstTy.TensorTy(List.map pruneDim dd) |
of Ty.Shape dd => DstTy.tensorTy(List.map pruneDim dd) |
45 |
| shp => raise Fail("unresolved shape " ^ TU.shapeToString shp) |
| shp => raise Fail("unresolved shape " ^ TU.shapeToString shp) |
46 |
(* end case *)) |
(* end case *)) |
47 |
|
|
|
fun dimVarToTensor dv = DstTy.TensorTy[pruneDim(MV.toDim dv)] |
|
|
fun shapeVarToTensor sv = pruneShape sv |
|
48 |
|
|
49 |
fun assign (y, rator, xs) = [(y, IL.OP(rator, xs))] |
fun dimVarToInt dv = pruneDim(MV.toDim dv) |
50 |
|
fun dimVarToTensor dv = DstTy.tensorTy[dimVarToInt dv] |
51 |
|
fun dimVarToMatrix dv = let |
52 |
|
val d = dimVarToInt dv |
53 |
|
in |
54 |
|
DstTy.tensorTy[d, d] (* square matrix type *) |
55 |
|
end |
56 |
|
|
57 |
|
|
58 |
|
fun assign (y, rator, xs) = [IL.ASSGN(y, IL.OP(rator, xs))] |
59 |
|
|
60 |
|
fun basisFn name (y, [], xs) = [IL.ASSGN(y, IL.APPLY(name, xs))] |
61 |
|
|
62 |
fun simpleOp rator (y, [], xs) = assign (y, rator, xs) |
fun simpleOp rator (y, [], xs) = assign (y, rator, xs) |
63 |
|
fun shapeVarToTensor sv = pruneShape sv |
64 |
|
|
65 |
|
|
66 |
fun tensorOp rator (y, [sv], xs) = assign (y, rator(shapeVarToTensor sv), xs) |
fun tensorOp rator (y, [sv], xs) = assign (y, rator(shapeVarToTensor sv), xs) |
67 |
|
|
68 |
fun vectorOp rator (y, [dv], xs) = assign (y, rator(dimVarToTensor dv), xs) |
fun vectorOp rator (y, [dv], xs) = assign (y, rator(dimVarToTensor dv), xs) |
69 |
|
|
70 |
fun kernel h (y, [], []) = assign(y, Op.Kernel h, []) |
fun kernel h (y, [], []) = assign(y, Op.Kernel(h, 0), []) |
71 |
|
|
72 |
|
(* utility functions for synthesizing eigenvector/eigenvalue code *) |
73 |
|
fun eigenVec (rator, dim) = let |
74 |
|
val ty = DstTy.SeqTy(DstTy.realTy, dim) |
75 |
|
in |
76 |
|
fn (y, _, [m]) => let |
77 |
|
val v = IL.Var.new("evals", ty) |
78 |
|
in |
79 |
|
[IL.MASSGN([v, y], rator, [m])] |
80 |
|
end |
81 |
|
end |
82 |
|
fun eigenVal (rator, dim) = let |
83 |
|
val ty = DstTy.SeqTy(DstTy.vecTy dim, dim) |
84 |
|
in |
85 |
|
fn (y, _, [m]) => let |
86 |
|
val v = IL.Var.new("evecs", ty) |
87 |
|
in |
88 |
|
[IL.MASSGN([y, v], rator, [m])] |
89 |
|
end |
90 |
|
end |
91 |
|
|
92 |
|
|
93 |
|
|
94 |
|
|
95 |
|
|
96 |
|
fun assignEin (y, rator, xs) = [IL.ASSGN(y, IL.EINAPP(rator, xs))] |
97 |
|
|
98 |
|
fun assignEin2 (y, rator, xs) = IL.ASSGN(y, IL.EINAPP(rator, xs)) |
99 |
|
|
100 |
|
fun simpleEinOp rator (y, _,xs) = assignEin(y, rator, xs) |
101 |
|
|
102 |
|
fun peelFieldSK SK=[2] (*(case TU.pruneShape(MV.toShape SK) |
103 |
|
of Ty.Shape dd => List.map pruneDim dd |
104 |
|
| shp => raise Fail("unresolved shape " ^ TU.shapeToString shp) |
105 |
|
(* end case *))*) |
106 |
|
|
107 |
|
|
108 |
|
|
109 |
|
fun tensorEinOp einop (y, [SK], xs) = |
110 |
|
let val ty1 as DstTy.TensorTy dd1 = pruneShape SK |
111 |
|
val rator =S.transform(einop,[dd1],[]) |
112 |
|
in |
113 |
|
assignEin(y, rator,xs) |
114 |
|
end |
115 |
|
|
116 |
|
|
117 |
|
|
118 |
|
|
119 |
|
|
120 |
|
fun scalarField(einop,paramarg,y,xs)= |
121 |
|
let val paramarg'=List.map dimVarToInt paramarg(*[2]*) |
122 |
|
val rator=S.transform(einop, [[]],paramarg') |
123 |
|
|
124 |
|
in |
125 |
|
assignEin(y, rator, xs) |
126 |
|
end |
127 |
|
|
128 |
|
fun singleField(SK,einop,paramarg, y, xs)= |
129 |
|
let |
130 |
|
val s=peelFieldSK SK |
131 |
|
val paramarg'= List.map dimVarToInt paramarg (*[2]*) |
132 |
|
val rator= S.transform(einop, [s],paramarg') |
133 |
|
in assignEin(y, rator, xs) |
134 |
|
end |
135 |
|
|
136 |
|
|
137 |
|
|
138 |
|
|
139 |
|
(****MV.toDim returns int, and DstTy.TensorTy returns intlist *) |
140 |
|
|
141 |
|
(*DK- SK-shape,NK-dim *) |
142 |
|
|
143 |
|
(* shape is an int list, DIM is in int|variable, k-level of differntiation *) |
144 |
|
|
145 |
(* build a table that maps Basis variables to their translation functions *) |
(* build a table that maps Basis variables to their translation functions *) |
146 |
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 |
147 |
val tbl = VTbl.mkTable (128, Fail "Translate table") |
val tbl = VTbl.mkTable (128, Fail "Translate table") |
148 |
|
val insert = VTbl.insert tbl |
149 |
in |
in |
150 |
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), |
|
151 |
(BV.lt_ii, simpleOp(Op.LT DstTy.IntTy)), |
(BV.lt_ii, simpleOp(Op.LT DstTy.IntTy)), |
152 |
(BV.lt_rr, simpleOp(Op.LT(DstTy.TensorTy[]))), |
(BV.lt_rr, simpleOp(Op.LT DstTy.realTy)), |
153 |
(BV.lte_ii, simpleOp(Op.LTE DstTy.IntTy)), |
(BV.lte_ii, simpleOp(Op.LTE DstTy.IntTy)), |
154 |
(BV.lte_rr, simpleOp(Op.LTE(DstTy.TensorTy[]))), |
(BV.lte_rr, simpleOp(Op.LTE DstTy.realTy)), |
155 |
(BV.gte_ii, simpleOp(Op.GTE DstTy.IntTy)), |
(BV.gte_ii, simpleOp(Op.GTE DstTy.IntTy)), |
156 |
(BV.gte_rr, simpleOp(Op.GTE(DstTy.TensorTy[]))), |
(BV.gte_rr, simpleOp(Op.GTE(DstTy.realTy))), |
157 |
(BV.gt_ii, simpleOp(Op.GT DstTy.IntTy)), |
(BV.gt_ii, simpleOp(Op.GT DstTy.IntTy)), |
158 |
(BV.gt_rr, simpleOp(Op.GT(DstTy.TensorTy[]))), |
(BV.gt_rr, simpleOp(Op.GT(DstTy.realTy))), |
159 |
(BV.equ_bb, simpleOp(Op.EQ DstTy.BoolTy)), |
(BV.equ_bb, simpleOp(Op.EQ DstTy.BoolTy)), |
160 |
(BV.equ_ii, simpleOp(Op.EQ DstTy.IntTy)), |
(BV.equ_ii, simpleOp(Op.EQ DstTy.IntTy)), |
161 |
(BV.equ_ss, simpleOp(Op.EQ DstTy.StringTy)), |
(BV.equ_ss, simpleOp(Op.EQ DstTy.StringTy)), |
162 |
(BV.equ_rr, simpleOp(Op.EQ(DstTy.TensorTy[]))), |
(BV.equ_rr, simpleOp(Op.EQ(DstTy.realTy))), |
163 |
(BV.neq_bb, simpleOp(Op.NEQ DstTy.BoolTy)), |
(BV.neq_bb, simpleOp(Op.NEQ DstTy.BoolTy)), |
164 |
(BV.neq_ii, simpleOp(Op.NEQ DstTy.IntTy)), |
(BV.neq_ii, simpleOp(Op.NEQ DstTy.IntTy)), |
165 |
(BV.neq_ss, simpleOp(Op.NEQ DstTy.StringTy)), |
(BV.neq_ss, simpleOp(Op.NEQ DstTy.StringTy)), |
166 |
(BV.neq_rr, simpleOp(Op.NEQ(DstTy.TensorTy[]))), |
(BV.neq_rr, simpleOp(Op.NEQ(DstTy.realTy))), |
167 |
(BV.neg_i, simpleOp(Op.Neg DstTy.IntTy)), |
(BV.add_ii, simpleOp Op.IAdd ), |
168 |
(BV.neg_t, tensorOp Op.Neg), |
(BV.add_tt, tensorEinOp EinOp.addTensor), |
169 |
(BV.neg_f, fn (y, _, xs) => assign(y, Op.NegField, xs)), |
(BV.add_ff, fn (y, [_,NK,SK], xs)=> singleField(SK,EinOp.addField, [NK,NK], y, xs)), |
170 |
(BV.op_at, fn (y, [_, dv, sv], xs) => |
(BV.add_fr, fn (y, [_,NK], xs)=> scalarField(EinOp.addTenField,[NK],y, xs)), |
171 |
assign(y, Op.Probe(shapeVarToTensor sv, dimVarToTensor dv), xs)), |
(BV.add_rf, fn (y, [_,NK], [s, f])=>scalarField(EinOp.addTenField,[NK],y,[f,s])), |
172 |
(BV.op_convolve, fn (y, _, xs) => assign(y, Op.Convolve, xs)), |
(BV.sub_ii, simpleOp Op.ISub ), |
173 |
(BV.op_D, fn (y, _, xs) => assign(y, Op.DiffField, xs)), |
(BV.sub_tt, tensorEinOp EinOp.subTensor), |
174 |
(BV.op_norm, tensorOp Op.Norm), |
(BV.sub_ff, fn (y, [_,NK,SK], xs)=>singleField(SK,EinOp.subField, [NK,NK],y,xs)), |
175 |
|
(BV.sub_fr, fn (y, [_,NK], xs) => scalarField(EinOp.subField,[NK], y,xs)), |
176 |
|
(BV.sub_rf, fn (y, [_,NK], [s, f]) => scalarField(EinOp.subField,[NK], y,[f, s])), |
177 |
|
|
178 |
|
(* CHANGE create negative subtraction*) |
179 |
|
(BV.mul_ii, simpleOp Op.IMul), |
180 |
|
(BV.mul_rr, fn (y,_,args)=> |
181 |
|
assignEin(y, EinOp.prodScalar,args)), |
182 |
|
|
183 |
|
(BV.mul_rt, tensorEinOp EinOp.scaleTensor), |
184 |
|
(BV.mul_tr, fn (y, [SK], [t, r])=>let |
185 |
|
val ty1 as DstTy.TensorTy dd1 = pruneShape SK |
186 |
|
val rator =S.transform(EinOp.scaleTensor,[dd1],[]) |
187 |
|
in |
188 |
|
assignEin(y, rator,[r,t]) |
189 |
|
end), |
190 |
|
|
191 |
|
|
192 |
|
|
193 |
|
(BV.mul_rf, fn (y,[_,NK,SK], xs)=> singleField(SK,EinOp.scaleField,[NK],y, xs)), |
194 |
|
|
195 |
|
|
196 |
|
|
197 |
|
(BV.mul_fr, fn (y, [_,NK,SK], [f, s])=> singleField(SK,EinOp.scaleField, [NK],y,[s,f])), |
198 |
|
|
199 |
|
(BV.div_ii, simpleOp Op.IDiv), |
200 |
|
(BV.div_rr, fn (y,_,args)=> |
201 |
|
assignEin(y, EinOp.divScalar,args)), |
202 |
|
|
203 |
|
(BV.div_tr, tensorEinOp EinOp.divideTensor), |
204 |
|
|
205 |
|
(BV.div_fr, fn (y, [_,NK,SK], xs) =>singleField(SK,EinOp.divideField, [NK],y, xs)), |
206 |
|
(BV.exp_ri, simpleOp(Op.Power)), |
207 |
|
(BV.exp_rr, basisFn MathFuns.pow), |
208 |
|
(BV.curl2D, simpleEinOp EinOp.Curl2d), |
209 |
|
(BV.curl3D, simpleEinOp EinOp.Curl3d), |
210 |
|
(BV.convolve_vk, fn (y, [_, NK, SK], xs) => singleField(SK,EinOp.conv, [NK],y,xs)), |
211 |
|
(BV.convolve_kv, fn (y, [_, NK, SK], [k, v]) =>singleField(SK,EinOp.conv, [NK],y,[v,k])), |
212 |
|
(BV.neg_i, simpleOp Op.INeg), |
213 |
|
(BV.neg_t, tensorEinOp EinOp.negTensor), |
214 |
|
|
215 |
|
|
216 |
|
(BV.neg_f, fn (y, [_,NK,SK], xs) => singleField(SK,EinOp.negField, [NK],y,xs)), |
217 |
|
|
218 |
|
(BV.op_probe, fn (y, [_, NK, SK], xs) => |
219 |
|
let |
220 |
|
val dv=dimVarToTensor NK (*Field*) |
221 |
|
val sv=shapeVarToTensor SK (*Position*) |
222 |
|
val dv'=peelFieldSK dv |
223 |
|
val sv'=peelFieldSK sv |
224 |
|
val einop= S.transform(EinOp.probe,[sv',dv'],[2]) |
225 |
|
in assignEin(y, einop,xs) |
226 |
|
end), |
227 |
|
(BV.op_D, fn (y, [_, NK], xs) => scalarField(EinOp.Grad,[NK], y,xs)), |
228 |
|
(BV.op_Dotimes, fn (y, [_, NK, SK, NK2], xs) => singleField(SK,EinOp.Divergence,[NK], y,xs)), |
229 |
|
(BV.op_norm, fn (y, [sv], xs) => (case shapeVarToTensor sv |
230 |
|
of DstTy.TensorTy[] => assign(y, Op.Abs DstTy.realTy, xs) |
231 |
|
| ty => assign(y, Op.Norm ty, xs) |
232 |
|
(* end case *))), |
233 |
|
|
234 |
(BV.op_not, simpleOp Op.Not), |
(BV.op_not, simpleOp Op.Not), |
235 |
(BV.fn_CL, fn (y, _, xs) => assign(y, Op.CL, xs)), |
(BV.op_cross, simpleEinOp EinOp.crossProduct), |
236 |
(BV.fn_convolve, fn (y, _, [h, img]) => assign(y, Op.Convolve, [img, h])), |
(BV.op_outer, fn (y, [dv1, dv2], xs) => let |
237 |
(BV.fn_cos, simpleOp Op.Cos), |
val d1 = [pruneDim(MV.toDim dv1)] |
238 |
(BV.fn_dot, vectorOp Op.Dot), |
val d2 = [pruneDim(MV.toDim dv2)] |
239 |
|
in |
240 |
|
assignEin( y, S.transform(EinOp.outerProduct,[d1,d2],[]),xs) |
241 |
|
end), |
242 |
|
(BV.op_inner, fn (y, [sh1, sh2, _], xs) => |
243 |
|
let |
244 |
|
val ty1 as DstTy.TensorTy dd1 = pruneShape sh1 |
245 |
|
val ty2 as DstTy.TensorTy dd2 = pruneShape sh2 |
246 |
|
val alpha= List.take(dd1, length(dd1)-1) |
247 |
|
val beta= tl(dd2) |
248 |
|
val i =hd(dd2) |
249 |
|
val ilist= [alpha, beta, [i]] |
250 |
|
in |
251 |
|
assignEin(y, S.transform(EinOp.innerProduct, ilist,[]),xs) |
252 |
|
end), |
253 |
|
|
254 |
|
(BV.op_colon, fn (y, [sh1, sh2, _], xs) => |
255 |
|
let |
256 |
|
val ty1 as DstTy.TensorTy dd1 = pruneShape sh1 |
257 |
|
val ty2 as DstTy.TensorTy dd2 = pruneShape sh2 |
258 |
|
val m= List.take(dd2,2) |
259 |
|
val i=hd(m) |
260 |
|
val j=tl(m) |
261 |
|
val alpha= List.take(dd1, length(dd1)-2) |
262 |
|
val beta=tl(tl(dd2)) |
263 |
|
val ilist=[alpha, beta, [i], j] |
264 |
|
in |
265 |
|
assignEin(y, S.transform(EinOp.doubleDot, ilist,[]),xs) |
266 |
|
end), |
267 |
|
|
268 |
(BV.fn_inside, fn (y, [_, dv, _], xs) => |
(BV.fn_inside, fn (y, [_, dv, _], xs) => |
269 |
assign(y, Op.Inside(dimVarToTensor dv), xs)), |
assign(y, Op.Inside(pruneDim(MV.toDim dv)), xs)), |
270 |
|
(BV.clamp_rrr, simpleOp (Op.Clamp DstTy.realTy)), |
271 |
|
(BV.clamp_vvv, vectorOp Op.Clamp), |
272 |
|
(BV.lerp3, tensorOp Op.Lerp), |
273 |
|
(BV.lerp5, fn (y, [sv], [a, b, x0, x, x1]) =>let |
274 |
|
(*assignEin(y, EinOp.subScalar,[x,x0])),*) |
275 |
|
|
276 |
|
val t1 = IL.Var.new("t1", DstTy.realTy) |
277 |
|
val t2 = IL.Var.new("t2", DstTy.realTy) |
278 |
|
val t3 = IL.Var.new("t3", DstTy.realTy) |
279 |
|
in [ |
280 |
|
assignEin2(t1, EinOp.subScalar,[x,x0]), |
281 |
|
assignEin2(t2, EinOp.subScalar,[x1,x0]), |
282 |
|
assignEin2(t3, EinOp.divScalar,[t1,t2]), |
283 |
|
|
284 |
|
IL.ASSGN(y, IL.OP(Op.Lerp(shapeVarToTensor sv), [a, b, t3])) |
285 |
|
] end), |
286 |
|
(BV.evals2x2, eigenVal (Op.Eigen2x2, 2)), |
287 |
|
(BV.evals3x3, eigenVal (Op.Eigen3x3, 3)), |
288 |
|
(BV.evecs2x2, eigenVec (Op.Eigen2x2, 2)), |
289 |
|
(BV.evecs3x3, eigenVec (Op.Eigen3x3, 3)), |
290 |
(BV.fn_max, simpleOp Op.Max), |
(BV.fn_max, simpleOp Op.Max), |
291 |
(BV.fn_min, simpleOp Op.Min), |
(BV.fn_min, simpleOp Op.Min), |
292 |
(BV.fn_modulate, vectorOp Op.Mul), |
(BV.fn_modulate, fn (y, _, xs) => assign (y, Op.IMul, xs)), |
293 |
(BV.fn_pow, simpleOp Op.Pow), |
(BV.fn_normalize, vectorOp Op.Normalize), |
294 |
(BV.fn_principleEvec, vectorOp Op.PrincipleEvec), |
(BV.fn_principleEvec, vectorOp Op.PrincipleEvec), |
295 |
(BV.fn_sin, simpleOp Op.Sin), |
|
296 |
|
(BV.fn_trace, fn (y, [dv], xs) =>let |
297 |
|
val d=dimVarToInt dv |
298 |
|
in |
299 |
|
assignEin(y,S.transform(EinOp.trace, [[d]],[]),xs) |
300 |
|
end), |
301 |
|
|
302 |
|
(BV.fn_transpose, fn (y, [dv1, dv2], xs) => |
303 |
|
let |
304 |
|
val d1=dimVarToInt dv1 |
305 |
|
val d2=dimVarToInt dv2 |
306 |
|
in |
307 |
|
assignEin(y,S.transform(EinOp.transpose, [[d1],[d2]],[]),xs) |
308 |
|
end), |
309 |
|
|
310 |
(BV.kn_bspln3, kernel Kernel.bspln3), |
(BV.kn_bspln3, kernel Kernel.bspln3), |
311 |
(BV.kn_bspln5, kernel Kernel.bspln5), |
(BV.kn_bspln5, kernel Kernel.bspln5), |
312 |
(BV.kn_ctmr, kernel Kernel.ctmr), |
(BV.kn_ctmr, kernel Kernel.ctmr), |
313 |
|
(BV.kn_c2ctmr, kernel Kernel.ctmr), |
314 |
|
(BV.kn_c4hexic, kernel Kernel.c4hexic), |
315 |
(BV.kn_tent, kernel Kernel.tent), |
(BV.kn_tent, kernel Kernel.tent), |
316 |
(BV.i2r, simpleOp Op.IntToReal) |
(BV.kn_c1tent, kernel Kernel.tent), |
317 |
|
(BV.i2r, simpleOp Op.IntToReal), |
318 |
|
|
319 |
|
(BV.identity, fn (y, [dv], xs) =>let |
320 |
|
val d=dimVarToInt dv |
321 |
|
in assignEin(y, S.transform(EinOp.identity,[[d],[d]],[]),xs) |
322 |
|
end), |
323 |
|
|
324 |
|
(* (BV.zero, fn (y, [sv], []) => |
325 |
|
assign(y, Op.Zero(shapeVarToTensor sv), [])),*) |
326 |
|
(BV.subscript, fn (y, [tv, dv], xs) => |
327 |
|
assign(y, |
328 |
|
Op.SeqSub(DstTy.SeqTy(pruneTy tv, pruneDim(MV.toDim dv))), |
329 |
|
xs)) |
330 |
|
|
331 |
|
|
332 |
|
(*, |
333 |
|
|
334 |
|
(BV.dynSubscript, fn (y, [tv], args) => |
335 |
|
assign(y, Op.SeqSub(DstTy.DynSeqTy(pruneTy tv)), args))*) |
336 |
]; |
]; |
337 |
|
|
338 |
|
(* add C math functions *) |
339 |
|
List.app (fn (n, x) => insert(x, basisFn n)) BV.mathFns; |
340 |
tbl |
tbl |
341 |
end |
end |
342 |
|
|
344 |
of SOME transFn => transFn(y, mvs, xs) |
of SOME transFn => transFn(y, mvs, xs) |
345 |
| NONE => raise Fail("TranslateBasis.translate: unknown basis function " ^ Var.uniqueNameOf f) |
| NONE => raise Fail("TranslateBasis.translate: unknown basis function " ^ Var.uniqueNameOf f) |
346 |
(* end case *)) |
(* end case *)) |
347 |
|
handle ex => (print(concat["translate (", IL.Var.toString y, ", ", |
348 |
|
Var.uniqueNameOf f, ", ...)\n"]); raise ex) |
349 |
|
|
350 |
end |
end |