Define a domain for safe division.
| 889 | |
| 890 | |
| 891 | class _DomainSafeDivide: |
| 892 | """ |
| 893 | Define a domain for safe division. |
| 894 | |
| 895 | """ |
| 896 | |
| 897 | def __init__(self, tolerance=None): |
| 898 | self.tolerance = tolerance |
| 899 | |
| 900 | def __call__(self, a, b): |
| 901 | # Delay the selection of the tolerance to here in order to reduce numpy |
| 902 | # import times. The calculation of these parameters is a substantial |
| 903 | # component of numpy's import time. |
| 904 | if self.tolerance is None: |
| 905 | self.tolerance = np.finfo(float).tiny |
| 906 | # don't call ma ufuncs from __array_wrap__ which would fail for scalars |
| 907 | a, b = np.asarray(a), np.asarray(b) |
| 908 | with np.errstate(all='ignore'): |
| 909 | return umath.absolute(a) * self.tolerance >= umath.absolute(b) |
| 910 | |
| 911 | |
| 912 | class _DomainGreater: |
no outgoing calls
no test coverage detected
searching dependent graphs…