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

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

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

revision 539 by jgs, Wed Nov 9 02:02:19 2005 UTC revision 540 by jgs, Mon Feb 20 06:05:32 2006 UTC
# Line 16  from esys import bruce Line 16  from esys import bruce
16  import numarray  import numarray
17  from numarray import array,Float64,ones,greater  from numarray import array,Float64,ones,greater
18    
19  Tag1=10  Tag1=1
20  Tag2=11  Tag2=2
21    
22  tol=1.E-15  tol=1.E-15
23    
24  #  # a rank 1 test argument
 #  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:  
25  a_r1=[ [1,2,3], [-1,-2,-3], [100,200,300] ]  a_r1=[ [1,2,3], [-1,-2,-3], [100,200,300] ]
26  a_r1_in=[ [1./1,2,3], [-1./1,-1./2,-1./3], [1./100,1./200,1./300] ]  
27    # a rank 4 test argument
28  a_r4=[ \  a_r4=[ \
29  [ [ [[ 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]]  ] ], \
30  [ [ [[ -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]]  ] ], \
31  [ [[[ 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]]  ] ] ]  [ [[[ 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  
32    
33  def prepareArg(val,ex,wh):  def prepareArg(val,ex,wh):
34       if ex=="Array":      if ex=="Expanded":
35          out=val[0]          exx=True
36       else:      else:
37          if ex=="Expanded":          exx=False
38              exx=True      out=Data(val[0],what=wh,expand=exx)
39          else:      if ex=="Tagged1":
40              exx=False          out.setTaggedValue(Tag1,val[1])
41          out=Data(val[0],what=wh,expand=exx)      elif ex=="Tagged2":
42          if ex=="Tagged1":          out.setTaggedValue(Tag1,val[1])
43             out.setTaggedValue(Tag1,val[1])          out.setTaggedValue(Tag2,val[2])
44          elif ex=="Tagged2":      return out
45             out.setTaggedValue(Tag1,val[1])  
46             out.setTaggedValue(Tag2,val[2])  def turnToArray(val,tagged):
47       return out      if tagged=="Tagged1":
48            out=[array(val[0],Float64),array(val[1],Float64),array(val[0],Float64)]
49        elif tagged=="Tagged2":
50            out=[array(val[0],Float64),array(val[1],Float64),array(val[2],Float64)]
51        else:
52            out=[array(val[0],Float64),array(val[0],Float64),array(val[0],Float64)]
53        return out
54    
55  def checkResult(text,res,val0,val1,val2,wh):  def checkResult(text,res,val0,val1,val2,wh):
56       ref=Data(val0,what=wh,expand=False)      ref=Data(val0,what=wh,expand=False)
57       ref.setTaggedValue(Tag1,val1)      ref.setTaggedValue(Tag1,val1)
58       ref.setTaggedValue(Tag2,val2)      ref.setTaggedValue(Tag2,val2)
59       norm=Lsup(ref)+tol      norm=Lsup(ref)+tol
60       error=Lsup(ref-res)/norm      error=Lsup(ref-res)/norm
61       print "@@ %s, shape %s: error = %e"%(text,ref.getShape(),error)      print "@@ %s, shape %s: error = %e"%(text,ref.getShape(),error)
62       if error>tol:      if error>tol:
63         print "**** %s: error is too large"%(text)          print "**** %s: error is too large"%(text)
64         raise SystemError,"@@ %s at %s: error is too large"%(text,wh)          raise SystemError,"@@ %s at %s: error is too large"%(text,wh)
65         sys.exit(1)          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  
   
 def isScalar(arg):  
     if isinstance(arg,Data):  
        if arg.getRank()==1 and arg.getShape()[0]==1:  
          return not None  
        else:  
          return None  
     else:  
         g=array(arg)  
         if g.rank==0:  
            return not None  
         else:  
            if g.rank==1 and g.shape[0]==1:  
               return not None  
            else:  
               return None  
66    
67  #  #
68  # ==============================================================  # ==============================================================
# Line 117  def isScalar(arg): Line 71  def isScalar(arg):
71  #  #
72    
73  msh=bruce.Rectangle(20,6)  msh=bruce.Rectangle(20,6)
74  for wh in [ContinuousFunction(msh),Function(msh)]:  
75    for wh in [ContinuousFunction(msh), Function(msh)]:
76    
77    print wh    print wh
78    
79    for ex1 in ["Constant", "Expanded"]:    for ex1 in ["Constant", "Expanded", "Tagged1", "Tagged2"]:
80    
81      print "Slice getting: ", ex1, ":"      print "Slice getting: ", ex1
82    
83      # rank 1      # rank 1
84    
# Line 157  for wh in [ContinuousFunction(msh),Funct Line 112  for wh in [ContinuousFunction(msh),Funct
112                    arrays[1][2:], \                    arrays[1][2:], \
113                    arrays[2][2:], \                    arrays[2][2:], \
114                    wh)                    wh)
115                                                                                                                            
116      checkResult("slicing: rank=1 [:1] "+ex1, \      checkResult("slicing: rank=1 [:1] "+ex1, \
117                    arg[:1], \                    arg[:1], \
118                    arrays[0][:1], \                    arrays[0][:1], \

Legend:
Removed from v.539  
changed lines
  Added in v.540

  ViewVC Help
Powered by ViewVC 1.1.26