Apply pre-defined model masks.
429887
def _model_mask(self, wavelengths=None):
        

        if wavelengths is None:
            wavelengths = self.wavelengths
        wavelengths = np.array(wavelengths)

        mask = np.ones_like(wavelengths, dtype=bool)
        model_mask = self._configuration.get("masks", {}).get("model", [])
        logger.debug("Applying model mask: {0}".format(model_mask))
        for start, end in model_mask:
            idx = np.clip(wavelengths.searchsorted([start, end]) + [0, 1], 0,
                wavelengths.size)
            mask[idx[0]:idx[1]] = False
        return mask
595952
def _makemasks(self, index=None, level=0):
        
        if index is None:
            index = self.index

        try:
            dims = len(array(index).shape)
            if dims == 1:
                index = array(index, ndmin=2).T
        except:
            raise TypeError('A multi-index must be convertible to a numpy ndarray')

        try:
            index = index[:, level]
        except:
            raise ValueError("Levels must be indices into individual elements of the index")

        lenIdx = index.shape[0]
        nlevels = index.shape[1]

        combs = product(*[unique(index.T[i, :]) for i in range(nlevels)])
        combs = array([l for l in combs])

        masks = array([[array_equal(index[i], c) for i in range(lenIdx)] for c in combs])

        return zip(*[(masks[x], combs[x]) for x in range(len(masks)) if masks[x].any()])
372559
def segmentation_to_mask(polys, height, width):
    
    polys = [p.flatten().tolist() for p in polys]
    assert len(polys) > 0, "Polygons are empty!"

    import pycocotools.mask as cocomask
    rles = cocomask.frPyObjects(polys, height, width)
    rle = cocomask.merge(rles)
    return cocomask.decode(rle)
1365321
def putmask(self, mask, value):
        
        values = self.values.copy()
        try:
            np.putmask(values, mask, self._convert_for_op(value))
            return self._shallow_copy(values)
        except (ValueError, TypeError) as err:
            if is_object_dtype(self):
                raise err

            # coerces to object
            return self.astype(object).putmask(mask, value)
78041
function SpriteMaskFilter(sprite)
{
    var maskMatrix = new math.Matrix();

    AbstractFilter.call(this,
        fs.readFileSync(__dirname + '/spriteMaskFilter.vert', 'utf8'),
        fs.readFileSync(__dirname + '/spriteMaskFilter.frag', 'utf8'),
        {
            mask:           { type: 'sampler2D', value: sprite._texture },
            alpha:          { type: 'f', value: 1},
            otherMatrix:    { type: 'mat3', value: maskMatrix.toArray(true) }
        }
    );

    this.maskSprite = sprite;
    this.maskMatrix = maskMatrix;
}
1147135
def dropout_mask(x:Tensor, sz:Collection[int], p:float):
    ""
    return x.new(*sz).bernoulli_(1-p).div_(1-p)
912238
def validation_scatter(self, log_lam, b, masks, pre_v, gp, flux,
                           time, med):
        '''
        

        '''

        # Update the lambda matrix
        self.lam[b] = 10 ** log_lam

        # Validation set scatter
        scatter = [None for i in range(len(masks))]
        for i in range(len(masks)):
            model = self.cv_compute(b, *pre_v[i])
            try:
                gpm, _ = gp.predict(flux - model - med, time[masks[i]])
            except ValueError:
                # Sometimes the model can have NaNs if
                # `lambda` is a crazy value
                return 1.e30
            fdet = (flux - model)[masks[i]] - gpm
            scatter[i] = 1.e6 * (1.4826 * np.nanmedian(np.abs(fdet / med -
                                 np.nanmedian(fdet / med))) /
                                 np.sqrt(len(masks[i])))

        return np.max(scatter)
1044860
public void revertFeatures(@NonNull INDArray[] features, INDArray[] maskArrays) {
        for (int i = 0; i < features.length; i++) {
            INDArray mask = (maskArrays == null ? null : maskArrays[i]);
            revertFeatures(features[i], mask, i);
        }
    }
594429
def poly2o_residual(params, data, mask):
    """"""
    bg = poly2o_model(params, shape=data.shape)
    res = (data - bg)[mask]
    return res.flatten()
852047
def remove_absolute_mask__r2(X, y, model_generator, method_name, num_fcounts=11):
    
    return __run_measure(measures.remove_mask, X, y, model_generator, method_name, 0, num_fcounts, sklearn.metrics.r2_score)
275471
def mdaZeros(shap, dtype=numpy.float, mask=None):
    
    res = MaskedDistArray(shap, dtype)
    res[:] = 0
    res.mask = mask
    return res
901337
def set_classifier_mask(self, v, base_mask=True):
        """"""
        base = self._base
        v = tonparray(v)
        a = np.unique(v)
        if a[0] != -1 or a[1] != 1:
            raise RuntimeError("The labels must be -1 and 1 (%s)" % a)
        mask = np.zeros_like(v)
        cnt = min([(v == x).sum() for x in a]) * base._tr_fraction
        cnt = int(round(cnt))
        for i in a:
            index = np.where((v == i) & base_mask)[0]
            np.random.shuffle(index)
            mask[index[:cnt]] = True
        base._mask = SparseArray.fromlist(mask)
        return SparseArray.fromlist(v)
460318
def _make_mask(self, data, lon_str=LON_STR, lat_str=LAT_STR):
        """"""
        mask = False
        for west, east, south, north in self.mask_bounds:
            if west < east:
                mask_lon = (data[lon_str] > west) & (data[lon_str] < east)
            else:
                mask_lon = (data[lon_str] < west) | (data[lon_str] > east)
            mask_lat = (data[lat_str] > south) & (data[lat_str] < north)
            mask |= mask_lon & mask_lat
        return mask
813014
def _build_mask(self):
        """"""
        self.mask = torch.ones(self.d, self.d).byte()
        for ci in self.c_data.values():
            si, ei = ci["start_index"], ci["end_index"]
            for cj in self.c_data.values():
                sj, ej = cj["start_index"], cj["end_index"]

                # Check if ci and cj are part of the same maximal clique
                # If so, mask out their corresponding blocks in O^{-1}
                if len(ci["max_cliques"].intersection(cj["max_cliques"])) > 0:
                    self.mask[si:ei, sj:ej] = 0
                    self.mask[sj:ej, si:ei] = 0
114218
def set_on_mask(self, mask):
        """"""
        set_cmd = self._create_set_property_msg('_on_mask', 0x02, mask)
        self._send_method(set_cmd, self._property_set)
473192
def _format_object_mask(objectmask):
    
    objectmask = objectmask.strip()

    if (not objectmask.startswith('mask') and
            not objectmask.startswith('[')):
        objectmask = "mask[%s]" % objectmask
    return objectmask
193063
def apply_mask(data: bytes, mask: bytes) -> bytes:
    
    if len(mask) != 4:
        raise ValueError("mask must contain 4 bytes")

    return bytes(b ^ m for b, m in zip(data, itertools.cycle(mask)))