/[escript]/trunk/escript/py_src/util.py
ViewVC logotype

Diff of /trunk/escript/py_src/util.py

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

revision 378 by gross, Fri Dec 16 09:02:28 2005 UTC revision 396 by gross, Wed Dec 21 05:08:25 2005 UTC
# Line 364  def testForZero(arg): Line 364  def testForZero(arg):
364      @return : True if the argument is identical to zero.      @return : True if the argument is identical to zero.
365      @rtype : C{bool}      @rtype : C{bool}
366      """      """
367      try:      if isinstance(arg,numarray.NumArray):
368         return not Lsup(arg)>0.         return not Lsup(arg)>0.
369      except TypeError:      elif isinstance(arg,escript.Data):
370           return False
371        elif isinstance(arg,float):
372           return not Lsup(arg)>0.
373        elif isinstance(arg,int):
374           return not Lsup(arg)>0.
375        elif isinstance(arg,Symbol):
376           return False
377        else:
378         return False         return False
379    
380  def matchType(arg0=0.,arg1=0.):  def matchType(arg0=0.,arg1=0.):
# Line 908  def wherePositive(arg): Line 916  def wherePositive(arg):
916     @raises TypeError: if the type of the argument is not expected.     @raises TypeError: if the type of the argument is not expected.
917     """     """
918     if isinstance(arg,numarray.NumArray):     if isinstance(arg,numarray.NumArray):
919        if arg.rank==0:        out=numarray.greater(arg,numarray.zeros(arg.shape,numarray.Float))
920           if arg>0:        if isinstance(out,float): out=numarray.array(out)
921             return numarray.array(1.)        return out
          else:  
            return numarray.array(0.)  
       else:  
          return numarray.greater(arg,numarray.zeros(arg.shape,numarray.Float))  
922     elif isinstance(arg,escript.Data):     elif isinstance(arg,escript.Data):
923        return arg._wherePositive()        return arg._wherePositive()
924     elif isinstance(arg,float):     elif isinstance(arg,float):
# Line 994  def whereNegative(arg): Line 998  def whereNegative(arg):
998     @raises TypeError: if the type of the argument is not expected.     @raises TypeError: if the type of the argument is not expected.
999     """     """
1000     if isinstance(arg,numarray.NumArray):     if isinstance(arg,numarray.NumArray):
1001        if arg.rank==0:        out=numarray.less(arg,numarray.zeros(arg.shape,numarray.Float))
1002           if arg<0:        if isinstance(out,float): out=numarray.array(out)
1003             return numarray.array(1.)        return out
          else:  
            return numarray.array(0.)  
       else:  
          return numarray.less(arg,numarray.zeros(arg.shape,numarray.Float))  
1004     elif isinstance(arg,escript.Data):     elif isinstance(arg,escript.Data):
1005        return arg._whereNegative()        return arg._whereNegative()
1006     elif isinstance(arg,float):     elif isinstance(arg,float):
# Line 1080  def whereNonNegative(arg): Line 1080  def whereNonNegative(arg):
1080     @raises TypeError: if the type of the argument is not expected.     @raises TypeError: if the type of the argument is not expected.
1081     """     """
1082     if isinstance(arg,numarray.NumArray):     if isinstance(arg,numarray.NumArray):
1083        if arg.rank==0:        out=numarray.greater_equal(arg,numarray.zeros(arg.shape,numarray.Float))
1084           if arg<0:        if isinstance(out,float): out=numarray.array(out)
1085             return numarray.array(0.)        return out
          else:  
            return numarray.array(1.)  
       else:  
          return numarray.greater_equal(arg,numarray.zeros(arg.shape,numarray.Float))  
