616 |
for i3 in range(arg0.shape[3]): |
for i3 in range(arg0.shape[3]): |
617 |
out=eval(test_expr.replace("%a1%","arg0[i0,i1,i2,i3]")) |
out=eval(test_expr.replace("%a1%","arg0[i0,i1,i2,i3]")) |
618 |
return eval(post_expr) |
return eval(post_expr) |
619 |
|
|
620 |
|
def clipTEST(arg0,mn,mx): |
621 |
|
if isinstance(arg0,float): |
622 |
|
return max(min(arg0,mx),mn) |
623 |
|
out=numarray.zeros(arg0.shape,numarray.Float64) |
624 |
|
if arg0.rank==1: |
625 |
|
for i0 in range(arg0.shape[0]): |
626 |
|
out[i0]=max(min(arg0[i0],mx),mn) |
627 |
|
elif arg0.rank==2: |
628 |
|
for i0 in range(arg0.shape[0]): |
629 |
|
for i1 in range(arg0.shape[1]): |
630 |
|
out[i0,i1]=max(min(arg0[i0,i1],mx),mn) |
631 |
|
elif arg0.rank==3: |
632 |
|
for i0 in range(arg0.shape[0]): |
633 |
|
for i1 in range(arg0.shape[1]): |
634 |
|
for i2 in range(arg0.shape[2]): |
635 |
|
out[i0,i1,i2]=max(min(arg0[i0,i1,i2],mx),mn) |
636 |
|
elif arg0.rank==4: |
637 |
|
for i0 in range(arg0.shape[0]): |
638 |
|
for i1 in range(arg0.shape[1]): |
639 |
|
for i2 in range(arg0.shape[2]): |
640 |
|
for i3 in range(arg0.shape[3]): |
641 |
|
out[i0,i1,i2,i3]=max(min(arg0[i0,i1,i2,i3],mx),mn) |
642 |
|
return out |
643 |
|
def minimumTEST(arg0,arg1): |
644 |
|
if isinstance(arg0,float): |
645 |
|
if isinstance(arg1,float): |
646 |
|
if arg0>arg1: |
647 |
|
return arg1 |
648 |
|
else: |
649 |
|
return arg0 |
650 |
|
else: |
651 |
|
arg0=numarray.ones(arg1.shape)*arg0 |
652 |
|
else: |
653 |
|
if isinstance(arg1,float): |
654 |
|
arg1=numarray.ones(arg0.shape)*arg1 |
655 |
|
out=numarray.zeros(arg0.shape,numarray.Float64) |
656 |
|
if arg0.rank==0: |
657 |
|
if arg0>arg1: |
658 |
|
out=arg1 |
659 |
|
else: |
660 |
|
out=arg0 |
661 |
|
elif arg0.rank==1: |
662 |
|
for i0 in range(arg0.shape[0]): |
663 |
|
if arg0[i0]>arg1[i0]: |
664 |
|
out[i0]=arg1[i0] |
665 |
|
else: |
666 |
|
out[i0]=arg0[i0] |
667 |
|
elif arg0.rank==2: |
668 |
|
for i0 in range(arg0.shape[0]): |
669 |
|
for i1 in range(arg0.shape[1]): |
670 |
|
if arg0[i0,i1]>arg1[i0,i1]: |
671 |
|
out[i0,i1]=arg1[i0,i1] |
672 |
|
else: |
673 |
|
out[i0,i1]=arg0[i0,i1] |
674 |
|
elif arg0.rank==3: |
675 |
|
for i0 in range(arg0.shape[0]): |
676 |
|
for i1 in range(arg0.shape[1]): |
677 |
|
for i2 in range(arg0.shape[2]): |
678 |
|
if arg0[i0,i1,i2]>arg1[i0,i1,i2]: |
679 |
|
out[i0,i1,i2]=arg1[i0,i1,i2] |
680 |
|
else: |
681 |
|
out[i0,i1,i2]=arg0[i0,i1,i2] |
682 |
|
elif arg0.rank==4: |
683 |
|
for i0 in range(arg0.shape[0]): |
684 |
|
for i1 in range(arg0.shape[1]): |
685 |
|
for i2 in range(arg0.shape[2]): |
686 |
|
for i3 in range(arg0.shape[3]): |
687 |
|
if arg0[i0,i1,i2,i3]>arg1[i0,i1,i2,i3]: |
688 |
|
out[i0,i1,i2,i3]=arg1[i0,i1,i2,i3] |
689 |
|
else: |
690 |
|
out[i0,i1,i2,i3]=arg0[i0,i1,i2,i3] |
691 |
|
return out |
692 |
|
|
693 |
|
|
694 |
|
#======================================================================================================= |
695 |
|
# clip |
696 |
|
#======================================================================================================= |
697 |
|
oper_L=[["clip",clipTEST]] |
698 |
|
for oper in oper_L: |
699 |
|
for case0 in ["float","array","Symbol","constData","taggedData","expandedData"]: |
700 |
|
for sh0 in [ (),(2,), (4,5), (6,2,2),(3,2,3,4)]: |
701 |
|
if len(sh0)==0 or not case0=="float": |
702 |
|
text=" #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n" |
703 |
|
tname="test_%s_%s_rank%s"%(oper[0],case0,len(sh0)) |
704 |
|
text+=" def %s(self):\n"%tname |
705 |
|
a_0=makeArray(sh0,[-1.,1]) |
706 |
|
if case0 in ["taggedData", "expandedData"]: |
707 |
|
a1_0=makeArray(sh0,[-1.,1]) |
708 |
|
else: |
709 |
|
a1_0=a_0 |
710 |
|
|
711 |
|
r=oper[1](a_0,-0.3,0.5) |
712 |
|
r1=oper[1](a1_0,-0.3,0.5) |
713 |
|
text+=mkText(case0,"arg",a_0,a1_0) |
714 |
|
text+=" res=%s(arg,-0.3,0.5)\n"%oper[0] |
715 |
|
if case0=="Symbol": |
716 |
|
text+=mkText("array","s",a_0,a1_0) |
717 |
|
text+=" sub=res.substitute({arg:s})\n" |
718 |
|
res="sub" |
719 |
|
text+=mkText("array","ref",r,r1) |
720 |
|
else: |
721 |
|
res="res" |
722 |
|
text+=mkText(case0,"ref",r,r1) |
723 |
|
text+=mkTypeAndShapeTest(case0,sh0,"res") |
724 |
|
text+=" self.failUnless(Lsup(%s-ref)<=self.RES_TOL*Lsup(ref),\"wrong result\")\n"%res |
725 |
|
|
726 |
|
if case0 == "taggedData" : |
727 |
|
t_prog_with_tags+=text |
728 |
|
else: |
729 |
|
t_prog+=text |
730 |
|
|
731 |
|
print test_header |
732 |
|
# print t_prog |
733 |
|
print t_prog_with_tags |
734 |
|
print test_tail |
735 |
|
1/0 |
736 |
|
#======================================================================================================= |
737 |
|
# maximum, minimum, clipping |
738 |
|
#======================================================================================================= |
739 |
|
oper_L=[ ["maximum",maximumTEST], |
740 |
|
["minimum",minimumTEST]] |
741 |
|
for oper in oper_L: |
742 |
|
for case0 in ["float","array","Symbol","constData","taggedData","expandedData"]: |
743 |
|
for sh1 in [ (),(2,), (4,5), (6,2,2),(3,2,3,4)]: |
744 |
|
for case1 in ["float","array","Symbol","constData","taggedData","expandedData"]: |
745 |
|
for sh0 in [ (),(2,), (4,5), (6,2,2),(3,2,3,4)]: |
746 |
|
if (len(sh0)==0 or not case0=="float") and (len(sh1)==0 or not case1=="float") \ |
747 |
|
and (sh0==sh1 or len(sh0)==0 or len(sh1)==0) : |
748 |
|
use_tagging_for_expanded_data= case0=="taggedData" or case1=="taggedData" |
749 |
|
|
750 |
|
text=" #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n" |
751 |
|
tname="test_%s_%s_rank%s_%s_rank%s"%(oper[0],case0,len(sh0),case1,len(sh1)) |
752 |
|
text+=" def %s(self):\n"%tname |
753 |
|
a_0=makeArray(sh0,[-1.,1]) |
754 |
|
if case0 in ["taggedData", "expandedData"]: |
755 |
|
a1_0=makeArray(sh0,[-1.,1]) |
756 |
|
else: |
757 |
|
a1_0=a_0 |
758 |
|
|
759 |
|
a_1=makeArray(sh1,[-1.,1]) |
760 |
|
if case1 in ["taggedData", "expandedData"]: |
761 |
|
a1_1=makeArray(sh1,[-1.,1]) |
762 |
|
else: |
763 |
|
a1_1=a_1 |
764 |
|
r=oper[1](a_0,a_1) |
765 |
|
r1=oper[1](a1_0,a1_1) |
766 |
|
text+=mkText(case0,"arg0",a_0,a1_0,use_tagging_for_expanded_data) |
767 |
|
text+=mkText(case1,"arg1",a_1,a1_1,use_tagging_for_expanded_data) |
768 |
|
text+=" res=%s(arg0,arg1)\n"%oper[0] |
769 |
|
case=getResultCaseForBin(case0,case1) |
770 |
|
if case=="Symbol": |
771 |
|
c0_res,c1_res=case0,case1 |
772 |
|
subs="{" |
773 |
|
if case0=="Symbol": |
774 |
|
text+=mkText("array","s0",a_0,a1_0) |
775 |
|
subs+="arg0:s0" |
776 |
|
c0_res="array" |
777 |
|
if case1=="Symbol": |
778 |
|
text+=mkText("array","s1",a_1,a1_1) |
779 |
|
if not subs.endswith("{"): subs+="," |
780 |
|
subs+="arg1:s1" |
781 |
|
c1_res="array" |
782 |
|
subs+="}" |
783 |
|
text+=" sub=res.substitute(%s)\n"%subs |
784 |
|
res="sub" |
785 |
|
text+=mkText(getResultCaseForBin(c0_res,c1_res),"ref",r,r1) |
786 |
|
else: |
787 |
|
res="res" |
788 |
|
text+=mkText(case,"ref",r,r1) |
789 |
|
if len(sh0)>len(sh1): |
790 |
|
text+=mkTypeAndShapeTest(case,sh0,"res") |
791 |
|
else: |
792 |
|
text+=mkTypeAndShapeTest(case,sh1,"res") |
793 |
|
text+=" self.failUnless(Lsup(%s-ref)<=self.RES_TOL*Lsup(ref),\"wrong result\")\n"%res |
794 |
|
|
795 |
|
if case0 == "taggedData" or case1 == "taggedData": |
796 |
|
t_prog_with_tags+=text |
797 |
|
else: |
798 |
|
t_prog+=text |
799 |
|
|
800 |
|
print test_header |
801 |
|
# print t_prog |
802 |
|
print t_prog_with_tags |
803 |
|
print test_tail |
804 |
|
1/0 |
805 |
|
|
806 |
|
|
807 |
|
#======================================================================================================= |
808 |
|
# outer inner |
809 |
|
#======================================================================================================= |
810 |
|
oper=["outer",outerTEST] |
811 |
|
# oper=["inner",innerTEST] |
812 |
|
for case0 in ["float","array","Symbol","constData","taggedData","expandedData"]: |
813 |
|
for sh1 in [ (),(2,), (4,5), (6,2,2),(3,2,3,4)]: |
814 |
|
for case1 in ["float","array","Symbol","constData","taggedData","expandedData"]: |
815 |
|
for sh0 in [ (),(2,), (4,5), (6,2,2),(3,2,3,4)]: |
816 |
|
if (len(sh0)==0 or not case0=="float") and (len(sh1)==0 or not case1=="float") \ |
817 |
|
and len(sh0+sh1)<5: |
818 |
|
use_tagging_for_expanded_data= case0=="taggedData" or case1=="taggedData" |
819 |
|
|
820 |
|
text=" #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n" |
821 |
|
tname="test_%s_%s_rank%s_%s_rank%s"%(oper[0],case0,len(sh0),case1,len(sh1)) |
822 |
|
text+=" def %s(self):\n"%tname |
823 |
|
a_0=makeArray(sh0,[-1.,1]) |
824 |
|
if case0 in ["taggedData", "expandedData"]: |
825 |
|
a1_0=makeArray(sh0,[-1.,1]) |
826 |
|
else: |
827 |
|
a1_0=a_0 |
828 |
|
|
829 |
|
a_1=makeArray(sh1,[-1.,1]) |
830 |
|
if case1 in ["taggedData", "expandedData"]: |
831 |
|
a1_1=makeArray(sh1,[-1.,1]) |
832 |
|
else: |
833 |
|
a1_1=a_1 |
834 |
|
r=oper[1](a_0,a_1) |
835 |
|
r1=oper[1](a1_0,a1_1) |
836 |
|
text+=mkText(case0,"arg0",a_0,a1_0,use_tagging_for_expanded_data) |
837 |
|
text+=mkText(case1,"arg1",a_1,a1_1,use_tagging_for_expanded_data) |
838 |
|
text+=" res=%s(arg0,arg1)\n"%oper[0] |
839 |
|
case=getResultCaseForBin(case0,case1) |
840 |
|
if case=="Symbol": |
841 |
|
c0_res,c1_res=case0,case1 |
842 |
|
subs="{" |
843 |
|
if case0=="Symbol": |
844 |
|
text+=mkText("array","s0",a_0,a1_0) |
845 |
|
subs+="arg0:s0" |
846 |
|
c0_res="array" |
847 |
|
if case1=="Symbol": |
848 |
|
text+=mkText("array","s1",a_1,a1_1) |
849 |
|
if not subs.endswith("{"): subs+="," |
850 |
|
subs+="arg1:s1" |
851 |
|
c1_res="array" |
852 |
|
subs+="}" |
853 |
|
text+=" sub=res.substitute(%s)\n"%subs |
854 |
|
res="sub" |
855 |
|
text+=mkText(getResultCaseForBin(c0_res,c1_res),"ref",r,r1) |
856 |
|
else: |
857 |
|
res="res" |
858 |
|
text+=mkText(case,"ref",r,r1) |
859 |
|
text+=mkTypeAndShapeTest(case,sh0+sh1,"res") |
860 |
|
text+=" self.failUnless(Lsup(%s-ref)<=self.RES_TOL*Lsup(ref),\"wrong result\")\n"%res |
861 |
|
|
862 |
|
if case0 == "taggedData" or case1 == "taggedData": |
863 |
|
t_prog_with_tags+=text |
864 |
|
else: |
865 |
|
t_prog+=text |
866 |
|
|
867 |
|
print test_header |
868 |
|
# print t_prog |
869 |
|
print t_prog_with_tags |
870 |
|
print test_tail |
871 |
|
1/0 |
872 |
|
|
873 |
#======================================================================================================= |
#======================================================================================================= |
874 |
# local reduction |
# local reduction |
875 |
#======================================================================================================= |
#======================================================================================================= |
987 |
print test_header |
print test_header |
988 |
# print t_prog |
# print t_prog |
989 |
print t_prog_with_tags |
print t_prog_with_tags |
|
print test_tail |
|
|
1/0 |
|
|
#======================================================================================================= |
|
|
# outer/inner |
|
|
#======================================================================================================= |
|
|
oper=["inner",innerTEST] |
|
|
# oper=["outer",outerTEST] |
|
|
for case0 in ["float","array","Symbol","constData","taggedData","expandedData"]: |
|
|
for sh1 in [ (),(2,), (4,5), (6,2,2),(3,2,3,4)]: |
|
|
for case1 in ["float","array","Symbol","constData","taggedData","expandedData"]: |
|
|
for sh0 in [ (),(2,), (4,5), (6,2,2),(3,2,3,4)]: |
|
|
if (len(sh0)==0 or not case0=="float") and (len(sh1)==0 or not case1=="float") \ |
|
|
and len(sh0+sh1)<5: |
|
|
use_tagging_for_expanded_data= case0=="taggedData" or case1=="taggedData" |
|
|
|
|
|
text=" #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n" |
|
|
tname="test_%s_%s_rank%s_%s_rank%s"%(oper[0],case0,len(sh0),case1,len(sh1)) |
|
|
text+=" def %s(self):\n"%tname |
|
|
a_0=makeArray(sh0,[-1.,1]) |
|
|
if case0 in ["taggedData", "expandedData"]: |
|
|
a1_0=makeArray(sh0,[-1.,1]) |
|
|
else: |
|
|
a1_0=a_0 |
|
|
|
|
|
a_1=makeArray(sh1,[-1.,1]) |
|
|
if case1 in ["taggedData", "expandedData"]: |
|
|
a1_1=makeArray(sh1,[-1.,1]) |
|
|
else: |
|
|
a1_1=a_1 |
|
|
r=oper[1](a_0,a_1) |
|
|
r1=oper[1](a1_0,a1_1) |
|
|
text+=mkText(case0,"arg0",a_0,a1_0,use_tagging_for_expanded_data) |
|
|
text+=mkText(case1,"arg1",a_1,a1_1,use_tagging_for_expanded_data) |
|
|
text+=" res=%s(arg0,arg1)\n"%oper[0] |
|
|
case=getResultCaseForBin(case0,case1) |
|
|
if case=="Symbol": |
|
|
c0_res,c1_res=case0,case1 |
|
|
subs="{" |
|
|
if case0=="Symbol": |
|
|
text+=mkText("array","s0",a_0,a1_0) |
|
|
subs+="arg0:s0" |
|
|
c0_res="array" |
|
|
if case1=="Symbol": |
|
|
text+=mkText("array","s1",a_1,a1_1) |
|
|
if not subs.endswith("{"): subs+="," |
|
|
subs+="arg1:s1" |
|
|
c1_res="array" |
|
|
subs+="}" |
|
|
text+=" sub=res.substitute(%s)\n"%subs |
|
|
res="sub" |
|
|
text+=mkText(getResultCaseForBin(c0_res,c1_res),"ref",r,r1) |
|
|
else: |
|
|
res="res" |
|
|
text+=mkText(case,"ref",r,r1) |
|
|
text+=mkTypeAndShapeTest(case,sh0+sh1,"res") |
|
|
text+=" self.failUnless(Lsup(%s-ref)<=self.RES_TOL*Lsup(ref),\"wrong result\")\n"%res |
|
|
|
|
|
if case0 == "taggedData" or case1 == "taggedData": |
|
|
t_prog_with_tags+=text |
|
|
else: |
|
|
t_prog+=text |
|
|
|
|
|
print test_header |
|
|
# print t_prog |
|
|
print t_prog_with_tags |
|
990 |
print test_tail |
print test_tail |
991 |
1/0 |
1/0 |
992 |
#======================================================================================================= |
#======================================================================================================= |