Define masked version of binary operations, where invalid values are pre-masked. Parameters ---------- mbfunc : function The function for which to define a masked version. Made available as ``_MaskedBinaryOperation.f``. domain : class instance Defaul
| 1027 | |
| 1028 | |
| 1029 | class _MaskedBinaryOperation(_MaskedUFunc): |
| 1030 | """ |
| 1031 | Define masked version of binary operations, where invalid |
| 1032 | values are pre-masked. |
| 1033 | |
| 1034 | Parameters |
| 1035 | ---------- |
| 1036 | mbfunc : function |
| 1037 | The function for which to define a masked version. Made available |
| 1038 | as ``_MaskedBinaryOperation.f``. |
| 1039 | domain : class instance |
| 1040 | Default domain for the function. Should be one of the ``_Domain*`` |
| 1041 | classes. Default is None. |
| 1042 | fillx : scalar, optional |
| 1043 | Filling value for the first argument, default is 0. |
| 1044 | filly : scalar, optional |
| 1045 | Filling value for the second argument, default is 0. |
| 1046 | |
| 1047 | """ |
| 1048 | |
| 1049 | def __init__(self, mbfunc, fillx=0, filly=0): |
| 1050 | """ |
| 1051 | abfunc(fillx, filly) must be defined. |
| 1052 | |
| 1053 | abfunc(x, filly) = x for all x to enable reduce. |
| 1054 | |
| 1055 | """ |
| 1056 | super().__init__(mbfunc) |
| 1057 | self.fillx = fillx |
| 1058 | self.filly = filly |
| 1059 | ufunc_domain[mbfunc] = None |
| 1060 | ufunc_fills[mbfunc] = (fillx, filly) |
| 1061 | |
| 1062 | def __call__(self, a, b, *args, **kwargs): |
| 1063 | """ |
| 1064 | Execute the call behavior. |
| 1065 | |
| 1066 | """ |
| 1067 | # Get the data, as ndarray |
| 1068 | (da, db) = (getdata(a), getdata(b)) |
| 1069 | # Get the result |
| 1070 | with np.errstate(): |
| 1071 | np.seterr(divide='ignore', invalid='ignore') |
| 1072 | result = self.f(da, db, *args, **kwargs) |
| 1073 | # Get the mask for the result |
| 1074 | (ma, mb) = (getmask(a), getmask(b)) |
| 1075 | if ma is nomask: |
| 1076 | if mb is nomask: |
| 1077 | m = nomask |
| 1078 | else: |
| 1079 | m = umath.logical_or(getmaskarray(a), mb) |
| 1080 | elif mb is nomask: |
| 1081 | m = umath.logical_or(ma, getmaskarray(b)) |
| 1082 | else: |
| 1083 | m = umath.logical_or(ma, mb) |
| 1084 | |
| 1085 | # Case 1. : scalar |
| 1086 | if not result.ndim: |
no outgoing calls
no test coverage detected
searching dependent graphs…