1086     elif isinstance(arg,escript.Data):     elif isinstance(arg,escript.Data):
1087        return arg._whereNonNegative()        return arg._whereNonNegative()
1088     elif isinstance(arg,float):     elif isinstance(arg,float):
# Line 1114  def whereNonPositive(arg): Line 1110  def whereNonPositive(arg):
1110     @raises TypeError: if the type of the argument is not expected.     @raises TypeError: if the type of the argument is not expected.
1111     """     """
1112     if isinstance(arg,numarray.NumArray):     if isinstance(arg,numarray.NumArray):
1113        if arg.rank==0:        out=numarray.less_equal(arg,numarray.zeros(arg.shape,numarray.Float))*1.
1114           if arg>0:        if isinstance(out,float): out=numarray.array(out)
1115             return numarray.array(0.)        return out
          else:  
            return numarray.array(1.)  
       else:  
          return numarray.less_equal(arg,numarray.zeros(arg.shape,numarray.Float))*1.  
1116     elif isinstance(arg,escript.Data):     elif isinstance(arg,escript.Data):
1117        return arg._whereNonPositive()        return arg._whereNonPositive()
1118     elif isinstance(arg,float):     elif isinstance(arg,float):
# Line 1150  def whereZero(arg,tol=0.): Line 1142  def whereZero(arg,tol=0.):
1142     @raises TypeError: if the type of the argument is not expected.     @raises TypeError: if the type of the argument is not expected.
1143     """     """
1144     if isinstance(arg,numarray.NumArray):     if isinstance(arg,numarray.NumArray):
1145        if arg.rank==0:        out=numarray.less_equal(abs(arg)-tol,numarray.zeros(arg.shape,numarray.Float))*1.
1146           if abs(arg)<=tol:        if isinstance(out,float): out=numarray.array(out)
1147             return numarray.array(1.)        return out
          else:  
            return numarray.array(0.)  
       else:  
          return numarray.less_equal(abs(arg)-tol,numarray.zeros(arg.shape,numarray.Float))*1.  
1148     elif isinstance(arg,escript.Data):     elif isinstance(arg,escript.Data):
1149        if tol>0.:        if tol>0.:
1150           return whereNegative(abs(arg)-tol)           return whereNegative(abs(arg)-tol)
# Line 1237  def whereNonZero(arg,tol=0.): Line 1225  def whereNonZero(arg,tol=0.):
1225     @raises TypeError: if the type of the argument is not expected.     @raises TypeError: if the type of the argument is not expected.
1226     """     """
1227     if isinstance(arg,numarray.NumArray):     if isinstance(arg,numarray.NumArray):
1228        if arg.rank==0:        out=numarray.greater(abs(arg)-tol,numarray.zeros(arg.shape,numarray.Float))*1.
1229          if abs(arg)>tol:        if isinstance(out,float): out=numarray.array(out)
1230             return numarray.array(1.)        return out
         else:  
            return numarray.array(0.)  
       else:  
          return numarray.greater(abs(arg)-tol,numarray.zeros(arg.shape,numarray.Float))*1.  
1231     elif isinstance(arg,escript.Data):     elif isinstance(arg,escript.Data):
1232        if tol>0.:        if tol>0.:
1233           return 1.-whereZero(arg,tol)           return 1.-whereZero(arg,tol)
# Line 3305  def maximum(*args): Line 3289  def maximum(*args):
3289         if out==None:         if out==None:
3290            out=a            out=a
3291         else:         else:
3292            m=whereNegative(out-a)            diff=add(a,-out)
3293            out=m*a+(1.-m)*out            out=add(out,mult(wherePositive(diff),diff))
3294      return out      return out
3295        
3296  def minimum(*arg):  def minimum(*args):
3297      """      """
3298      the minimum over arguments args      the minimum over arguments args
3299    
# Line 3323  def minimum(*arg): Line 3307  def minimum(*arg):
3307         if out==None:         if out==None:
3308            out=a            out=a
3309         else:         else:
3310            m=whereNegative(out-a)            diff=add(a,-out)
3311            out=m*out+(1.-m)*a            out=add(out,mult(whereNegative(diff),diff))
3312      return out      return out
3313    
3314  def clip(arg,minval=0.,maxval=1.):  def clip(arg,minval=0.,maxval=1.):

Legend:
Removed from v.378  
changed lines
  Added in v.396

  ViewVC Help
Powered by ViewVC 1.1.26