Define a domain for safe division.
| 838 | |
| 839 | |
| 840 | class _DomainSafeDivide: |
| 841 | """ |
| 842 | Define a domain for safe division. |
| 843 | |
| 844 | """ |
| 845 | |
| 846 | def __init__(self, tolerance=None): |
| 847 | self.tolerance = tolerance |
| 848 | |
| 849 | def __call__(self, a, b): |
| 850 | # Delay the selection of the tolerance to here in order to reduce numpy |
| 851 | # import times. The calculation of these parameters is a substantial |
| 852 | # component of numpy's import time. |
| 853 | if self.tolerance is None: |
| 854 | self.tolerance = np.finfo(float).tiny |
| 855 | # don't call ma ufuncs from __array_wrap__ which would fail for scalars |
| 856 | a, b = np.asarray(a), np.asarray(b) |
| 857 | with np.errstate(invalid='ignore'): |
| 858 | return umath.absolute(a) * self.tolerance >= umath.absolute(b) |
| 859 | |
| 860 | |
| 861 | class _DomainGreater: |
no outgoing calls
no test coverage detected