/[escript]/trunk/escript/test/python/BinaryOps.py
ViewVC logotype

Diff of /trunk/escript/test/python/BinaryOps.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 544 by jgs, Wed Nov 9 02:02:19 2005 UTC revision 545 by jgs, Tue Feb 21 01:24:05 2006 UTC
# Line 1  Line 1 
1    """
2    
3    Test binary operations.
4    
5    Version $Id$
6    
7    """
8    
9  import sys  import sys
10  import unittest  import unittest
11  import os  import os
# Line 7  from esys import bruce Line 15  from esys import bruce
15    
16  import numarray  import numarray
17    
 """  
   
 Test binary operations.  
   
 Version $Id$  
   
 """  
   
18  from numarray import array,Float64,ones,greater  from numarray import array,Float64,ones,greater
19    
20  Tag1=10  Tag1=10
21  Tag2=11  Tag2=20
22    
23  tol=1.E-15  tol=1.E-15
24    
# Line 51  arglist = [ \ Line 51  arglist = [ \
51  [ 3.0, 6.0, 3 ] \  [ 3.0, 6.0, 3 ] \
52  ]  ]
53    
 # these are used to test slicing:  
 a_r1=[ [1,2,3], [-1,-2,-3], [100,200,300] ]  
 a_r1_in=[ [1./1,2,3], [-1./1,-1./2,-1./3], [1./100,1./200,1./300] ]  
 a_r4=[ \  
 [ [ [[ 1,2,3],[11,12,13]], [[21,22,23],[31,32,33]], [[41,42,43],[51,52,53]]  ], [ [[101,102,103],[111,112,113]], [[121,122,123],[131,132,133]], [[141,142,143],[151,152,153]]  ], [ [[201,202,203],[211,212,213]], [[221,222,223],[231,232,233]], [[241,242,243],[251,252,253]]  ] ], \  
 [ [ [[ -1,-2,-3],[-11,-12,-13]], [[-21,-22,-23],[-31,-32,-33]], [[-41,-42,-43],[-51,-52,-53]]  ], [ [[-101,-102,-103],[-111,-112,-113]], [[-121,-122,-123],[-131,-132,-133]], [[-141,-142,-143],[-151,-152,-153]]  ], [ [[-201,-202,-203],[-211,-212,-213]], [[-221,-222,-223],[-231,-232,-233]], [[-241,-242,-243],[-251,-252,-253]]  ] ], \  
 [ [[[ 11,12,13],[111,112,113]], [[121,122,123],[131,132,133]], [[141,142,143],[151,152,153]]  ], [ [[1101,1102,1103],[1111,1112,1113]], [[1121,1122,1123],[1131,1132,1133]], [[1141,1142,1143],[1151,1152,1153]]  ], [ [[1201,1202,1203],[1211,1212,1213]], [[1221,1222,1223],[1231,1232,1233]], [[1241,1242,1243],[1251,1252,1253]]  ] ] ]  
 a_r4_in=[ \  
 [ [ [[ 1./1,1./2,1./3],[1./11,1./12,1./13]], [[1./21,1./22,1./23],[1./31,1./32,1./33]], [[1./41,1./42,1./43],[1./51,1./52,1./53]]  ], [ [[1./101,1./102,1./103],[1./111,1./112,1./113]], [[1./121,1./122,1./123],[1./131,1./132,1./133]], [[1./141,1./142,1./143],[1./151,1./152,1./153]]  ], [ [[1./201,1./202,1./203],[1./211,1./212,1./213]], [[1./221,1./222,1./223],[1./231,1./232,1./233]], [[1./241,1./242,1./243],[1./251,1./252,1./253]]  ] ], \  
 [ [ [[ -1./1,-1./2,-1./3],[-1./11,-1./12,-1./13]], [[-1./21,-1./22,-1./23],[-1./31,-1./32,-1./33]], [[-1./41,-1./42,-1./43],[-1./51,-1./52,-1./53]]  ], [ [[-1./101,-1./102,-1./103],[-1./111,-1./112,-1./113]], [[-1./121,-1./122,-1./123],[-1./131,-1./132,-1./133]], [[-1./141,-1./142,-1./143],[1./-151,-1./152,-1./153]]  ], [ [[-1./201,-1./202,-1./203],[-1./211,-1./212,-1./213]], [[-1./221,-1./222,-1./223],[-1./231,-1./232,-1./233]], [[-1./241,-1./242,-1./243],[-1./251,-1./252,-1./253]]  ] ], \  
 [ [[[ 1./11,1./12,1./13],[1./111,1./112,1./113]], [[1./121,1./122,1./123],[1./131,1./132,1./133]], [[1./141,1./142,1./143],[1./151,1./152,1./153]]  ], [ [[1./1101,1./1102,1./1103],[1./1111,1./1112,1./1113]], [[1./1121,1./1122,1./1123],[1./1131,1./1132,1./1133]], [[1./1141,1./1142,1./1143],[1./1151,1./1152,1./1153]]  ], [ [[1./1201,1./1202,1./1203],[1./1211,1./1212,1./1213]], [[1./1221,1./1222,1./1223],[1./1231,1./1232,1./1233]], [[1./1241,1./1242,1./1243],[1./1251,1./1252,1./1253]]  ] ] ]  
   
 def turnToArray(val,tagged):  
      if tagged=="Tagged1":  
          out=[array(val[0],Float64),array(val[1],Float64),array(val[0],Float64)]  
      elif tagged=="Tagged2":  
          out=[array(val[0],Float64),array(val[1],Float64),array(val[2],Float64)]  
      else:  
          out=[array(val[0],Float64),array(val[0],Float64),array(val[0],Float64)]  
      return out  
   
