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

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

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

revision 541 by jgs, Wed Nov 9 02:02:19 2005 UTC revision 542 by jgs, Mon Feb 20 06:53:12 2006 UTC
# Line 1  Line 1 
1    """
2    
3    Test slice setting for Data objects.
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 slice setting for Data objects.  
   
 Version $Id$  
   
 """  
   
18  from numarray import array,Float64,ones,greater  from numarray import array,Float64,ones,greater
19    
20  Tag1=10  Tag1=1
21  Tag2=11  Tag2=2
22    
23  tol=1.E-15  tol=1.E-15
24    
25  #  #  rank 1 test arguments
 #  list of arguments: a list item has the form [a0,a1,a2]  
 #  what a0 is the default value and a1 is used for tag Tag1  
 #  and a2 for tag2. a0,a1,a2 are converted into numarrays.  
 #    
   
 arglist = [ \  
 [ [3,4], [-5,6.], [2,3] ], \  
 [ [[1,2],[3,4]], [[5,6],[7,8]], [[-5,-6],[7,8]] ], \  
 [ [[15,8],[12,8]], [[-9,9],[13,8]], [[7,34],[19,7]] ], \  
 [ [[[15,8],[12,8]],[[-9,9],[13,8]]], [[[3,4],[-9,4]],[[1,-9],[7,4]]], [[[5,2],[6,2]],[[-6,4],[7,5]]] ], \  
 [ 3.0, 6.0, 3 ] \  
 ]  
   
 # these are used to test slicing:  
26  a_r1=[ [1,2,3], [-1,-2,-3], [100,200,300] ]  a_r1=[ [1,2,3], [-1,-2,-3], [100,200,300] ]
27  a_r1_in=[ [1./1,2,3], [-1./1,-1./2,-1./3], [1./100,1./200,1./300] ]  a_r1_in=[ [1./1,2,3], [-1./1,-1./2,-1./3], [1./100,1./200,1./300] ]
28    
29    #  rank 4 test arguments
30  a_r4=[ \  a_r4=[ \
31  [ [ [[ 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]]  ] ], \
32  [ [ [[ -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]]  ] ], \
# Line 48  a_r4_in=[ \ Line 36  a_r4_in=[ \
36  [ [ [[ -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]]  ] ], \
37  [ [[[ 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]]  ] ] ]  [ [[[ 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]]  ] ] ]
38    
 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  
   
39  def prepareArg(val,ex,wh):  def prepareArg(val,ex,wh):
40       if ex=="Array":      if ex=="Array":
41          out=val[0]          out=val[0]
42       else:      else:
43          if ex=="Expanded":          if ex=="Expanded":
44              exx=True              exx=True
45          else:          else:
46              exx=False              exx=False
47          out=Data(val[0],what=wh,expand=exx)          out=Data(val[0],what=wh,expand=exx)
48          if ex=="Tagged1":          if ex=="Tagged1":
49             out.setTaggedValue(Tag1,val[1])              out.setTaggedValue(Tag1,val[1])
50          elif ex=="Tagged2":          elif ex=="Tagged2":
51             out.setTaggedValue(Tag1,val[1])              out.setTaggedValue(Tag1,val[1])
52             out.setTaggedValue(Tag2,val[2])              out.setTaggedValue(Tag2,val[2])
53       return out      return out
54    
55  def checkResult(text,res,val0,val1,val2,wh):  def turnToArray(val,tagged):
56       ref=Data(val0,what=wh,expand=False)      if tagged=="Tagged1":
57       ref.setTaggedValue(Tag1,val1)          out=[array(val[0],Float64),array(val[1],Float64),array(val[0],Float64)]
58       ref.setTaggedValue(Tag2,val2)      elif tagged=="Tagged2":
59       norm=Lsup(ref)+tol          out=[array(val[0],Float64),array(val[1],Float64),array(val[2],Float64)]
60       error=Lsup(ref-res)/norm      else:
61       print "@@ %s, shape %s: error = %e"%(text,ref.getShape(),error)          out=[array(val[0],Float64),array(val[0],Float64),array(val[0],Float64)]
62       if error>tol:      return out
        print "**** %s: error is too large"%(text)  
        raise SystemError,"@@ %s: error is too large"%(text)  
        sys.exit(1)  
   
 def getRank(arg):  
     if isinstance(arg,Data):  
        return arg.getRank()  
     else:  
         g=array(arg)  
         if g.rank==0:  
            return 1  
         else:  
            return g.rank  
63    
64  def isScalar(arg):  def checkResult(text,res,val0,val1,val2,wh):
65      if isinstance(arg,Data):      ref=Data(val0,what=wh,expand=False)
66         if arg.getRank()==1 and arg.getShape()[0]==1:      ref.setTaggedValue(Tag1,val1)
67           return not None      ref.setTaggedValue(Tag2,val2)
68         else:      norm=Lsup(ref)+tol
69           return None      error=Lsup(ref-res)/norm
70      else:      print "@@ %s, shape %s: error = %e"%(text,ref.getShape(),error)
71          g=array(arg)      if error>tol:
72          if g.rank==0:          print "**** %s: error is too large"%(text)
73             return not None          raise SystemError,"@@ %s: error is too large"%(text)
74          else:          sys.exit(1)
            if g.rank==1 and g.shape[0]==1:  
               return not None  
            else:  
               return None  
75    
76  #  #
 # ==============================================================  
 #  
77  # test slice setting:  # test slice setting:
78  #  #
79    
# Line 122  for wh in [ContinuousFunction(msh),Funct Line 82  for wh in [ContinuousFunction(msh),Funct
82    
83    print wh    print wh
84    
85    for ex1 in ["Constant","Expanded"]:    for ex1 in ["Constant","Expanded","Tagged1","Tagged2"]:
86    
87      for ex2 in ["Array","Constant","Expanded"]:      for ex2 in ["Array","Constant","Expanded","Tagged1","Tagged2"]:
88    
89            print "Slice setting: ", ex1, ",", ex2, ":"            print "Slice setting: ", ex1, ",", ex2, ":"
90    

Legend:
Removed from v.541  
changed lines
  Added in v.542

  ViewVC Help
Powered by ViewVC 1.1.26