/[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 329 by gross, Wed Dec 7 04:42:43 2005 UTC revision 341 by gross, Mon Dec 12 05:26:10 2005 UTC
# Line 24  Utility functions for escript Line 24  Utility functions for escript
24  __author__="Lutz Gross, l.gross@uq.edu.au"  __author__="Lutz Gross, l.gross@uq.edu.au"
25  __licence__="contact: esys@access.uq.edu.au"  __licence__="contact: esys@access.uq.edu.au"
26  __url__="http://www.iservo.edu.au/esys/escript"  __url__="http://www.iservo.edu.au/esys/escript"
27  __version__="$Revision$"  __version__="$Revision: 329 $"
28  __date__="$Date$"  __date__="$Date$"
29    
30    
# Line 907  def wherePositive(arg): Line 907  def wherePositive(arg):
907     @raises TypeError: if the type of the argument is not expected.     @raises TypeError: if the type of the argument is not expected.
908     """     """
909     if isinstance(arg,numarray.NumArray):     if isinstance(arg,numarray.NumArray):
910        return numarray.greater(arg,numarray.zeros(arg.shape,numarray.Float))        if arg.rank==0:
911             if arg>0:
912               return numarray.array(1.)
913             else:
914               return numarray.array(0.)
915          else:
916             return numarray.greater(arg,numarray.zeros(arg.shape,numarray.Float))
917     elif isinstance(arg,escript.Data):     elif isinstance(arg,escript.Data):
918        return arg._wherePositive()        return arg._wherePositive()
919     elif isinstance(arg,float):     elif isinstance(arg,float):
# Line 987  def whereNegative(arg): Line 993  def whereNegative(arg):
993     @raises TypeError: if the type of the argument is not expected.     @raises TypeError: if the type of the argument is not expected.
994     """     """
995     if isinstance(arg,numarray.NumArray):     if isinstance(arg,numarray.NumArray):
996        return numarray.less(arg,numarray.zeros(arg.shape,numarray.Float))        if arg.rank==0:
997             if arg<0:
998               return numarray.array(1.)
999             else:
1000               return numarray.array(0.)
1001          else:
1002             return numarray.less(arg,numarray.zeros(arg.shape,numarray.Float))
1003     elif isinstance(arg,escript.Data):     elif isinstance(arg,escript.Data):
1004        return arg._whereNegative()        return arg._whereNegative()
1005     elif isinstance(arg,float):     elif isinstance(arg,float):
# Line 1067  def whereNonNegative(arg): Line 1079  def whereNonNegative(arg):
1079     @raises TypeError: if the type of the argument is not expected.     @raises TypeError: if the type of the argument is not expected.
1080     """     """
1081     if isinstance(arg,numarray.NumArray):     if isinstance(arg,numarray.NumArray):
1082        return numarray.greater_equal(arg,numarray.zeros(arg.shape,numarray.Float))        if arg.rank==0:
1083             if arg<0:
1084               return numarray.array(0.)
1085             else:
1086               return numarray.array(1.)
1087          else:
1088             return numarray.greater_equal(arg,numarray.zeros(arg.shape,numarray.Float))
1089     elif isinstance(arg,escript.Data):     elif isinstance(arg,escript.Data):
1090        return arg._whereNonNegative()        return arg._whereNonNegative()
1091     elif isinstance(arg,float):     elif isinstance(arg,float):
# Line 1095  def whereNonPositive(arg): Line 1113  def whereNonPositive(arg):
1113     @raises TypeError: if the type of the argument is not expected.     @raises TypeError: if the type of the argument is not expected.
1114     """     """
1115     if isinstance(arg,numarray.NumArray):     if isinstance(arg,numarray.NumArray):
1116        return numarray.less_equal(arg,numarray.zeros(arg.shape,numarray.Float))        if arg.rank==0:
1117             if arg>0:
1118               return numarray.array(0.)
1119             else:
1120               return numarray.array(1.)
1121          else:
1122             return numarray.less_equal(arg,numarray.zeros(arg.shape,numarray.Float))*1.
1123     elif isinstance(arg,escript.Data):     elif isinstance(arg,escript.Data):
1124        return arg._whereNonPositive()        return arg._whereNonPositive()
1125     elif isinstance(arg,float):     elif isinstance(arg,float):
# Line 1125  def whereZero(arg,tol=0.): Line 1149  def whereZero(arg,tol=0.):
1149     @raises TypeError: if the type of the argument is not expected.     @raises TypeError: if the type of the argument is not expected.
1150     """     """
1151     if isinstance(arg,numarray.NumArray):     if isinstance(arg,numarray.NumArray):
1152        return numarray.less_equal(abs(arg)-tol,numarray.zeros(arg.shape,numarray.Float))        if arg.rank==0:
1153             if abs(arg)<=tol:
1154               return numarray.array(1.)
1155             else:
1156               return numarray.array(0.)
1157          else:
1158             return numarray.less_equal(abs(arg)-tol,numarray.zeros(arg.shape,numarray.Float))*1.
1159     elif isinstance(arg,escript.Data):     elif isinstance(arg,escript.Data):
1160        if tol>0.:        if tol>0.:
1161           return whereNegative(abs(arg)-tol)           return whereNegative(abs(arg)-tol)
# Line 1206  def whereNonZero(arg,tol=0.): Line 1236  def whereNonZero(arg,tol=0.):
1236     @raises TypeError: if the type of the argument is not expected.     @raises TypeError: if the type of the argument is not expected.
1237     """     """
1238     if isinstance(arg,numarray.NumArray):     if isinstance(arg,numarray.NumArray):
1239        return numarray.greater(abs(arg)-tol,numarray.zeros(arg.shape,numarray.Float))        if arg.rank==0:
1240            if abs(arg)>tol:
1241               return numarray.array(1.)
1242            else:
1243               return numarray.array(0.)
1244          else:
1245             return numarray.greater(abs(arg)-tol,numarray.zeros(arg.shape,numarray.Float))*1.
1246     elif isinstance(arg,escript.Data):     elif isinstance(arg,escript.Data):
1247        if tol>0.:        if tol>0.:
1248           return 1.-whereZero(arg,tol)           return 1.-whereZero(arg,tol)
# Line 2687  def minval(arg): Line 2723  def minval(arg):
2723     @raises TypeError: if the type of the argument is not expected.     @raises TypeError: if the type of the argument is not expected.
2724     """     """
2725     if isinstance(arg,numarray.NumArray):     if isinstance(arg,numarray.NumArray):
2726        return arg.min()        if arg.rank==0:
2727             return float(arg)
2728          else:
2729             return arg.min()
2730     elif isinstance(arg,escript.Data):     elif isinstance(arg,escript.Data):
2731        return arg._minval()        return arg._minval()
2732     elif isinstance(arg,float):     elif isinstance(arg,float):
# Line 2761  def maxval(arg): Line 2800  def maxval(arg):
2800     @raises TypeError: if the type of the argument is not expected.     @raises TypeError: if the type of the argument is not expected.
2801     """     """
2802     if isinstance(arg,numarray.NumArray):     if isinstance(arg,numarray.NumArray):
2803        return arg.max()        if arg.rank==0:
2804             return float(arg)
2805          else:
2806             return arg.max()
2807     elif isinstance(arg,escript.Data):     elif isinstance(arg,escript.Data):
2808        return arg._maxval()        return arg._maxval()
2809     elif isinstance(arg,float):     elif isinstance(arg,float):

Legend:
Removed from v.329  
changed lines
  Added in v.341

  ViewVC Help
Powered by ViewVC 1.1.26