1 |
#!/usr/bin/python |
#!/usr/bin/python |
2 |
# $Id:$ |
# $Id$ |
3 |
|
|
4 |
""" |
""" |
5 |
program generates parts of the util.py and the test_util.py script |
program generates parts of the util.py and the test_util.py script |
431 |
if case=="float": |
if case=="float": |
432 |
if isinstance(a,float): |
if isinstance(a,float): |
433 |
t_out+=" %s=%s\n"%(name,a) |
t_out+=" %s=%s\n"%(name,a) |
434 |
elif len(a)==1: |
elif a.rank==0: |
435 |
t_out+=" %s=%s\n"%(name,a) |
t_out+=" %s=%s\n"%(name,a) |
436 |
else: |
else: |
437 |
t_out+=" %s=numarray.array(%s)\n"%(name,a.tolist()) |
t_out+=" %s=numarray.array(%s)\n"%(name,a.tolist()) |
438 |
elif case=="array": |
elif case=="array": |
439 |
if isinstance(a,float): |
if isinstance(a,float): |
440 |
t_out+=" %s=numarray.array(%s)\n"%(name,a) |
t_out+=" %s=numarray.array(%s)\n"%(name,a) |
441 |
elif len(a)==1: |
elif a.rank==0: |
442 |
t_out+=" %s=numarray.array(%s)\n"%(name,a) |
t_out+=" %s=numarray.array(%s)\n"%(name,a) |
443 |
else: |
else: |
444 |
t_out+=" %s=numarray.array(%s)\n"%(name,a.tolist()) |
t_out+=" %s=numarray.array(%s)\n"%(name,a.tolist()) |
445 |
elif case=="constData": |
elif case=="constData": |
446 |
if isinstance(a,float): |
if isinstance(a,float): |
447 |
t_out+=" %s=Data(%s,self.functionspace)\n"%(name,a) |
t_out+=" %s=Data(%s,self.functionspace)\n"%(name,a) |
448 |
elif len(a)==1: |
elif a.rank==0: |
449 |
t_out+=" %s=Data(%s,self.functionspace)\n"%(name,a) |
t_out+=" %s=Data(%s,self.functionspace)\n"%(name,a) |
450 |
else: |
else: |
451 |
t_out+=" %s=Data(numarray.array(%s),self.functionspace)\n"%(name,a.tolist()) |
t_out+=" %s=Data(numarray.array(%s),self.functionspace)\n"%(name,a.tolist()) |
453 |
if isinstance(a,float): |
if isinstance(a,float): |
454 |
t_out+=" %s=Data(%s,self.functionspace)\n"%(name,a) |
t_out+=" %s=Data(%s,self.functionspace)\n"%(name,a) |
455 |
t_out+=" %s.setTaggedValue(1,%s)\n"%(name,a1) |
t_out+=" %s.setTaggedValue(1,%s)\n"%(name,a1) |
456 |
elif len(a)==1: |
elif a.rank==0: |
457 |
t_out+=" %s=Data(%s,self.functionspace)\n"%(name,a) |
t_out+=" %s=Data(%s,self.functionspace)\n"%(name,a) |
458 |
t_out+=" %s.setTaggedValue(1,%s)\n"%(name,a1) |
t_out+=" %s.setTaggedValue(1,%s)\n"%(name,a1) |
459 |
else: |
else: |
464 |
if isinstance(a,float): |
if isinstance(a,float): |
465 |
t_out+=" %s=Data(%s,self.functionspace)\n"%(name,a) |
t_out+=" %s=Data(%s,self.functionspace)\n"%(name,a) |
466 |
t_out+=" %s.setTaggedValue(1,%s)\n"%(name,a1) |
t_out+=" %s.setTaggedValue(1,%s)\n"%(name,a1) |
467 |
elif len(a)==1: |
elif a.rank==0: |
468 |
t_out+=" %s=Data(%s,self.functionspace)\n"%(name,a) |
t_out+=" %s=Data(%s,self.functionspace)\n"%(name,a) |
469 |
t_out+=" %s.setTaggedValue(1,%s)\n"%(name,a1) |
t_out+=" %s.setTaggedValue(1,%s)\n"%(name,a1) |
470 |
else: |
else: |
475 |
t_out+=" msk_%s=whereNegative(self.functionspace.getX()[0]-0.5)\n"%name |
t_out+=" msk_%s=whereNegative(self.functionspace.getX()[0]-0.5)\n"%name |
476 |
if isinstance(a,float): |
if isinstance(a,float): |
477 |
t_out+=" %s=msk_%s*(%s)+(1.-msk_%s)*(%s)\n"%(name,name,a,name,a1) |
t_out+=" %s=msk_%s*(%s)+(1.-msk_%s)*(%s)\n"%(name,name,a,name,a1) |
478 |
elif len(a)==1: |
elif a.rank==0: |
479 |
t_out+=" %s=msk_%s*numarray.array(%s)+(1.-msk_%s)*numarray.array(%s)\n"%(name,name,a,name,a1) |
t_out+=" %s=msk_%s*numarray.array(%s)+(1.-msk_%s)*numarray.array(%s)\n"%(name,name,a,name,a1) |
480 |
else: |
else: |
481 |
t_out+=" %s=msk_%s*numarray.array(%s)+(1.-msk_%s)*numarray.array(%s)\n"%(name,name,a.tolist(),name,a1.tolist()) |
t_out+=" %s=msk_%s*numarray.array(%s)+(1.-msk_%s)*numarray.array(%s)\n"%(name,name,a.tolist(),name,a1.tolist()) |
482 |
elif case=="Symbol": |
elif case=="Symbol": |
483 |
if isinstance(a,float): |
if isinstance(a,float): |
484 |
t_out+=" %s=Symbol(shape=())\n"%(name) |
t_out+=" %s=Symbol(shape=())\n"%(name) |
485 |
elif len(a)==1: |
elif a.rank==0: |
486 |
t_out+=" %s=Symbol(shape=())\n"%(name) |
t_out+=" %s=Symbol(shape=())\n"%(name) |
487 |
else: |
else: |
488 |
t_out+=" %s=Symbol(shape=%s)\n"%(name,str(a.shape)) |
t_out+=" %s=Symbol(shape=%s)\n"%(name,str(a.shape)) |
517 |
out=out.replace("%%a%s%%"%c,r) |
out=out.replace("%%a%s%%"%c,r) |
518 |
return out |
return out |
519 |
|
|
520 |
|
def innerTEST(arg0,arg1): |
521 |
|
if isinstance(arg0,float): |
522 |
|
out=numarray.array(arg0*arg1) |
523 |
|
else: |
524 |
|
out=(arg0*arg1).sum() |
525 |
|
return out |
526 |
|
|
527 |
|
def outerTEST(arg0,arg1): |
528 |
|
if isinstance(arg0,float): |
529 |
|
out=numarray.array(arg0*arg1) |
530 |
|
elif isinstance(arg1,float): |
531 |
|
out=numarray.array(arg0*arg1) |
532 |
|
else: |
533 |
|
out=numarray.outerproduct(arg0,arg1).resize(arg0.shape+arg1.shape) |
534 |
|
return out |
535 |
|
|
536 |
|
def tensorProductTest(arg0,arg1,sh_s): |
537 |
|
if isinstance(arg0,float): |
538 |
|
out=numarray.array(arg0*arg1) |
539 |
|
elif isinstance(arg1,float): |
540 |
|
out=numarray.array(arg0*arg1) |
541 |
|
elif len(sh_s)==0: |
542 |
|
out=numarray.outerproduct(arg0,arg1).resize(arg0.shape+arg1.shape) |
543 |
|
else: |
544 |
|
l=len(sh_s) |
545 |
|
sh0=arg0.shape[:arg0.rank-l] |
546 |
|
sh1=arg1.shape[l:] |
547 |
|
ls,l0,l1=1,1,1 |
548 |
|
for i in sh_s: ls*=i |
549 |
|
for i in sh0: l0*=i |
550 |
|
for i in sh1: l1*=i |
551 |
|
out1=numarray.outerproduct(arg0,arg1).resize((l0,ls,ls,l1)) |
552 |
|
out2=numarray.zeros((l0,l1),numarray.Float) |
553 |
|
for i0 in range(l0): |
554 |
|
for i1 in range(l1): |
555 |
|
for i in range(ls): out2[i0,i1]+=out1[i0,i,i,i1] |
556 |
|
out=out2.resize(sh0+sh1) |
557 |
|
return out |
558 |
|
|
559 |
|
def testMatrixMult(arg0,arg1,sh_s): |
560 |
|
return numarray.matrixmultiply(arg0,arg1) |
561 |
|
|
562 |
|
|
563 |
|
def testTensorMult(arg0,arg1,sh_s): |
564 |
|
if len(arg0)==2: |
565 |
|
return numarray.matrixmultiply(arg0,arg1) |
566 |
|
else: |
567 |
|
if arg1.rank==4: |
568 |
|
out=numarray.zeros((arg0.shape[0],arg0.shape[1],arg1.shape[2],arg1.shape[3]),numarray.Float) |
569 |
|
for i0 in range(arg0.shape[0]): |
570 |
|
for i1 in range(arg0.shape[1]): |
571 |
|
for i2 in range(arg0.shape[2]): |
572 |
|
for i3 in range(arg0.shape[3]): |
573 |
|
for j2 in range(arg1.shape[2]): |
574 |
|
for j3 in range(arg1.shape[3]): |
575 |
|
out[i0,i1,j2,j3]+=arg0[i0,i1,i2,i3]*arg1[i2,i3,j2,j3] |
576 |
|
elif arg1.rank==3: |
577 |
|
out=numarray.zeros((arg0.shape[0],arg0.shape[1],arg1.shape[2]),numarray.Float) |
578 |
|
for i0 in range(arg0.shape[0]): |
579 |
|
for i1 in range(arg0.shape[1]): |
580 |
|
for i2 in range(arg0.shape[2]): |
581 |
|
for i3 in range(arg0.shape[3]): |
582 |
|
for j2 in range(arg1.shape[2]): |
583 |
|
out[i0,i1,j2]+=arg0[i0,i1,i2,i3]*arg1[i2,i3,j2] |
584 |
|
elif arg1.rank==2: |
585 |
|
out=numarray.zeros((arg0.shape[0],arg0.shape[1]),numarray.Float) |
586 |
|
for i0 in range(arg0.shape[0]): |
587 |
|
for i1 in range(arg0.shape[1]): |
588 |
|
for i2 in range(arg0.shape[2]): |
589 |
|
for i3 in range(arg0.shape[3]): |
590 |
|
out[i0,i1]+=arg0[i0,i1,i2,i3]*arg1[i2,i3] |
591 |
|
return out |
592 |
#======================================================================================================= |
#======================================================================================================= |
593 |
# basic binary operations (tests only!) |
# tensor multiply |
594 |
#======================================================================================================= |
#======================================================================================================= |
595 |
oper_range=[-5.,5.] |
# oper=["generalTensorProduct",tensorProductTest] |
596 |
for oper in [["add" ,"+",[-5.,5.]], |
# oper=["matrixmult",testMatrixMult] |
597 |
["mult","*",[-5.,5.]], |
oper=["tensormult",testTensorMult] |
598 |
["quotient" ,"/",[-5.,5.]], |
|
599 |
["power" ,"**",[0.01,5.]]]: |
for case0 in ["float","array","Symbol","constData","taggedData","expandedData"]: |
600 |
for case0 in case_set: |
for sh0 in [ (),(2,), (4,5), (6,2,2),(3,2,3,4)]: |
601 |
for case1 in case_set: |
for case1 in ["float","array","Symbol","constData","taggedData","expandedData"]: |
602 |
for sh in shape_set: |
for sh1 in [ (),(2,), (4,5), (6,2,2),(3,2,3,4)]: |
603 |
for sh_p in shape_set: |
for sh_s in [ (),(3,), (2,3), (2,4,3),(4,2,3,2)]: |
604 |
if len(sh_p)>0: |
if (len(sh0+sh_s)==0 or not case0=="float") and (len(sh1+sh_s)==0 or not case1=="float") \ |
605 |
resource=[-1,1] |
and len(sh0+sh1)<5 and len(sh0+sh_s)<5 and len(sh1+sh_s)<5: |
606 |
else: |
# if len(sh_s)==1 and len(sh0+sh_s)==2 and (len(sh_s+sh1)==1 or len(sh_s+sh1)==2)): # test for matrixmult |
607 |
resource=[1] |
if ( len(sh_s)==1 and len(sh0+sh_s)==2 and ( len(sh1+sh_s)==2 or len(sh1+sh_s)==1 )) or (len(sh_s)==2 and len(sh0+sh_s)==4 and (len(sh1+sh_s)==2 or len(sh1+sh_s)==3 or len(sh1+sh_s)==4)): # test for tensormult |
608 |
for sh_d in resource: |
case=getResultCaseForBin(case0,case1) |
609 |
if sh_d>0: |
use_tagging_for_expanded_data= case0=="taggedData" or case1=="taggedData" |
610 |
sh0=sh |
text=" #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n" |
611 |
sh1=sh+sh_p |
# tname="test_generalTensorProduct_%s_rank%s_%s_rank%s_offset%s"%(case0,len(sh0+sh_s),case1,len(sh_s+sh1),len(sh_s)) |
612 |
else: |
#tname="test_matrixmult_%s_rank%s_%s_rank%s"%(case0,len(sh0+sh_s),case1,len(sh_s+sh1)) |
613 |
sh1=sh |
tname="test_tensormult_%s_rank%s_%s_rank%s"%(case0,len(sh0+sh_s),case1,len(sh_s+sh1)) |
614 |
sh0=sh+sh_p |
# if tname=="test_generalTensorProduct_array_rank1_array_rank2_offset1": |
615 |
|
# print tnametest_generalTensorProduct_Symbol_rank1_Symbol_rank3_offset1 |
616 |
if (not case0=="float" or len(sh0)==0) and (not case1=="float" or len(sh1)==0) and \ |
text+=" def %s(self):\n"%tname |
617 |
len(sh0)<5 and len(sh1)<5: |
a_0=makeArray(sh0+sh_s,[-1.,1]) |
618 |
|
if case0 in ["taggedData", "expandedData"]: |
619 |
|
a1_0=makeArray(sh0+sh_s,[-1.,1]) |
620 |
|
else: |
621 |
|
a1_0=a_0 |
622 |
|
|
623 |
|
a_1=makeArray(sh_s+sh1,[-1.,1]) |
624 |
|
if case1 in ["taggedData", "expandedData"]: |
625 |
|
a1_1=makeArray(sh_s+sh1,[-1.,1]) |
626 |
|
else: |
627 |
|
a1_1=a_1 |
628 |
|
r=oper[1](a_0,a_1,sh_s) |
629 |
|
r1=oper[1](a1_0,a1_1,sh_s) |
630 |
|
text+=mkText(case0,"arg0",a_0,a1_0,use_tagging_for_expanded_data) |
631 |
|
text+=mkText(case1,"arg1",a_1,a1_1,use_tagging_for_expanded_data) |
632 |
|
#text+=" res=matrixmult(arg0,arg1)\n" |
633 |
|
text+=" res=tensormult(arg0,arg1)\n" |
634 |
|
#text+=" res=generalTensorProduct(arg0,arg1,offset=%s)\n"%(len(sh_s)) |
635 |
|
if case=="Symbol": |
636 |
|
c0_res,c1_res=case0,case1 |
637 |
|
subs="{" |
638 |
|
if case0=="Symbol": |
639 |
|
text+=mkText("array","s0",a_0,a1_0) |
640 |
|
subs+="arg0:s0" |
641 |
|
c0_res="array" |
642 |
|
if case1=="Symbol": |
643 |
|
text+=mkText("array","s1",a_1,a1_1) |
644 |
|
if not subs.endswith("{"): subs+="," |
645 |
|
subs+="arg1:s1" |
646 |
|
c1_res="array" |
647 |
|
subs+="}" |
648 |
|
text+=" sub=res.substitute(%s)\n"%subs |
649 |
|
res="sub" |
650 |
|
text+=mkText(getResultCaseForBin(c0_res,c1_res),"ref",r,r1) |
651 |
|
else: |
652 |
|
res="res" |
653 |
|
text+=mkText(case,"ref",r,r1) |
654 |
|
text+=mkTypeAndShapeTest(case,sh0+sh1,"res") |
655 |
|
text+=" self.failUnless(Lsup(%s-ref)<=self.RES_TOL*Lsup(ref),\"wrong result\")\n"%res |
656 |
|
if case0 == "taggedData" or case1 == "taggedData": |
657 |
|
t_prog_with_tags+=text |
658 |
|
else: |
659 |
|
t_prog+=text |
660 |
|
print test_header |
661 |
|
# print t_prog |
662 |
|
print t_prog_with_tags |
663 |
|
print test_tail |
664 |
|
1/0 |
665 |
|
#======================================================================================================= |
666 |
|
# outer/inner |
667 |
|
#======================================================================================================= |
668 |
|
oper=["inner",innerTEST] |
669 |
|
# oper=["outer",outerTEST] |
670 |
|
for case0 in ["float","array","Symbol","constData","taggedData","expandedData"]: |
671 |
|
for sh1 in [ (),(2,), (4,5), (6,2,2),(3,2,3,4)]: |
672 |
|
for case1 in ["float","array","Symbol","constData","taggedData","expandedData"]: |
673 |
|
for sh0 in [ (),(2,), (4,5), (6,2,2),(3,2,3,4)]: |
674 |
|
if (len(sh0)==0 or not case0=="float") and (len(sh1)==0 or not case1=="float") \ |
675 |
|
and len(sh0+sh1)<5: |
676 |
use_tagging_for_expanded_data= case0=="taggedData" or case1=="taggedData" |
use_tagging_for_expanded_data= case0=="taggedData" or case1=="taggedData" |
677 |
|
|
678 |
text=" #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n" |
text=" #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n" |
679 |
tname="test_%s_%s_rank%s_%s_rank%s"%(oper[0],case0,len(sh0),case1,len(sh1)) |
tname="test_%s_%s_rank%s_%s_rank%s"%(oper[0],case0,len(sh0),case1,len(sh1)) |
680 |
text+=" def %s(self):\n"%tname |
text+=" def %s(self):\n"%tname |
681 |
a_0=makeArray(sh0,oper[2]) |
a_0=makeArray(sh0,[-1.,1]) |
682 |
if case0 in ["taggedData", "expandedData"]: |
if case0 in ["taggedData", "expandedData"]: |
683 |
a1_0=makeArray(sh0,oper[2]) |
a1_0=makeArray(sh0,[-1.,1]) |
684 |
else: |
else: |
685 |
a1_0=a_0 |
a1_0=a_0 |
686 |
|
|
687 |
a_1=makeArray(sh1,oper[2]) |
a_1=makeArray(sh1,[-1.,1]) |
688 |
if case1 in ["taggedData", "expandedData"]: |
if case1 in ["taggedData", "expandedData"]: |
689 |
a1_1=makeArray(sh1,oper[2]) |
a1_1=makeArray(sh1,[-1.,1]) |
690 |
else: |
else: |
691 |
a1_1=a_1 |
a1_1=a_1 |
692 |
r1=makeResult2(a1_0,a1_1,"%a1%"+oper[1]+"%a2%") |
r=oper[1](a_0,a_1) |
693 |
r=makeResult2(a_0,a_1,"%a1%"+oper[1]+"%a2%") |
r1=oper[1](a1_0,a1_1) |
694 |
text+=mkText(case0,"arg0",a_0,a1_0,use_tagging_for_expanded_data) |
text+=mkText(case0,"arg0",a_0,a1_0,use_tagging_for_expanded_data) |
695 |
text+=mkText(case1,"arg1",a_1,a1_1,use_tagging_for_expanded_data) |
text+=mkText(case1,"arg1",a_1,a1_1,use_tagging_for_expanded_data) |
696 |
text+=" res=%s(arg0,arg1)\n"%oper[0] |
text+=" res=%s(arg0,arg1)\n"%oper[0] |
|
|
|
697 |
case=getResultCaseForBin(case0,case1) |
case=getResultCaseForBin(case0,case1) |
698 |
if case=="Symbol": |
if case=="Symbol": |
699 |
c0_res,c1_res=case0,case1 |
c0_res,c1_res=case0,case1 |
714 |
else: |
else: |
715 |
res="res" |
res="res" |
716 |
text+=mkText(case,"ref",r,r1) |
text+=mkText(case,"ref",r,r1) |
717 |
if isinstance(r,float): |
text+=mkTypeAndShapeTest(case,sh0+sh1,"res") |
|
text+=mkTypeAndShapeTest(case,(),"res") |
|
|
else: |
|
|
text+=mkTypeAndShapeTest(case,r.shape,"res") |
|
718 |
text+=" self.failUnless(Lsup(%s-ref)<=self.RES_TOL*Lsup(ref),\"wrong result\")\n"%res |
text+=" self.failUnless(Lsup(%s-ref)<=self.RES_TOL*Lsup(ref),\"wrong result\")\n"%res |
719 |
|
|
720 |
if case0 == "taggedData" or case1 == "taggedData": |
if case0 == "taggedData" or case1 == "taggedData": |
721 |
t_prog_with_tags+=text |
t_prog_with_tags+=text |
722 |
else: |
else: |
723 |
t_prog+=text |
t_prog+=text |
724 |
|
|
725 |
print test_header |
print test_header |
726 |
# print t_prog |
# print t_prog |
727 |
print t_prog_with_tags |
print t_prog_with_tags |
728 |
print test_tail |
print test_tail |
729 |
1/0 |
1/0 |
|
|
|
730 |
#======================================================================================================= |
#======================================================================================================= |
731 |
# basic binary operation overloading (tests only!) |
# basic binary operation overloading (tests only!) |
732 |
#======================================================================================================= |
#======================================================================================================= |
740 |
for sh0 in shape_set: |
for sh0 in shape_set: |
741 |
for case1 in case_set: |
for case1 in case_set: |
742 |
for sh1 in shape_set: |
for sh1 in shape_set: |
743 |
if (not case0=="float" or len(sh0)==0) and (not case1=="float" or len(sh1)==0) and \ |
if not case0=="array" and \ |
744 |
|
(not case0=="float" or len(sh0)==0) and (not case1=="float" or len(sh1)==0) and \ |
745 |
(sh0==() or sh1==() or sh1==sh0) and \ |
(sh0==() or sh1==() or sh1==sh0) and \ |
746 |
not (case0 in ["float","array"] and case1 in ["float","array"]): |
not (case0 in ["float","array"] and case1 in ["float","array"]): |
747 |
|
use_tagging_for_expanded_data= case0=="taggedData" or case1=="taggedData" |
748 |
text=" #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n" |
text=" #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n" |
749 |
tname="test_%s_overloaded_%s_rank%s_%s_rank%s"%(oper[0],case0,len(sh0),case1,len(sh1)) |
tname="test_%s_overloaded_%s_rank%s_%s_rank%s"%(oper[0],case0,len(sh0),case1,len(sh1)) |
750 |
text+=" def %s(self):\n"%tname |
text+=" def %s(self):\n"%tname |
800 |
t_prog+=text |
t_prog+=text |
801 |
|
|
802 |
|
|
|
# print u_prog |
|
|
# 1/0 |
|
803 |
print test_header |
print test_header |
804 |
print t_prog |
# print t_prog |
805 |
|
# print t_prog_with_tags |
806 |
|
print t_prog_failing |
807 |
|
print test_tail |
808 |
1/0 |
1/0 |
809 |
|
#======================================================================================================= |
810 |
|
# basic binary operations (tests only!) |
811 |
|
#======================================================================================================= |
812 |
|
oper_range=[-5.,5.] |
813 |
|
for oper in [["add" ,"+",[-5.,5.]], |
814 |
|
["mult","*",[-5.,5.]], |
815 |
|
["quotient" ,"/",[-5.,5.]], |
816 |
|
["power" ,"**",[0.01,5.]]]: |
817 |
|
for case0 in case_set: |
818 |
|
for case1 in case_set: |
819 |
|
for sh in shape_set: |
820 |
|
for sh_p in shape_set: |
821 |
|
if len(sh_p)>0: |
822 |
|
resource=[-1,1] |
823 |
|
else: |
824 |
|
resource=[1] |
825 |
|
for sh_d in resource: |
826 |
|
if sh_d>0: |
827 |
|
sh0=sh |
828 |
|
sh1=sh+sh_p |
829 |
|
else: |
830 |
|
sh1=sh |
831 |
|
sh0=sh+sh_p |
832 |
|
|
833 |
|
if (not case0=="float" or len(sh0)==0) and (not case1=="float" or len(sh1)==0) and \ |
834 |
|
len(sh0)<5 and len(sh1)<5: |
835 |
|
use_tagging_for_expanded_data= case0=="taggedData" or case1=="taggedData" |
836 |
|
text=" #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n" |
837 |
|
tname="test_%s_%s_rank%s_%s_rank%s"%(oper[0],case0,len(sh0),case1,len(sh1)) |
838 |
|
text+=" def %s(self):\n"%tname |
839 |
|
a_0=makeArray(sh0,oper[2]) |
840 |
|
if case0 in ["taggedData", "expandedData"]: |
841 |
|
a1_0=makeArray(sh0,oper[2]) |
842 |
|
else: |
843 |
|
a1_0=a_0 |
844 |
|
|
845 |
|
a_1=makeArray(sh1,oper[2]) |
846 |
|
if case1 in ["taggedData", "expandedData"]: |
847 |
|
a1_1=makeArray(sh1,oper[2]) |
848 |
|
else: |
849 |
|
a1_1=a_1 |
850 |
|
r1=makeResult2(a1_0,a1_1,"%a1%"+oper[1]+"%a2%") |
851 |
|
r=makeResult2(a_0,a_1,"%a1%"+oper[1]+"%a2%") |
852 |
|
text+=mkText(case0,"arg0",a_0,a1_0,use_tagging_for_expanded_data) |
853 |
|
text+=mkText(case1,"arg1",a_1,a1_1,use_tagging_for_expanded_data) |
854 |
|
text+=" res=%s(arg0,arg1)\n"%oper[0] |
855 |
|
|
856 |
|
case=getResultCaseForBin(case0,case1) |
857 |
|
if case=="Symbol": |
858 |
|
c0_res,c1_res=case0,case1 |
859 |
|
subs="{" |
860 |
|
if case0=="Symbol": |
861 |
|
text+=mkText("array","s0",a_0,a1_0) |
862 |
|
subs+="arg0:s0" |
863 |
|
c0_res="array" |
864 |
|
if case1=="Symbol": |
865 |
|
text+=mkText("array","s1",a_1,a1_1) |
866 |
|
if not subs.endswith("{"): subs+="," |
867 |
|
subs+="arg1:s1" |
868 |
|
c1_res="array" |
869 |
|
subs+="}" |
870 |
|
text+=" sub=res.substitute(%s)\n"%subs |
871 |
|
res="sub" |
872 |
|
text+=mkText(getResultCaseForBin(c0_res,c1_res),"ref",r,r1) |
873 |
|
else: |
874 |
|
res="res" |
875 |
|
text+=mkText(case,"ref",r,r1) |
876 |
|
if isinstance(r,float): |
877 |
|
text+=mkTypeAndShapeTest(case,(),"res") |
878 |
|
else: |
879 |
|
text+=mkTypeAndShapeTest(case,r.shape,"res") |
880 |
|
text+=" self.failUnless(Lsup(%s-ref)<=self.RES_TOL*Lsup(ref),\"wrong result\")\n"%res |
881 |
|
|
882 |
|
if case0 == "taggedData" or case1 == "taggedData": |
883 |
|
t_prog_with_tags+=text |
884 |
|
else: |
885 |
|
t_prog+=text |
886 |
|
print test_header |
887 |
|
# print t_prog |
888 |
|
print t_prog_with_tags |
889 |
|
print test_tail |
890 |
|
1/0 |
891 |
|
|
892 |
# print t_prog_with_tagsoper_range=[-5.,5.] |
# print t_prog_with_tagsoper_range=[-5.,5.] |
893 |
for oper in [["add" ,"+",[-5.,5.]], |
for oper in [["add" ,"+",[-5.,5.]], |
894 |
["sub" ,"-",[-5.,5.]], |
["sub" ,"-",[-5.,5.]], |
1588 |
ref_diff=(makeResult(trafo[j0,j1,j2,j3]*a_in+finc,f)-makeResult(trafo[j0,j1,j2,j3]*a_in,f))/finc |
ref_diff=(makeResult(trafo[j0,j1,j2,j3]*a_in+finc,f)-makeResult(trafo[j0,j1,j2,j3]*a_in,f))/finc |
1589 |
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))) |
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))) |
1590 |
|
|
1591 |
#================== |
# |
|
case="inner" |
|
|
for arg0 in ["float","array","Symbol","constData","taggedData","expandedData"]: |
|
|
for arg1 in ["float","array","Symbol","constData","taggedData","expandedData"]: |
|
|
for sh0 in [ (),(2,), (4,5), (6,2,2),(3,2,3,4)]: |
|
|
sh1=sh0 |
|
|
if (len(sh0)==0 or not arg0=="float") and (len(sh1)==0 or not arg1=="float"): |
|
|
tname="test_%s_%s_rank%s_%s_rank%s"%(case,arg0,len(sh0),arg1,len(sh1)) |
|
|
t_prog+=" def %s(self):\n"%tname |
|
|
a0=makeArray(sh0,[-1,1]) |
|
|
a0_1=makeArray(sh0,[-1,1]) |
|
|
a1=makeArray(sh1,[-1,1]) |
|
|
a1_1=makeArray(sh1,[-1,1]) |
|
|
t_prog+=mkText(arg0,"arg0",a0,a0_1) |
|
|
t_prog+=mkText(arg1,"arg1",a1,a1_1) |
|
|
t_prog+=" res=%s(arg0,arg1)\n"%case |
|
|
|
|
|
print t_prog |
|
|
1/0 |
|
1592 |
|
|
1593 |
#================== |
#================== |
1594 |
cases=["Scalar","Vector","Tensor", "Tensor3","Tensor4"] |
cases=["Scalar","Vector","Tensor", "Tensor3","Tensor4"] |