~vcs-imports/numpy/master

« back to all changes in this revision

Viewing changes to numpy/core/numeric.py

  • Committer: Charles Harris
  • Date: 2013-07-12 00:16:42 UTC
  • mfrom: (8144.2.1)
  • Revision ID: git-v1:a053a4372aba0af0bd63ffd5e207baf469cfc7bf
Merge pull request #3518 from charris/use-errstate-context-manager

MAINT: Use np.errstate context manager.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2125
2125
        y = y[~xinf]
2126
2126
 
2127
2127
    # ignore invalid fpe's
2128
 
    with warnings.catch_warnings():
2129
 
        warnings.simplefilter("ignore")
 
2128
    with errstate(invalid='ignore'):
2130
2129
        r = all(less_equal(abs(x-y), atol + rtol * abs(y)))
2131
2130
 
2132
2131
    return r
2191
2190
    array([True, True])
2192
2191
    """
2193
2192
    def within_tol(x, y, atol, rtol):
2194
 
        err = seterr(invalid='ignore')
2195
 
        try:
 
2193
        with errstate(invalid='ignore'):
2196
2194
            result = less_equal(abs(x-y), atol + rtol * abs(y))
2197
 
        finally:
2198
 
            seterr(**err)
2199
2195
        if isscalar(a) and isscalar(b):
2200
2196
            result = bool(result)
2201
2197
        return result
2705
2701
    def __init__(self, **kwargs):
2706
2702
        self.call = kwargs.pop('call',_Unspecified)
2707
2703
        self.kwargs = kwargs
 
2704
 
2708
2705
    def __enter__(self):
2709
2706
        self.oldstate = seterr(**self.kwargs)
2710
2707
        if self.call is not _Unspecified:
2711
2708
            self.oldcall = seterrcall(self.call)
 
2709
 
2712
2710
    def __exit__(self, *exc_info):
2713
2711
        seterr(**self.oldstate)
2714
2712
        if self.call is not _Unspecified:
2715
2713
            seterrcall(self.oldcall)
2716
2714
 
 
2715
 
2717
2716
def _setdef():
2718
2717
    defval = [UFUNC_BUFSIZE_DEFAULT, ERR_DEFAULT2, None]
2719
2718
    umath.seterrobj(defval)