MCPcopy Create free account
hub / github.com/numpy/numpy / __call__

Method __call__

numpy/ma/core.py:1157–1197  ·  view source on GitHub ↗

Execute the call behavior.

(self, a, b, *args, **kwargs)

Source from the content-addressed store, hash-verified

1155 ufunc_fills[dbfunc] = (fillx, filly)
1156
1157 def __call__(self, a, b, *args, **kwargs):
1158 "Execute the call behavior."
1159 # Get the data
1160 (da, db) = (getdata(a), getdata(b))
1161 # Get the result
1162 with np.errstate(divide='ignore', invalid='ignore'):
1163 result = self.f(da, db, *args, **kwargs)
1164 # Get the mask as a combination of the source masks and invalid
1165 m = ~umath.isfinite(result)
1166 m |= getmask(a)
1167 m |= getmask(b)
1168 # Apply the domain
1169 domain = ufunc_domain.get(self.f, None)
1170 if domain is not None:
1171 m |= domain(da, db)
1172 # Take care of the scalar case first
1173 if not m.ndim:
1174 if m:
1175 return masked
1176 else:
1177 return result
1178 # When the mask is True, put back da if possible
1179 # any errors, just abort; impossible to guarantee masked values
1180 try:
1181 np.copyto(result, 0, casting='unsafe', where=m)
1182 # avoid using "*" since this may be overlaid
1183 masked_da = umath.multiply(m, da)
1184 # only add back if it can be cast safely
1185 if np.can_cast(masked_da.dtype, result.dtype, casting='safe'):
1186 result += masked_da
1187 except Exception:
1188 pass
1189
1190 # Transforms to a (subclass of) MaskedArray
1191 masked_result = result.view(get_masked_subclass(a, b))
1192 masked_result._mask = m
1193 if isinstance(a, MaskedArray):
1194 masked_result._update_from(a)
1195 elif isinstance(b, MaskedArray):
1196 masked_result._update_from(b)
1197 return masked_result
1198
1199
1200# Unary ufuncs

Callers

nothing calls this directly

Calls 7

getdataFunction · 0.85
getmaskFunction · 0.85
get_masked_subclassFunction · 0.85
_update_fromMethod · 0.80
fMethod · 0.45
getMethod · 0.45
viewMethod · 0.45

Tested by

no test coverage detected