Changeset 2738 for trunk

Show
Ignore:
Timestamp:
09/29/2008 09:12:43 AM (3 months ago)
Author:
guyer
Message:

Added an isclose function. Element-by-element version of allclose. Why
isn't this in NumPy already?

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/fipy/tools/numerix.py

    r2726 r2738  
    77 #  FILE: "numerix.py" 
    88 #                                    created: 1/10/04 {10:23:17 AM}  
    9  #                                last update: 6/13/08 {6:38:52 PM}  
     9 #                                last update: 9/29/08 {9:52:36 AM}  
    1010 #  Author: Jonathan Guyer <guyer@nist.gov> 
    1111 #  Author: Daniel Wheeler <daniel.wheeler@nist.gov> 
     
    10741074        return MA.allclose(first, second, atol=atol, rtol=rtol) 
    10751075 
     1076def isclose(first, second, rtol=1.e-5, atol=1.e-8): 
     1077    r""" 
     1078    Returns which elements of `first` and `second` are equal, subect to the given 
     1079    relative and absolute tolerances, such that:: 
     1080         
     1081        | first - second | < atol + rtol * | second | 
     1082         
     1083    This means essentially that both elements are small compared to `atol` or 
     1084    their difference divided by `second`'s value is small compared to `rtol`. 
     1085    """ 
     1086    return abs(first - second) < atol + rtol * abs(second) 
    10761087 
    10771088def take(a, indices, axis=0, fill_value=None):