580 |
for r in args: |
for r in args: |
581 |
out=out.replace("%%a%s%%"%c,r) |
out=out.replace("%%a%s%%"%c,r) |
582 |
return out |
return out |
583 |
|
|
584 |
|
|
585 |
|
#======================================================================================================= |
586 |
|
# swap axes |
587 |
|
#======================================================================================================= |
588 |
|
for case0 in ["array","Symbol","constData","taggedData","expandedData"]: |
589 |
|
for sh0 in [ (4,5), (6,2,2),(3,2,3,4)]: |
590 |
|
for axis0 in range(len(sh0)): |
591 |
|
for axis1 in range(axis0+1,len(sh0)): |
592 |
|
tname="test_%s_%s_rank%s_axes_%s%s"%("swapaxes",case0,len(sh0),axis0,axis1) |
593 |
|
text=" #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n" |
594 |
|
text+=" def %s(self):\n"%tname |
595 |
|
a_0=makeArray(sh0,[-8,8]) |
596 |
|
if case0 in ["taggedData", "expandedData"]: |
597 |
|
a1_0=makeArray(sh0,[-8,8]) |
598 |
|
else: |
599 |
|
a1_0=a_0 |
600 |
|
r=numarray.swapaxes(a_0,axis0,axis1) |
601 |
|
r1=numarray.swapaxes(a1_0,axis0,axis1) |
602 |
|
text+=mkText(case0,"arg",a_0,a1_0) |
603 |
|
text+=" res=swap_axes(arg,axis0=%s,axis1=%s)\n"%(axis0,axis1) |
604 |
|
if case0=="Symbol": |
605 |
|
text+=mkText("array","s",a_0,a1_0) |
606 |
|
text+=" sub=res.substitute({arg:s})\n" |
607 |
|
res="sub" |
608 |
|
text+=mkText("array","ref",r,r1) |
609 |
|
else: |
610 |
|
res="res" |
611 |
|
text+=mkText(case0,"ref",r,r1) |
612 |
|
text+=mkTypeAndShapeTest(case0,r.shape,"res") |
613 |
|
text+=" self.failUnless(Lsup(%s-ref)<=self.RES_TOL*Lsup(ref),\"wrong result\")\n"%res |
614 |
|
|
615 |
|
if case0 == "taggedData": |
616 |
|
t_prog_with_tags+=text |
617 |
|
else: |
618 |
|
t_prog+=text |
619 |
|
print test_header |
620 |
|
# print t_prog |
621 |
|
print t_prog_with_tags |
622 |
|
print test_tail |
623 |
|
1/0 |
624 |
|
while True: |
625 |
|
for sh_s in [ (),(3,), (2,3), (2,4,3),(4,2,3,2)]: |
626 |
|
if (len(sh0+sh_s)==0 or not case0=="float") and (len(sh1+sh_s)==0 or not case1=="float") \ |
627 |
|
and len(sh0+sh1)<5 and len(sh0+sh_s)<5 and len(sh1+sh_s)<5: |
628 |
|
arg_shape=oper[2](sh0,sh1,sh_s) |
629 |
|
if not arg_shape==None: |
630 |
|
case=getResultCaseForBin(case0,case1) |
631 |
|
use_tagging_for_expanded_data= case0=="taggedData" or case1=="taggedData" |
632 |
|
if oper[0] in [ "generalTensorProduct", "generalTransposedTensorProduct", "generalTensorTransposedProduct"]: |
633 |
|
tname="test_%s_%s_rank%s_%s_rank%s_offset%s"%(oper[0],case0,len(sh0+sh_s),case1,len(sh_s+sh1),len(sh_s)) |
634 |
|
|
635 |
|
res_text=" res=%s(arg0,arg1,axis_offset=%s)\n"%(oper[0],len(sh_s)) |
636 |
|
else: |
637 |
|
tname="test_%s_%s_rank%s_%s_rank%s"%(oper[0],case0,len(sh0+sh_s),case1,len(sh_s+sh1)) |
638 |
|
|
639 |
|
res_text=" res=%s(arg0,arg1)\n"%oper[0] |
640 |
|
|
641 |
|
a_0=makeArray(arg_shape[0],[-8,8]) |
642 |
|
if case0 in ["taggedData", "expandedData"]: |
643 |
|
a1_0=makeArray(arg_shape[0],[-8,8]) |
644 |
|
else: |
645 |
|
a1_0=a_0 |
646 |
|
|
647 |
|
a_1=makeArray(arg_shape[1],[-8,8]) |
648 |
|
if case1 in ["taggedData", "expandedData"]: |
649 |
|
a1_1=makeArray(arg_shape[1],[-8,8]) |
650 |
|
else: |
651 |
|
a1_1=a_1 |
652 |
|
r=oper[1](a_0,a_1,sh_s) |
653 |
|
r1=oper[1](a1_0,a1_1,sh_s) |
654 |
|
text+=mkText(case0,"arg0",a_0,a1_0,use_tagging_for_expanded_data) |
655 |
|
text+=mkText(case1,"arg1",a_1,a1_1,use_tagging_for_expanded_data) |
656 |
|
text+=res_text |
657 |
|
if case=="Symbol": |
658 |
|
c0_res,c1_res=case0,case1 |
659 |
|
subs="{" |
660 |
|
if case0=="Symbol": |
661 |
|
text+=mkText("array","s0",a_0,a1_0) |
662 |
|
subs+="arg0:s0" |
663 |
|
c0_res="array" |
664 |
|
if case1=="Symbol": |
665 |
|
text+=mkText("array","s1",a_1,a1_1) |
666 |
|
if not subs.endswith("{"): subs+="," |
667 |
|
subs+="arg1:s1" |
668 |
|
c1_res="array" |
669 |
|
subs+="}" |
670 |
|
text+=" sub=res.substitute(%s)\n"%subs |
671 |
|
res="sub" |
672 |
|
text+=mkText(getResultCaseForBin(c0_res,c1_res),"ref",r,r1) |
673 |
|
else: |
674 |
|
res="res" |
675 |
|
text+=mkText(case,"ref",r,r1) |
676 |
|
text+=mkTypeAndShapeTest(case,sh0+sh1,"res") |
677 |
|
text+=" self.failUnless(Lsup(%s-ref)<=self.RES_TOL*Lsup(ref),\"wrong result\")\n"%res |
678 |
|
1/0 |
679 |
|
|
680 |
#================================================= |
#================================================= |
681 |
def testMatrixMult(arg0,arg1,sh_s): |
def testMatrixMult(arg0,arg1,sh_s): |
682 |
return numarray.matrixmultiply(arg0,arg1) |
return numarray.matrixmultiply(arg0,arg1) |