MCPcopy Index your code
hub / github.com/numpy/numpy / _MaskedUnaryOperation

Class _MaskedUnaryOperation

numpy/ma/core.py:955–1026  ·  view source on GitHub ↗

Defines masked version of unary operations, where invalid values are pre-masked. Parameters ---------- mufunc : callable The function for which to define a masked version. Made available as ``_MaskedUnaryOperation.f``. fill : scalar, optional Filling

Source from the content-addressed store, hash-verified

953
954
955class _MaskedUnaryOperation(_MaskedUFunc):
956 """
957 Defines masked version of unary operations, where invalid values are
958 pre-masked.
959
960 Parameters
961 ----------
962 mufunc : callable
963 The function for which to define a masked version. Made available
964 as ``_MaskedUnaryOperation.f``.
965 fill : scalar, optional
966 Filling value, default is 0.
967 domain : class instance
968 Domain for the function. Should be one of the ``_Domain*``
969 classes. Default is None.
970
971 """
972
973 def __init__(self, mufunc, fill=0, domain=None):
974 super().__init__(mufunc)
975 self.fill = fill
976 self.domain = domain
977 ufunc_domain[mufunc] = domain
978 ufunc_fills[mufunc] = fill
979
980 def __call__(self, a, *args, **kwargs):
981 """
982 Execute the call behavior.
983
984 """
985 d = getdata(a)
986 # Deal with domain
987 if self.domain is not None:
988 # Case 1.1. : Domained function
989 # nans at masked positions cause RuntimeWarnings, even though
990 # they are masked. To avoid this we suppress warnings.
991 with np.errstate(divide='ignore', invalid='ignore'):
992 result = self.f(d, *args, **kwargs)
993 # Make a mask
994 m = ~umath.isfinite(result)
995 m |= self.domain(d)
996 m |= getmask(a)
997 else:
998 # Case 1.2. : Function without a domain
999 # Get the result and the mask
1000 with np.errstate(divide='ignore', invalid='ignore'):
1001 result = self.f(d, *args, **kwargs)
1002 m = getmask(a)
1003
1004 if not result.ndim:
1005 # Case 2.1. : The result is scalarscalar
1006 if m:
1007 return masked
1008 return result
1009
1010 if m is not nomask:
1011 # Case 2.2. The result is an array
1012 # We need to fill the invalid data back w/ the input Now,

Callers 1

core.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…