54  def prepareArg(val,ex,wh):  def prepareArg(val,ex,wh):
55       if ex=="Array":      if ex=="Array":
56          out=val[0]          out=val[0]
57       else:      else:
58          if ex=="Expanded":          if ex=="Expanded":
59              exx=True               exx=True
60          else:          else:
61              exx=False               exx=False
62          out=Data(val[0],what=wh,expand=exx)          out=Data(val[0],what=wh,expand=exx)
63          if ex=="Tagged1":          if ex=="Tagged1":
64             out.setTaggedValue(Tag1,val[1])              out.setTaggedValue(Tag1,val[1])
65          elif ex=="Tagged2":          elif ex=="Tagged2":
66             out.setTaggedValue(Tag1,val[1])              out.setTaggedValue(Tag1,val[1])
67             out.setTaggedValue(Tag2,val[2])              out.setTaggedValue(Tag2,val[2])
68       return out      return out
69    
70    def turnToArray(val,tagged):
71        if tagged=="Tagged1":
72            out=[array(val[0],Float64),array(val[1],Float64),array(val[0],Float64)]
73        elif tagged=="Tagged2":
74            out=[array(val[0],Float64),array(val[1],Float64),array(val[2],Float64)]
75        else:
76            out=[array(val[0],Float64),array(val[0],Float64),array(val[0],Float64)]
77        return out
78    
79  def checkResult(text,res,val0,val1,val2,wh):  def checkResult(text,res,val0,val1,val2,wh):
80       ref=Data(val0,what=wh,expand=False)       ref=Data(val0,what=wh,expand=False)
# Line 96  def checkResult(text,res,val0,val1,val2, Line 84  def checkResult(text,res,val0,val1,val2,
84       error=Lsup(ref-res)/norm       error=Lsup(ref-res)/norm
85       print "@@ %s, shape %s: error = %e"%(text,ref.getShape(),error)       print "@@ %s, shape %s: error = %e"%(text,ref.getShape(),error)
86       if error>tol:       if error>tol:
87         print "**** %s : error is too large"%(text)           print "**** %s : error is too large"%(text)
88         raise SystemError,"@@ %s at %s: error is too large"%(text,wh)           raise SystemError,"@@ %s at %s: error is too large"%(text,wh)
89         sys.exit(1)           sys.exit(1)
90    
91  def getRank(arg):  def getRank(arg):
92      if isinstance(arg,Data):      if isinstance(arg,Data):
# Line 138  for wh in [ContinuousFunction(msh),Funct Line 126  for wh in [ContinuousFunction(msh),Funct
126    print wh    print wh
127    
128    #for ex1 in ["Array","Constant","Expanded","Tagged1","Tagged2"]:    #for ex1 in ["Array","Constant","Expanded","Tagged1","Tagged2"]:
129    for ex1 in ["Array","Constant","Expanded"]:    for ex1 in ["Constant","Expanded","Tagged1","Tagged2"]:
130    
131      #for ex2 in ["Array","Constant","Expanded","Tagged1","Tagged2"]:      #for ex2 in ["Array","Constant","Expanded","Tagged1","Tagged2"]:
132      for ex2 in ["Array","Constant","Expanded"]:      for ex2 in ["Constant","Expanded","Tagged1","Tagged2"]:
133    
134        if ex1=="Array" and ex2=="Array":        if ex1=="Array" and ex2=="Array":
135          continue          continue

Legend:
Removed from v.544  
changed lines
  Added in v.545

  ViewVC Help
Powered by ViewVC 1.1.26