/[escript]/trunk/escript/py_src/generateutil
ViewVC logotype

Annotation of /trunk/escript/py_src/generateutil

Parent Directory Parent Directory | Revision Log Revision Log


Revision 154 - (hide annotations)
Mon Nov 7 05:51:17 2005 UTC (13 years, 11 months ago) by jgs
Original Path: trunk/esys2/escript/py_src/generateutil
File size: 45421 byte(s)
Merge of development branch dev-02 back to main trunk on 2005-11-07

1 jgs 154 #!/usr/bin/python
2     # $Id$
3    
4     """
5     program generates parts of the util.py and the test_util.py script
6     """
7     u_prog ="import esys.escript\n"
8     u_prog+="import numarray\n"
9     u_prog+="import math\n"
10     t_prog=""
11    
12     func= [ ["atan", [-100.,100.], "math.atan(%a%)"],
13     ["log", [1.e-8,10.], "math.log(%a%)"]
14     ]
15     import random
16     import numarray
17     import math
18     finc=1.e-6
19    
20    
21     def makeArray(shape,rng):
22     l=rng[1]-rng[0]
23     out=numarray.zeros(shape,numarray.Float64)
24     if len(shape)==0:
25     out=random.random()
26     elif len(shape)==1:
27     for i0 in range(shape[0]):
28     out[i0]=l*random.random()+rng[0]
29     elif len(shape)==2:
30     for i0 in range(shape[0]):
31     for i1 in range(shape[1]):
32     out[i0,i1]=l*random.random()+rng[0]
33     elif len(shape)==3:
34     for i0 in range(shape[0]):
35     for i1 in range(shape[1]):
36     for i2 in range(shape[2]):
37     out[i0,i1,i2]=l*random.random()+rng[0]
38     elif len(shape)==4:
39     for i0 in range(shape[0]):
40     for i1 in range(shape[1]):
41     for i2 in range(shape[2]):
42     for i3 in range(shape[3]):
43     out[i0,i1,i2,i3]=l*random.random()+rng[0]
44     else:
45     raise SystemError,"rank is restricted to 4"
46     return out
47    
48     def makeResult2(val,case):
49     if isinstance(val,float):
50     out=val
51     elif len(val.shape)==0:
52     out=val[0]
53     elif len(val.shape)==1:
54     out=val[0]
55     for i0 in range(val.shape[0]):
56     if case == "Lsup":
57     out=max(out,abs(val[i0]))
58     elif case == "sup":
59     out=max(out,val[i0])
60     else:
61     out=min(out,val[i0])
62     elif len(val.shape)==2:
63     out=val[0,0]
64     for i0 in range(val.shape[0]):
65     for i1 in range(val.shape[1]):
66     if case == "Lsup":
67     out=max(out,abs(val[i0,i1]))
68     elif case == "sup":
69     out=max(out,val[i0,i1])
70     else:
71     out=min(out,val[i0,i1])
72     elif len(val.shape)==3:
73     out=val[0,0,0]
74     for i0 in range(val.shape[0]):
75     for i1 in range(val.shape[1]):
76     for i2 in range(val.shape[2]):
77     if case == "Lsup":
78     out=max(out,abs(val[i0,i1,i2]))
79     elif case == "sup":
80     out=max(out,val[i0,i1,i2])
81     else:
82     out=min(out,val[i0,i1,i2])
83     elif len(val.shape)==4:
84     out=val[0,0,0,0]
85     for i0 in range(val.shape[0]):
86     for i1 in range(val.shape[1]):
87     for i2 in range(val.shape[2]):
88     for i3 in range(val.shape[3]):
89     if case == "Lsup":
90     out=max(out,abs(val[i0,i1,i2,i3]))
91     elif case == "sup":
92     out=max(out,val[i0,i1,i2,i3])
93     else:
94     out=min(out,val[i0,i1,i2,i3])
95     else:
96     raise SystemError,"rank is restricted to 4"
97     return out
98    
99     def makeResult(val,f):
100     if isinstance(val,float):
101     out=eval(f[2].replace("%a%","val"))
102     elif len(val.shape)==0:
103     out=eval(f[2].replace("%a%","val"))
104     elif len(val.shape)==1:
105     out=numarray.zeros(val.shape,numarray.Float64)
106     for i0 in range(val.shape[0]):
107     out[i0]=eval(f[2].replace("%a%","val[i0]"))
108     elif len(val.shape)==2:
109     out=numarray.zeros(val.shape,numarray.Float64)
110     for i0 in range(val.shape[0]):
111     for i1 in range(val.shape[1]):
112     out[i0,i1]=eval(f[2].replace("%a%","val[i0,i1]"))
113     elif len(val.shape)==3:
114     out=numarray.zeros(val.shape,numarray.Float64)
115     for i0 in range(val.shape[0]):
116     for i1 in range(val.shape[1]):
117     for i2 in range(val.shape[2]):
118     out[i0,i1,i2]=eval(f[2].replace("%a%","val[i0,i1,i2]"))
119     elif len(val.shape)==4:
120     out=numarray.zeros(val.shape,numarray.Float64)
121     for i0 in range(val.shape[0]):
122     for i1 in range(val.shape[1]):
123     for i2 in range(val.shape[2]):
124     for i3 in range(val.shape[3]):
125     out[i0,i1,i2,i3]=eval(f[2].replace("%a%","val[i0,i1,i2,i3]"))
126     else:
127     raise SystemError,"rank is restricted to 4"
128     return out
129    
130    
131     def mkText(case,name,a,a1=None):
132     t_out=""
133     if case in ["float","array" ]:
134     if isinstance(a,float):
135     t_out+=" %s=%s\n"%(name,a)
136     elif len(a)==1:
137     t_out+=" %s=%s\n"%(name,a)
138     else:
139     t_out+=" %s=numarray.array(%s)\n"%(name,a.tolist())
140     elif case=="constData":
141     if isinstance(a,float):
142     t_out+=" %s=Data(%s,self.functionspace)\n"%(name,a)
143     elif len(a)==1:
144     t_out+=" %s=Data(%s,self.functionspace)\n"%(name,a)
145     else:
146     t_out+=" %s=Data(numarray.array(%s),self.functionspace)\n"%(name,a.tolist())
147     elif case=="taggedData":
148     if isinstance(a,float):
149     t_out+=" %s=Data(%s,self.functionspace)\n"%(name,a)
150     t_out+=" %s.setTaggedValue(1,%s)\n"%(name,a1)
151     elif len(a)==1:
152     t_out+=" %s=Data(%s,self.functionspace)\n"%(name,a)
153     t_out+=" %s.setTaggedValue(1,%s)\n"%(name,a1)
154     else:
155     t_out+=" %s=Data(numarray.array(%s),self.functionspace)\n"%(name,a.tolist())
156     t_out+=" %s.setTaggedValue(1,%s)\n"%(name,a1.tolist())
157     elif case=="expandedData":
158     t_out+=" msk_%s=whereNegative(self.functionspace.getX()[0]-0.5)\n"%name
159     if isinstance(a,float):
160     t_out+=" %s=msk_%s*%s+(1.-msk_%s)*%s\n"%(name,name,a,name,a1)
161     elif len(a)==1:
162     t_out+=" %s=msk_%s*%s+(1.-msk_%s)*%s\n"%(name,name,a,name,a1)
163     else:
164     t_out+=" %s=msk_%s*%s+(1.-msk_%s)*%s\n"%(name,name,a.tolist(),name,a1.tolist())
165     elif case=="Symbol":
166     if isinstance(a,float):
167     t_out+=" %s=Symbol(shape=())\n"%(name)
168     elif len(a)==1:
169     t_out+=" %s=Symbol(shape=())\n"%(name)
170     else:
171     t_out+=" %s=Symbol(shape=%s)\n"%(name,str(a.shape))
172    
173     return t_out
174     #==================
175     case="inner"
176     for arg0 in ["float","array","Symbol","constData","taggedData","expandedData"]:
177     for arg1 in ["float","array","Symbol","constData","taggedData","expandedData"]:
178     for sh0 in [ (),(2,), (4,5), (6,2,2),(3,2,3,4)]:
179     sh1=sh0
180     if (len(sh0)==0 or not arg0=="float") and (len(sh1)==0 or not arg1=="float"):
181     tname="test_%s_%s_rank%s_%s_rank%s"%(case,arg0,len(sh0),arg1,len(sh1))
182     t_prog+=" def %s(self):\n"%tname
183     a0=makeArray(sh0,[-1,1])
184     a0_1=makeArray(sh0,[-1,1])
185     a1=makeArray(sh1,[-1,1])
186     a1_1=makeArray(sh1,[-1,1])
187     t_prog+=mkText(arg0,"arg0",a0,a0_1)
188     t_prog+=mkText(arg1,"arg1",a1,a1_1)
189     t_prog+=" res=%s(arg0,arg1)\n"%case
190    
191     print t_prog
192     1/0
193    
194     #==================
195     cases=["Scalar","Vector","Tensor", "Tensor3","Tensor4"]
196    
197     for case in range(len(cases)):
198     for d in [ None , "d", 1, 2 , 3]:
199     if not d==None or cases[case]=="Scalar":
200     t_prog+=" #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"
201     tname="test_Symbol_%s_d%s"%(cases[case],d)
202     t_prog+=" def %s(self):\n"%tname
203     if d=="d":
204     t_prog+=" s=%sSymbol(dim=self.functionspace)\n"%(cases[case])
205     t_prog+=" d=self.functionspace.getDim()\n"
206     sh="("
207     for i in range(case):
208     if i==0:
209     sh+=d
210     else:
211     sh+=","+d
212     sh+=")"
213     else:
214     t_prog+=" s=%sSymbol(dim=%s)\n"%(cases[case],d)
215     sh=()
216     for i in range(case): sh=sh+(d,)
217     t_prog+=" self.failUnlessEqual(s.getRank(),%s,\"wrong rank.\")\n"%case
218     t_prog+=" self.failUnlessEqual(s.getShape(),%s,\"wrong shape.\")\n"%str(sh)
219     t_prog+=" self.failUnlessEqual(s.getDim(),%s,\"wrong spatial dimension.\")\n"%d
220     t_prog+=" self.failUnlessEqual(s.getArgument(),[],\"wrong arguments.\")\n"
221    
222     print t_prog
223     1/0
224     for sh in [ (),(2,), (4,5), (6,2,2),(3,2,3,4)]:
225     for d in [ None , "domain", 1, 2 , 3]:
226     for args in [ [], ["s2"], [1,-1.] ]:
227     t_prog+=" #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"
228     tname="def test_Symbol_rank%s_d%s_nargs%s"%(len(sh),d,len(args))
229     t_prog+=" %s(self):\n"%tname
230     t_prog+=" s2=ScalarSymbol()\n"
231     if args==["s2"]:
232     a="[s2]"
233     else:
234     a=str(args)
235     if d=="domain":
236     t_prog+=" s=Symbol(shape=%s,dim=self.functionspace.getDim(),args=%s)\n"%(str(sh),a)
237     d2="self.functionspace.getDim()"
238     else:
239     t_prog+=" s=Symbol(shape=%s,dim=%s,args=%s)\n"%(sh,d,a)
240     d2=str(d)
241    
242     t_prog+=" self.failUnlessEqual(s.getRank(),%s,\"wrong rank.\")\n"%len(sh)
243     t_prog+=" self.failUnlessEqual(s.getShape(),%s,\"wrong shape.\")\n"%str(sh)
244     t_prog+=" self.failUnlessEqual(s.getDim(),%s,\"wrong spatial dimension.\")\n"%d2
245     t_prog+=" self.failUnlessEqual(s.getArgument(),%s,\"wrong arguments.\")\n\n"%a
246     t_prog+=" ss=s.substitute({s:numarray.zeros(%s)})\n"%str(sh)
247     t_prog+=" self.failUnless(isinstance(ss,numarray.NumArray),\"value after substitution is not numarray.\")\n"
248     t_prog+=" self.failUnlessEqual(ss.shape,%s,\"value after substitution has not expected shape\")\n"%str(sh)
249    
250     t_prog+=" try:\n s.substitute({s:numarray.zeros((5,))})\n fail(\"illegal substition was successful\")\n"
251     t_prog+=" except TypeError:\n pass\n\n"
252    
253     ###
254     for sh2 in [ (),(2,), (4,5), (6,2,2),(3,2,3,4)]:
255     if len(sh+sh2)<5:
256     t_prog+=" dsdarg=s.diff(Symbol(shape=%s))\n"%str(sh2)
257     if len(sh+sh2)==0:
258     t_prog+=" self.failUnless(isinstance(dsdarg,float),\"ds/ds() has wrong type.\")\n"
259     else:
260     t_prog+=" self.failUnless(isinstance(dsdarg,numarray.NumArray),\"ds/ds%s has wrong type.\")\n"%str(sh2)
261    
262     t_prog+=" self.failUnlessEqual(dsdarg.shape,%s,\"ds/ds%s has wrong shape.\")\n"%(str(sh+sh2),str(sh2))
263     t_prog+=" self.failIf(Lsup(dsdarg)>0.,\"ds/ds%s has wrong value.\")\n"%str(sh2)
264     if len(sh)<3:
265     t_prog+="\n dsds=s.diff(s)\n"
266     if len(sh)==0:
267     t_prog+=" self.failUnless(isinstance(dsds,float),\"ds/ds has wrong type.\")\n"
268     t_prog+=" self.failUnlessEqual(dsds,1.,\"ds/ds has wrong value.\")\n"
269     else:
270     t_prog+=" self.failUnless(isinstance(dsds,numarray.NumArray),\"ds/ds has wrong type.\")\n"
271     t_prog+=" self.failUnlessEqual(dsds.shape,%s,\"ds/ds has wrong shape.\")\n"%str(sh+sh)
272     if len(sh)==1:
273     for i0 in range(sh[0]):
274     for i2 in range(sh[0]):
275     if i0==i2:
276     v=1.
277     else:
278     v=0.
279     t_prog+=" self.failUnlessEqual(dsds[%s,%s],%s,\"ds/ds has wrong value at (%s,%s).\")\n"%(i0,i2,v,i0,i2)
280     else:
281     for i0 in range(sh[0]):
282     for i1 in range(sh[1]):
283     for i2 in range(sh[0]):
284     for i3 in range(sh[1]):
285     if i0==i2 and i1==i3:
286     v=1.
287     else:
288     v=0.
289     t_prog+=" self.failUnlessEqual(dsds[%s,%s,%s,%s],%s,\"ds/ds has wrong value at (%s,%s,%s,%s).\")\n"%(i0,i1,i2,i3,v,i0,i1,i2,i3)
290    
291     ###
292     t_prog+="\n"
293     for i in range(len(args)):
294     t_prog+=" self.failUnlessEqual(s.getArgument(%s),%s,\"wrong argument %s.\")\n"%(i,str(args[i]),i)
295     t_prog+=" sa=s.getSubstitutedArguments({s2:-10})\n"
296     t_prog+=" self.failUnlessEqual(len(sa),%s,\"wrong number of substituted arguments\")\n"%len(args)
297     if args==["s2"]:
298     t_prog+=" self.failUnlessEqual(sa[0],-10,\"wrongly substituted argument 0.\")\n"
299     else:
300     for i in range(len(args)):
301     t_prog+=" self.failUnlessEqual(sa[%s],%s,\"wrongly substituted argument %s.\")\n"%(i,str(args[i]),i)
302    
303     t_prog+="\n"
304     for arg in ["10.", "10", "SymbolMatch", "SymbolMisMatch", \
305     "DataMatch","DataMisMatch", "NumArrayMatch", "NumArrayMisMatch"]:
306     if arg in ["10.", "10"]:
307     a=str(arg)
308     if len(sh)==0:
309     t_prog+=" self.failUnless(s.isAppropriateValue(%s),\"%s is appropriate substitute\")\n"%(a,arg)
310     else:
311     t_prog+=" self.failIf(s.isAppropriateValue(%s),\" %s is not appropriate substitute\")\n"%(a,arg)
312     elif arg in ["SymbolMatch", "SymbolMisMatch"]:
313     if arg=="SymbolMatch":
314     t_prog+=" self.failUnless(s.isAppropriateValue(Symbol(shape=%s,dim=%s)),\"Symbol is appropriate substitute\")\n"%(str(sh),d)
315     else:
316     if isinstance(d,int):
317     t_prog+=" self.failIf(s.isAppropriateValue(Symbol(shape=%s,dim=%s)),\"Symbol is not appropriate substitute (dim)\")\n"%(str(sh),d+1)
318     else:
319     t_prog+=" self.failIf(s.isAppropriateValue(Symbol(shape=%s)),\"Symbol is not appropriate substitute (shape)\")\n"%((5,))
320    
321     elif arg in ["DataMatch","DataMisMatch"]:
322     if arg=="DataMatch" and d=="domain":
323     t_prog+=" self.failUnless(s.isAppropriateValue(escript.Data(0.,%s,self.functionspace)),\"Data is appropriate substitute\")\n"%str(sh)
324     elif arg=="DataMisMatch":
325     t_prog+=" self.failIf(s.isAppropriateValue(escript.Data(0.,%s,self.functionspace)),\"Data is not appropriate substitute (shape)\")\n"%(str((5,)))
326     else:
327     if arg=="NumArrayMatch":
328     t_prog+=" self.failUnless(s.isAppropriateValue(numarray.zeros(%s)),\"NumArray is appropriate substitute\")\n"%str(sh)
329     else:
330     t_prog+=" self.failIf(s.isAppropriateValue(numarray.zeros(%s)),\"NumArray is not appropriate substitute (shape)\")\n"%(str((5,)))
331     print t_prog
332     1/0
333    
334    
335     for case in ["Lsup", "sup", "inf"]:
336     for args in ["float","array","constData","taggedData","expandedData"]:
337     for sh in [ (),(2,), (4,5), (6,2,2),(3,2,3,4)]:
338     if not args=="float" or len(sh)==0:
339     t_prog+=" #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"
340     tname="def test_%s_%s_rank%s"%(case,args,len(sh))
341     t_prog+=" %s(self):\n"%tname
342     if args in ["float","array" ]:
343     a=makeArray(sh,[-1,1])
344     r=makeResult2(a,case)
345     if len(sh)==0:
346     t_prog+=" arg=%s\n"%a
347     else:
348     t_prog+=" arg=numarray.array(%s)\n"%a.tolist()
349     t_prog+=" ref=%s\n"%r
350     t_prog+=" res=%s(arg)\n"%case
351     t_prog+=" self.failUnless(isinstance(res,float),\"wrong type of result.\")\n"
352     t_prog+=" self.failUnless(abs(res-ref)<=self.tol*abs(ref),\"wrong result\")\n"
353     elif args== "constData":
354     a=makeArray(sh,[-1,1])
355     r=makeResult2(a,case)
356     if len(sh)==0:
357     t_prog+=" arg=Data(%s,self.functionspace)\n"%(a)
358     else:
359     t_prog+=" arg=Data(numarray.array(%s),self.functionspace)\n"%(a.tolist())
360     t_prog+=" ref=%s\n"%r
361     t_prog+=" res=%s(arg)\n"%case
362     t_prog+=" self.failUnless(isinstance(res,float),\"wrong type of result.\")\n"
363     t_prog+=" self.failUnless(abs(res-ref)<=self.tol*abs(ref),\"wrong result\")\n"
364     elif args in [ "taggedData","expandedData"]:
365     a=makeArray(sh,[-1,1])
366     r=makeResult2(a,case)
367     a1=makeArray(sh,[-1,1])
368     r1=makeResult2(a1,case)
369     if case in ["Lsup","sup"]:
370     r=max(r,r1)
371     else:
372     r=min(r,r1)
373     if len(sh)==0:
374     if args=="expandedData":
375     t_prog+=" arg=Data(%s,self.functionspace,True)\n"%(a)
376     else:
377     t_prog+=" arg=Data(%s,self.functionspace)\n"%(a)
378     t_prog+=" arg.setTaggedValue(1,%s)\n"%a
379     else:
380     if args=="expandedData":
381     t_prog+=" arg=Data(numarray.array(%s),self.functionspace,True)\n"%(a.tolist())
382     else:
383     t_prog+=" arg=Data(numarray.array(%s),self.functionspace)\n"%(a.tolist())
384     t_prog+=" arg.setTaggedValue(1,%s)\n"%a1.tolist()
385     t_prog+=" res=%s(arg)\n"%case
386     t_prog+=" ref=%s\n"%r
387     t_prog+=" self.failUnless(isinstance(res,float),\"wrong type of result.\")\n"
388     t_prog+=" self.failUnless(abs(res-ref)<=self.tol*abs(ref),\"wrong result\")\n"
389    
390     print t_prog
391    
392     1/0
393    
394    
395     for case in ["Lsup", "sup", "inf"]:
396     for args in ["float","array","constData","taggedData","expandedData"]:
397     for sh in [ (),(2,), (4,5), (6,2,2),(3,2,3,4)]:
398     if not args=="float" or len(sh)==0:
399     t_prog+=" #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"
400     tname="def test_%s_%s_rank%s"%(case,args,len(sh))
401     t_prog+=" %s(self):\n"%tname
402     if args in ["float","array" ]:
403     a=makeArray(sh,[-1,1])
404     r=makeResult2(a,case)
405     if len(sh)==0:
406     t_prog+=" arg=%s\n"%a
407     else:
408     t_prog+=" arg=numarray.array(%s)\n"%a.tolist()
409     t_prog+=" ref=%s\n"%r
410     t_prog+=" res=%s(arg)\n"%case
411     t_prog+=" self.failUnless(isinstance(res,float),\"wrong type of result.\")\n"
412     t_prog+=" self.failUnless(abs(res-ref)<=self.tol*abs(ref),\"wrong result\")\n"
413     elif args== "constData":
414     a=makeArray(sh,[-1,1])
415     r=makeResult2(a,case)
416     if len(sh)==0:
417     t_prog+=" arg=Data(%s,self.functionspace)\n"%(a)
418     else:
419     t_prog+=" arg=Data(numarray.array(%s),self.functionspace)\n"%(a.tolist())
420     t_prog+=" ref=%s\n"%r
421     t_prog+=" res=%s(arg)\n"%case
422     t_prog+=" self.failUnless(isinstance(res,float),\"wrong type of result.\")\n"
423     t_prog+=" self.failUnless(abs(res-ref)<=self.tol*abs(ref),\"wrong result\")\n"
424     elif args in [ "taggedData","expandedData"]:
425     a=makeArray(sh,[-1,1])
426     r=makeResult2(a,case)
427     a1=makeArray(sh,[-1,1])
428     r1=makeResult2(a1,case)
429     if case in ["Lsup","sup"]:
430     r=max(r,r1)
431     else:
432     r=min(r,r1)
433     if len(sh)==0:
434     if args=="expandedData":
435     t_prog+=" arg=Data(%s,self.functionspace,True)\n"%(a)
436     else:
437     t_prog+=" arg=Data(%s,self.functionspace)\n"%(a)
438     t_prog+=" arg.setTaggedValue(1,%s)\n"%a
439     else:
440     if args=="expandedData":
441     t_prog+=" arg=Data(numarray.array(%s),self.functionspace,True)\n"%(a.tolist())
442     else:
443     t_prog+=" arg=Data(numarray.array(%s),self.functionspace)\n"%(a.tolist())
444     t_prog+=" arg.setTaggedValue(1,%s)\n"%a1.tolist()
445     t_prog+=" res=%s(arg)\n"%case
446     t_prog+=" ref=%s\n"%r
447     t_prog+=" self.failUnless(isinstance(res,float),\"wrong type of result.\")\n"
448     t_prog+=" self.failUnless(abs(res-ref)<=self.tol*abs(ref),\"wrong result\")\n"
449    
450     print t_prog
451    
452     1/0
453    
454    
455     for f in func:
456     u_prog+="def %s(arg):\n"%f[0]
457     u_prog+=" \"\"\"\n"
458     u_prog+=" returns %s of argument arg\n\n"%f[0]
459     u_prog+=" @param arg: argument\n"
460     u_prog+=" @type arg: C{float}, L{escript.Data}, L{Symbol}, L{numarray.NumArray}.\n"
461     u_prog+=" @rtype:C{float}, L{escript.Data}, L{Symbol}, L{numarray.NumArray} depending on the type of arg.\n"
462     u_prog+=" @raises TypeError: if the type of the argument is not expected.\n"
463     u_prog+=" \"\"\"\n"
464     u_prog+=" if isinstance(arg,numarray.NumArray):\n"
465     u_prog+=" return numarray.%s(arg)\n"%f[0]
466     u_prog+=" elif isinstance(arg,escript.Data):\n"
467     u_prog+=" return arg._%s(arg)\n"%f[0]
468     u_prog+=" elif isinstance(arg,float):\n"
469     u_prog+=" return math.%s(arg)\n"%f[0]
470     u_prog+=" elif isinstance(arg,int):\n"
471     u_prog+=" return math.%s(float(arg))\n"%f[0]
472     u_prog+=" elif isinstance(arg,Symbol):\n"
473     u_prog+=" return Symbol_%s(arg)\n"%f[0]
474     u_prog+=" else:\n"
475     u_prog+=" raise TypeError,\"%s: Unknown argument type.\"\n"%f[0]
476     u_prog+="class Symbol_%s(DependendSymbol):\n"%f[0]
477     u_prog+=" \"\"\"\n"
478     u_prog+=" Symbol of the result of the %s function\n"%f[0]
479     u_prog+=" \"\"\"\n"
480     u_prog+=" def __init__(self,arg):\n"
481     u_prog+=" \"\"\"\n"
482     u_prog+=" initialization %s function with argument arg\n"%f[0]
483     u_prog+=" @param arg: argument of function\n"
484     u_prog+=" @type arg: L{Symbol}.\n"
485     u_prog+=" \"\"\"\n"
486     u_prog+=" DependendSymbol.__init__(self,args=[arg],shape=arg.getShape(),dim=arg.getDim())\n"
487     u_prog+=" def __str__(self):\n"
488     u_prog+=" \"\"\"\n"
489     u_prog+=" string representation of the object\n"
490     u_prog+=" @rtype: C{str}\n"
491     u_prog+=" \"\"\"\n"
492     u_prog+=" return \"%s(%%s)\"%%str(self.getArgument(0))\n"%f[0]
493     u_prog+=" def substitute(self,argvals):\n"
494     u_prog+=" \"\"\"\n"
495     u_prog+=" assigns new values to symbols in the definition of the symbol\n The method replaces the L{Symbol} u by argvals[u] in the expression defining this object.\n\n"
496     u_prog+=" @param argvals: new values assigned to symbols\n"
497     u_prog+=" @type argvals: C{dict} with keywords of type L{Symbol}.\n"
498     u_prog+=" @return: result of the substitution process. Operations are executed as much as possible.\""
499     u_prog+=" @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, L{numarray.NumArray} depending on the degree of substitution\n"
500     u_prog+=" raise: TypeError: if a value for a L{Symbol} cannot be substituted.\n"
501     u_prog+=" \"\"\"\n"
502     u_prog+=" if argval.has_key(self): \n"
503     u_prog+=" if self.isAppropriateValue(arg):\n"
504     u_prog+=" return argval[self] \n"
505     u_prog+=" else:\n"
506     u_prog+=" raise TypeError,\"%s: new value is not appropriate.\"\n"
507     u_prog+=" else:\n"
508     u_prog+=" arg=self.getSubstitutedArguments(argvals)[0]\n"
509     u_prog+=" return %s(arg)\n"%f[0]
510     u_prog+=" def getMyCode(self,argstrs,format=\"escript\"):\n"
511     u_prog+=" \"\"\"\n"
512     u_prog+=" returns a program code that can be used to evaluate the symbol.\n"
513     u_prog+="\n"
514     u_prog+=" @param argstrs: gives for each argument a string representing of the argument for the evaluation.\n"
515     u_prog+=" @type argstrs: C{list} of C{str}.\n"
516     u_prog+=" @param format: specifies the format to be used. At the moment only \"escript\" is supported.\n"
517     u_prog+=" @type format: C{str}\n"
518     u_prog+=" @return: a piece of program code which can be used to evaluate the expression assuming the values for the arguments are available.\n"
519     u_prog+=" @rtype: C{str}\n"
520     u_prog+=" @raises NotImplementedError: if no implementation for the given format is available\n"
521     u_prog+=" \"\"\"\n"
522     u_prog+=" if format==\"escript\":\n"
523     u_prog+=" return %s(%%s)%argstrs[0]\"\n"%f[0]
524     u_prog+=" else:\n"
525     u_prog+=" raise NotImplementedError,\"%s does not provide program code for format %%s.\"%format\n"%f[0]
526    
527     u_prog+=" def diff(self,arg):\n"
528     u_prog+=" \"\"\"\n"
529     u_prog+=" returns the derivative of the symbol with respect to a symbol\n"
530     u_prog+=" @param arg: argument for derivation\n"
531     u_prog+=" @type arg: L{Symbol}.\n"
532     u_prog+=" @raises NotImplementedError: derivative not available.\n"
533     u_prog+=" \"\"\"\n"
534     u_prog+=" if arg==self: \n"
535     u_prog+=" return identity(self.getShape())\n"
536     u_prog+=" else:\n"
537     u_prog+=" darg=self.getDifferentiatedArguments(arg)[0]\n"
538     u_prog+=" raise NotImplementedError,\"%s: derivative is not available.\"\n"%f[0]
539     u_prog+=" # dself=?\n"
540     u_prog+=" return dself.matchShape(darg)*darg\n"
541    
542    
543     for args in ["float","array","constData","taggedData","expandedData","Symbol"]:
544     for sh in [ (),(2,), (4,5), (6,2,2),(3,2,3,4)]:
545     if not args=="float" or len(sh)==0:
546     t_prog+=" #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"
547     tname="def test_%s_%s_rank%s"%(f[0],args,len(sh))
548     t_prog+=" %s(self):\n"%tname
549     if args in ["float","array" ]:
550     a=makeArray(sh,f[1])
551     r=makeResult(a,f)
552     if len(sh)==0:
553     t_prog+=" arg=%s\n"%a
554     t_prog+=" ref=%s\n"%r
555     else:
556     t_prog+=" arg=numarray.array(%s)\n"%a.tolist()
557     t_prog+=" ref=numarray.array(%s)\n"%r.tolist()
558     t_prog+=" res=%s(arg)\n"%f[0]
559     if args=="float":
560     t_prog+=" self.failUnless(isinstance(res,float),\"wrong type of result.\")\n"
561     else:
562     t_prog+=" self.failUnlessEqual(res.shape,%s,\"wrong shape of result.\")\n"%str(sh)
563     t_prog+=" self.failUnless(Lsup(res-ref)<=self.tol*Lsup(ref),\"wrong result\")\n"
564     elif args== "constData":
565     a=makeArray(sh,f[1])
566     r=makeResult(a,f)
567     if len(sh)==0:
568     t_prog+=" arg=Data(%s,self.functionspace)\n"%(a)
569     t_prog+=" ref=%s\n"%r
570     else:
571     t_prog+=" arg=Data(numarray.array(%s),self.functionspace)\n"%(a.tolist())
572     t_prog+=" ref=numarray.array(%s)\n"%r.tolist()
573     t_prog+=" res=%s(arg)\n"%f[0]
574     t_prog+=" self.failUnlessEqual(res.getShape(),%s,\"wrong shape of result.\")\n"%str(sh)
575     t_prog+=" self.failUnless(Lsup(res-ref)<=self.tol*Lsup(ref),\"wrong result\")\n"
576     elif args in [ "taggedData","expandedData"]:
577     a=makeArray(sh,f[1])
578     r=makeResult(a,f)
579     a1=makeArray(sh,f[1])
580     r1=makeResult(a1,f)
581     if len(sh)==0:
582     if args=="expandedData":
583     t_prog+=" arg=Data(%s,self.functionspace,True)\n"%(a)
584     t_prog+=" ref=Data(%s,self.functionspace,True)\n"%(r)
585     else:
586     t_prog+=" arg=Data(%s,self.functionspace)\n"%(a)
587     t_prog+=" ref=Data(%s,self.functionspace)\n"%(r)
588     t_prog+=" arg.setTaggedValue(1,%s)\n"%a
589     t_prog+=" ref.setTaggedValue(1,%s)\n"%r1
590     else:
591     if args=="expandedData":
592     t_prog+=" arg=Data(numarray.array(%s),self.functionspace,True)\n"%(a.tolist())
593     t_prog+=" ref=Data(numarray.array(%s),self.functionspace,True)\n"%(r.tolist())
594     else:
595     t_prog+=" arg=Data(numarray.array(%s),self.functionspace)\n"%(a.tolist())
596     t_prog+=" ref=Data(numarray.array(%s),self.functionspace)\n"%(r.tolist())
597     t_prog+=" arg.setTaggedValue(1,%s)\n"%a1.tolist()
598     t_prog+=" ref.setTaggedValue(1,%s)\n"%r1.tolist()
599     t_prog+=" res=%s(arg)\n"%f[0]
600     t_prog+=" self.failUnlessEqual(res.getShape(),%s,\"wrong shape of result.\")\n"%str(sh)
601     t_prog+=" self.failUnless(Lsup(res-ref)<=self.tol*Lsup(ref),\"wrong result\")\n"
602     elif args=="Symbol":
603     t_prog+=" arg=Symbol(shape=%s)\n"%str(sh)
604     t_prog+=" v=%s(arg)\n"%f[0]
605     t_prog+=" self.failUnlessRaises(ValueError,v.substitute,Symbol(shape=(1,1)),\"illegal shape of substitute not identified.\")\n"
606     a=makeArray(sh,f[1])
607     r=makeResult(a,f)
608     if len(sh)==0:
609     t_prog+=" res=v.substitute({arg : %s})\n"%a
610     t_prog+=" ref=%s\n"%r
611     t_prog+=" self.failUnless(isinstance(res,float),\"wrong type of result.\")\n"
612     else:
613     t_prog+=" res=v.substitute({arg : numarray.array(%s)})\n"%a.tolist()
614     t_prog+=" ref=numarray.array(%s)\n"%r.tolist()
615     t_prog+=" self.failUnlessEqual(res.getShape(),%s,\"wrong shape of substitution result.\")\n"%str(sh)
616     t_prog+=" self.failUnless(Lsup(res-ref)<=self.tol*Lsup(ref),\"wrong result\")\n"
617    
618     if len(sh)==0:
619     t_prog+=" # test derivative with respect to itself:\n"
620     t_prog+=" dvdv=v.diff(v)\n"
621     t_prog+=" self.failUnlessEqual(dvdv,1.,\"derivative with respect to self is not 1.\")\n"
622     elif len(sh)==1:
623     t_prog+=" # test derivative with respect to itself:\n"
624     t_prog+=" dvdv=v.diff(v)\n"
625     t_prog+=" self.failUnlessEqual(dvdv.shape,%s,\"shape of derivative with respect is wrong\")\n"%str(sh+sh)
626     for i0_l in range(sh[0]):
627     for i0_r in range(sh[0]):
628     if i0_l == i0_r:
629     v=1.
630     else:
631     v=0.
632     t_prog+=" self.failUnlessEqual(dvdv[%s,%s],%s,\"derivative with respect to self: [%s,%s] is not %s\")\n"%(i0_l,i0_r,v,i0_l,i0_r,v)
633     elif len(sh)==2:
634     t_prog+=" # test derivative with respect to itself:\n"
635     t_prog+=" dvdv=v.diff(v)\n"
636     t_prog+=" self.failUnlessEqual(dvdv.shape,%s,\"shape of derivative with respect is wrong\")\n"%str(sh+sh)
637     for i0_l in range(sh[0]):
638     for i0_r in range(sh[0]):
639     for i1_l in range(sh[1]):
640     for i1_r in range(sh[1]):
641     if i0_l == i0_r and i1_l == i1_r:
642     v=1.
643     else:
644     v=0.
645     t_prog+=" self.failUnlessEqual(dvdv[%s,%s,%s,%s],%s,\"derivative with respect to self: [%s,%s,%s,%s] is not %s\")\n"%(i0_l,i1_l,i0_r,i1_r,v,i0_l,i1_l,i0_r,i1_r,v)
646    
647     for sh_in in [ (),(2,), (4,5), (6,2,2),(3,2,3,4)]:
648     if len(sh_in)+len(sh)<=4:
649    
650     t_prog+=" # test derivative with shape %s as argument\n"%str(sh_in)
651     trafo=makeArray(sh+sh_in,[0,1.])
652     a_in=makeArray(sh_in,f[1])
653     t_prog+=" arg_in=Symbol(shape=%s)\n"%str(sh_in)
654     t_prog+=" arg2=Symbol(shape=%s)\n"%str(sh)
655    
656     if len(sh)==0:
657     t_prog+=" arg2="
658     if len(sh_in)==0:
659     t_prog+="%s*arg_in\n"%trafo
660     elif len(sh_in)==1:
661     for i0 in range(sh_in[0]):
662     if i0>0: t_prog+="+"
663     t_prog+="%s*arg_in[%s]"%(trafo[i0],i0)
664     t_prog+="\n"
665     elif len(sh_in)==2:
666     for i0 in range(sh_in[0]):
667     for i1 in range(sh_in[1]):
668     if i0+i1>0: t_prog+="+"
669     t_prog+="%s*arg_in[%s,%s]"%(trafo[i0,i1],i0,i1)
670    
671     elif len(sh_in)==3:
672     for i0 in range(sh_in[0]):
673     for i1 in range(sh_in[1]):
674     for i2 in range(sh_in[2]):
675     if i0+i1+i2>0: t_prog+="+"
676     t_prog+="%s*arg_in[%s,%s,%s]"%(trafo[i0,i1,i2],i0,i1,i2)
677     elif len(sh_in)==4:
678     for i0 in range(sh_in[0]):
679     for i1 in range(sh_in[1]):
680     for i2 in range(sh_in[2]):
681     for i3 in range(sh_in[3]):
682     if i0+i1+i2+i3>0: t_prog+="+"
683     t_prog+="%s*arg_in[%s,%s,%s,%s]"%(trafo[i0,i1,i2,i3],i0,i1,i2,i3)
684     t_prog+="\n"
685     elif len(sh)==1:
686     for j0 in range(sh[0]):
687     t_prog+=" arg2[%s]="%j0
688     if len(sh_in)==0:
689     t_prog+="%s*arg_in"%trafo[j0]
690     elif len(sh_in)==1:
691     for i0 in range(sh_in[0]):
692     if i0>0: t_prog+="+"
693     t_prog+="%s*arg_in[%s]"%(trafo[j0,i0],i0)
694     elif len(sh_in)==2:
695     for i0 in range(sh_in[0]):
696     for i1 in range(sh_in[1]):
697     if i0+i1>0: t_prog+="+"
698     t_prog+="%s*arg_in[%s,%s]"%(trafo[j0,i0,i1],i0,i1)
699     elif len(sh_in)==3:
700     for i0 in range(sh_in[0]):
701     for i1 in range(sh_in[1]):
702     for i2 in range(sh_in[2]):
703     if i0+i1+i2>0: t_prog+="+"
704     t_prog+="%s*arg_in[%s,%s,%s]"%(trafo[j0,i0,i1,i2],i0,i1,i2)
705     t_prog+="\n"
706     elif len(sh)==2:
707     for j0 in range(sh[0]):
708     for j1 in range(sh[1]):
709     t_prog+=" arg2[%s,%s]="%(j0,j1)
710     if len(sh_in)==0:
711     t_prog+="%s*arg_in"%trafo[j0,j1]
712     elif len(sh_in)==1:
713     for i0 in range(sh_in[0]):
714     if i0>0: t_prog+="+"
715     t_prog+="%s*arg_in[%s]"%(trafo[j0,j1,i0],i0)
716     elif len(sh_in)==2:
717     for i0 in range(sh_in[0]):
718     for i1 in range(sh_in[1]):
719     if i0+i1>0: t_prog+="+"
720     t_prog+="%s*arg_in[%s,%s]"%(trafo[j0,j1,i0,i1],i0,i1)
721     t_prog+="\n"
722     elif len(sh)==3:
723     for j0 in range(sh[0]):
724     for j1 in range(sh[1]):
725     for j2 in range(sh[2]):
726     t_prog+=" arg2[%s,%s,%s]="%(j0,j1,j2)
727     if len(sh_in)==0:
728     t_prog+="%s*arg_in"%trafo[j0,j1,j2]
729     elif len(sh_in)==1:
730     for i0 in range(sh_in[0]):
731     if i0>0: t_prog+="+"
732     t_prog+="%s*arg_in[%s]"%(trafo[j0,j1,j2,i0],i0)
733     t_prog+="\n"
734     elif len(sh)==4:
735     for j0 in range(sh[0]):
736     for j1 in range(sh[1]):
737     for j2 in range(sh[2]):
738     for j3 in range(sh[3]):
739     t_prog+=" arg2[%s,%s,%s,%s]="%(j0,j1,j2,j3)
740     if len(sh_in)==0:
741     t_prog+="%s*arg_in"%trafo[j0,j1,j2,j3]
742     t_prog+="\n"
743     t_prog+=" dvdin=v.substitute({arg : arg2}).diff(arg_in)\n"
744     if len(sh_in)==0:
745     t_prog+=" res_in=dvdin.substitute({arg_in : %s})\n"%a_in
746     else:
747     t_prog+=" res_in=dvdin.substitute({arg : numarray.array(%s)})\n"%a_in.tolist()
748    
749     if len(sh)==0:
750     if len(sh_in)==0:
751     ref_diff=(makeResult(trafo*a_in+finc,f)-makeResult(trafo*a_in,f))/finc
752     t_prog+=" self.failUnlessAlmostEqual(dvdin,%s,self.places,\"%s-derivative: wrong derivative\")\n"%(ref_diff,str(sh_in))
753     elif len(sh_in)==1:
754     s=0
755     for k0 in range(sh_in[0]):
756     s+=trafo[k0]*a_in[k0]
757     for i0 in range(sh_in[0]):
758     ref_diff=(makeResult(s+trafo[i0]*finc,f)-makeResult(s,f))/finc
759     t_prog+=" self.failUnlessAlmostEqual(dvdin[%s],%s,self.places,\"%s-derivative: wrong derivative with respect of %s\")\n"%(i0,ref_diff,str(sh_in),str(i0))
760     elif len(sh_in)==2:
761     s=0
762     for k0 in range(sh_in[0]):
763     for k1 in range(sh_in[1]):
764     s+=trafo[k0,k1]*a_in[k0,k1]
765     for i0 in range(sh_in[0]):
766     for i1 in range(sh_in[1]):
767     ref_diff=(makeResult(s+trafo[i0,i1]*finc,f)-makeResult(s,f))/finc
768     t_prog+=" self.failUnlessAlmostEqual(dvdin[%s,%s],%s,self.places,\"%s-derivative: wrong derivative with respect of %s\")\n"%(i0,i1,ref_diff,str(sh_in),str((i0,i1)))
769    
770     elif len(sh_in)==3:
771     s=0
772     for k0 in range(sh_in[0]):
773     for k1 in range(sh_in[1]):
774     for k2 in range(sh_in[2]):
775     s+=trafo[k0,k1,k2]*a_in[k0,k1,k2]
776     for i0 in range(sh_in[0]):
777     for i1 in range(sh_in[1]):
778     for i2 in range(sh_in[2]):
779     ref_diff=(makeResult(s+trafo[i0,i1,i2]*finc,f)-makeResult(s,f))/finc
780     t_prog+=" self.failUnlessAlmostEqual(dvdin[%s,%s,%s],%s,self.places,\"%s-derivative: wrong derivative with respect of %s\")\n"%(i0,i1,i2,ref_diff,str(sh_in),str((i0,i1,i2)))
781     elif len(sh_in)==4:
782     s=0
783     for k0 in range(sh_in[0]):
784     for k1 in range(sh_in[1]):
785     for k2 in range(sh_in[2]):
786     for k3 in range(sh_in[3]):
787     s+=trafo[k0,k1,k2,k3]*a_in[k0,k1,k2,k3]
788     for i0 in range(sh_in[0]):
789     for i1 in range(sh_in[1]):
790     for i2 in range(sh_in[2]):
791     for i3 in range(sh_in[3]):
792     ref_diff=(makeResult(s+trafo[i0,i1,i2,i3]*finc,f)-makeResult(s,f))/finc
793     t_prog+=" self.failUnlessAlmostEqual(dvdin[%s,%s,%s,%s],%s,self.places,\"%s-derivative: wrong derivative with respect of %s\")\n"%(i0,i1,i2,i3,ref_diff,str(sh_in),str((i0,i1,i2,i3)))
794     elif len(sh)==1:
795     for j0 in range(sh[0]):
796     if len(sh_in)==0:
797     ref_diff=(makeResult(trafo[j0]*a_in+finc,f)-makeResult(trafo[j0]*a_in,f))/finc
798     t_prog+=" self.failUnlessAlmostEqual(dvdin[%s],%s,self.places,\"%s-derivative: wrong derivative of %s\")\n"%(j0,ref_diff,str(sh_in),j0)
799     elif len(sh_in)==1:
800     s=0
801     for k0 in range(sh_in[0]):
802     s+=trafo[j0,k0]*a_in[k0]
803     for i0 in range(sh_in[0]):
804     ref_diff=(makeResult(s+trafo[j0,i0]*finc,f)-makeResult(s,f))/finc
805     t_prog+=" self.failUnlessAlmostEqual(dvdin[%s,%s],%s,self.places,\"%s-derivative: wrong derivative of %s with respect of %s\")\n"%(j0,i0,ref_diff,str(sh_in),str(j0),str(i0))
806     elif len(sh_in)==2:
807     s=0
808     for k0 in range(sh_in[0]):
809     for k1 in range(sh_in[1]):
810     s+=trafo[j0,k0,k1]*a_in[k0,k1]
811     for i0 in range(sh_in[0]):
812     for i1 in range(sh_in[1]):
813     ref_diff=(makeResult(s+trafo[j0,i0,i1]*finc,f)-makeResult(s,f))/finc
814     t_prog+=" self.failUnlessAlmostEqual(dvdin[%s,%s,%s],%s,self.places,\"%s-derivative: wrong derivative of %s with respect of %s\")\n"%(j0,i0,i1,ref_diff,str(sh_in),str(j0),str((i0,i1)))
815    
816     elif len(sh_in)==3:
817    
818     s=0
819     for k0 in range(sh_in[0]):
820     for k1 in range(sh_in[1]):
821     for k2 in range(sh_in[2]):
822     s+=trafo[j0,k0,k1,k2]*a_in[k0,k1,k2]
823    
824     for i0 in range(sh_in[0]):
825     for i1 in range(sh_in[1]):
826     for i2 in range(sh_in[2]):
827     ref_diff=(makeResult(s+trafo[j0,i0,i1,i2]*finc,f)-makeResult(s,f))/finc
828     t_prog+=" self.failUnlessAlmostEqual(dvdin[%s,%s,%s,%s],%s,self.places,\"%s-derivative: wrong derivative of %s with respect of %s\")\n"%(j0,i0,i1,i2,ref_diff,str(sh_in),str(j0),str((i0,i1,i2)))
829     elif len(sh)==2:
830     for j0 in range(sh[0]):
831     for j1 in range(sh[1]):
832     if len(sh_in)==0:
833     ref_diff=(makeResult(trafo[j0,j1]*a_in+finc,f)-makeResult(trafo[j0,j1]*a_in,f))/finc
834     t_prog+=" self.failUnlessAlmostEqual(dvdin[%s,%s],%s,self.places,\"%s-derivative: wrong derivative of %s\")\n"%(j0,j1,ref_diff,str(sh_in),str((j0,j1)))
835     elif len(sh_in)==1:
836     s=0
837     for k0 in range(sh_in[0]):
838     s+=trafo[j0,j1,k0]*a_in[k0]
839     for i0 in range(sh_in[0]):
840     ref_diff=(makeResult(s+trafo[j0,j1,i0]*finc,f)-makeResult(s,f))/finc
841     t_prog+=" self.failUnlessAlmostEqual(dvdin[%s,%s,%s],%s,self.places,\"%s-derivative: wrong derivative of %s with respect of %s\")\n"%(j0,j1,i0,ref_diff,str(sh_in),str((j0,j1)),str(i0))
842    
843     elif len(sh_in)==2:
844     s=0
845     for k0 in range(sh_in[0]):
846     for k1 in range(sh_in[1]):
847     s+=trafo[j0,j1,k0,k1]*a_in[k0,k1]
848     for i0 in range(sh_in[0]):
849     for i1 in range(sh_in[1]):
850     ref_diff=(makeResult(s+trafo[j0,j1,i0,i1]*finc,f)-makeResult(s,f))/finc
851     t_prog+=" self.failUnlessAlmostEqual(dvdin[%s,%s,%s,%s],%s,self.places,\"%s-derivative: wrong derivative of %s with respect of %s\")\n"%(j0,j1,i0,i1,ref_diff,str(sh_in),str((j0,j1)),str((i0,i1)))
852     elif len(sh)==3:
853     for j0 in range(sh[0]):
854     for j1 in range(sh[1]):
855     for j2 in range(sh[2]):
856     if len(sh_in)==0:
857     ref_diff=(makeResult(trafo[j0,j1,j2]*a_in+finc,f)-makeResult(trafo[j0,j1,j2]*a_in,f))/finc
858     t_prog+=" self.failUnlessAlmostEqual(dvdin[%s,%s,%s],%s,self.places,\"%s-derivative: wrong derivative of %s\")\n"%(j0,j1,j2,ref_diff,str(sh_in),str((j0,j1,j2)))
859     elif len(sh_in)==1:
860     s=0
861     for k0 in range(sh_in[0]):
862     s+=trafo[j0,j1,j2,k0]*a_in[k0]
863     for i0 in range(sh_in[0]):
864     ref_diff=(makeResult(s+trafo[j0,j1,j2,i0]*finc,f)-makeResult(s,f))/finc
865     t_prog+=" self.failUnlessAlmostEqual(dvdin[%s,%s,%s,%s],%s,self.places,\"%s-derivative: wrong derivative of %s with respect of %s\")\n"%(j0,j1,j2,i0,ref_diff,str(sh_in),str((j0,j1,j2)),i0)
866     elif len(sh)==4:
867     for j0 in range(sh[0]):
868     for j1 in range(sh[1]):
869     for j2 in range(sh[2]):
870     for j3 in range(sh[3]):
871     if len(sh_in)==0:
872     ref_diff=(makeResult(trafo[j0,j1,j2,j3]*a_in+finc,f)-makeResult(trafo[j0,j1,j2,j3]*a_in,f))/finc
873     t_prog+=" self.failUnlessAlmostEqual(dvdin[%s,%s,%s,%s],%s,self.places,\"%s-derivative: wrong derivative of %s\")\n"%(j0,j1,j2,j3,ref_diff,str(sh_in),str((j0,j1,j2,j3)))
874    
875     # print u_prog
876     print t_prog

Properties

Name Value
svn:eol-style native
svn:executable *
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.26