/[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 2303 by gross, Wed Mar 11 08:17:57 2009 UTC revision 2304 by gross, Fri Mar 13 03:17:24 2009 UTC
# Line 1490  def whereNonPositive(arg): Line 1490  def whereNonPositive(arg):
1490     else:     else:
1491        raise TypeError,"whereNonPositive: Unknown argument type."        raise TypeError,"whereNonPositive: Unknown argument type."
1492    
1493  def whereZero(arg,tol=0.):  def whereZero(arg,tol=None,adaptTol=True,rtol=math.sqrt(EPSILON)):
1494     """     """
1495     Returns mask of zero entries of argument C{arg}.     Returns mask of zero entries of argument C{arg}.
1496    
1497     @param arg: argument     @param arg: argument
1498     @type arg: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray}     @type arg: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray}
1499     @param tol: tolerance. Values with absolute value less than tol are accepted     @param tol: absolute tolerance. Values with absolute value less than tol are accepted
1500                 as zero.                 as zero. If C{tol} is not present C{rtol}*C{L{Lsup}(arg)} is used.
1501     @type tol: C{float}     @type tol: C{float}
1502       @param rtol: relative tolerance used to define the absolute tolerance if C{tol} is not present.
1503       @type rtol: non-negative C{float}
1504     @rtype: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray} depending     @rtype: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray} depending
1505             on the type of C{arg}             on the type of C{arg}
1506       @raises ValueError: if C{rtol} is non-negative.
1507     @raises TypeError: if the type of the argument is not expected     @raises TypeError: if the type of the argument is not expected
1508     """     """
1509       if tol == None:
1510          if not isinstance(arg,Symbol):
1511             if rtol<=0: raise ValueError,"rtol must be non-negative."
1512             tol = Lsup(arg)*rtol
1513          else:
1514             tol=0.
1515     if isinstance(arg,numarray.NumArray):     if isinstance(arg,numarray.NumArray):
1516        out=numarray.less_equal(abs(arg)-tol,numarray.zeros(arg.shape,numarray.Float64))*1.        out=numarray.less_equal(abs(arg)-tol,numarray.zeros(arg.shape,numarray.Float64))*1.
1517        if isinstance(out,float): out=numarray.array(out,type=numarray.Float64)        if isinstance(out,float): out=numarray.array(out,type=numarray.Float64)
# Line 1587  def whereNonZero(arg,tol=0.): Line 1596  def whereNonZero(arg,tol=0.):
1596     Returns mask of values different from zero of argument C{arg}.     Returns mask of values different from zero of argument C{arg}.
1597    
1598     @param arg: argument     @param arg: argument
1599     @type arg: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray}.     @type arg: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray}
1600       @param tol: absolute tolerance. Values with absolute value less than tol are accepted
1601                   as zero. If C{tol} is not present C{rtol}*C{L{Lsup}(arg)} is used.
1602       @type tol: C{float}
1603       @param rtol: relative tolerance used to define the absolute tolerance if C{tol} is not present.
1604       @type rtol: non-negative C{float}
1605     @rtype: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray} depending     @rtype: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray} depending
1606             on the type of C{arg}             on the type of C{arg}
1607     @raise TypeError: if the type of the argument is not expected     @raises ValueError: if C{rtol} is non-negative.
1608       @raises TypeError: if the type of the argument is not expected
1609     """     """
1610       if tol == None:
1611          if not isinstance(arg,Symbol):
1612             if rtol<=0: raise ValueError,"rtol must be non-negative."
1613             tol = Lsup(arg)*rtol
1614          else:
1615             tol=0.
1616     if isinstance(arg,numarray.NumArray):     if isinstance(arg,numarray.NumArray):
1617        out=numarray.greater(abs(arg)-tol,numarray.zeros(arg.shape,numarray.Float64))*1.        out=numarray.greater(abs(arg)-tol,numarray.zeros(arg.shape,numarray.Float64))*1.
1618        if isinstance(out,float): out=numarray.array(out,type=numarray.Float64)        if isinstance(out,float): out=numarray.array(out,type=numarray.Float64)

Legend:
Removed from v.2303  
changed lines
  Added in v.2304

  ViewVC Help
Powered by ViewVC 1.1.26