Apply mask penalty rule 4 and return the penalty. Calculate the ratio of dark cells and give
penalty if the ratio is far from 50%. It gives 10 penalty for 5% distance.
518915
static int applyMaskPenaltyRule4(ByteMatrix matrix) {
    int numDarkCells = 0;
    byte[][] array = matrix.getArray();
    int width = matrix.getWidth();
    int height = matrix.getHeight();
    for (int y = 0; y < height; y++) {
      byte[] arrayY = array[y];
      for (int x = 0; x < width; x++) {
        if (arrayY[x] == 1) {
          numDarkCells++;
        }
      }
    }
    int numTotalCells = matrix.getHeight() * matrix.getWidth();
    int fivePercentVariances = Math.abs(numDarkCells * 2 - numTotalCells) * 10 / numTotalCells;
    return fivePercentVariances * N4;
  }
932156
def set_to_numa_nodemask(mask):
    
    result = nodemask_t()
    __nodemask_zero(result)

    for i in range(0, get_max_node() + 1):
        if i in mask:
            __nodemask_set(result, i)

    return result
540906
def absrange_fltr(dem, rangelim):
    
    out = range_fltr(np.ma.abs(dem), *rangelim)
    #Apply mask to original input
    out = np.ma.array(dem, mask=np.ma.getmaskarray(out))
    out.set_fill_value(dem.fill_value)
    return out
629794
def _update_mask(self):
        """"""
        self._threshold_mask = self._data > self._theta
        self._threshold_mask_v = self._data > self._theta/np.abs(self._v)
1280877
def showcutoffs(self, redblue = False):
        
        
        highmask = self.numpyarray > self.z2
        lowmask = self.numpyarray < self.z1
        if redblue == False :
            if self.negative :
                self.drawmask(highmask, colour = 255)
                self.drawmask(lowmask, colour = 0)
            else :
                self.drawmask(highmask, colour = 0)
                self.drawmask(lowmask, colour = 255)
        else :
            
            self.drawmask(highmask, colour = (255, 0, 0))
            self.drawmask(lowmask, colour = (0, 0, 255))
1320503
def dz_fltr_ma(dem, refdem, perc=None, rangelim=(0,30), smooth=False):
    
    if smooth:
        refdem = gauss_fltr_astropy(refdem)
        dem = gauss_fltr_astropy(dem)

    dz = refdem - dem

    #This is True for invalid values in DEM, and should be masked
    demmask = np.ma.getmaskarray(dem)

    if perc:
        dz_perc = malib.calcperc(dz, perc)
        print("Applying dz percentile filter (%s%%, %s%%): (%0.1f, %0.1f)" % (perc[0], perc[1], dz_perc[0], dz_perc[1]))
        #This is True for invalid values
        perc_mask = ((dz < dz_perc[0]) | (dz > dz_perc[1])).filled(False)
        demmask = (demmask | perc_mask)

    if rangelim:
        #This is True for invalid values
        range_mask = ((np.abs(dz) < rangelim[0]) | (np.abs(dz) > rangelim[1])).filled(False)
        if False:
            cutoff = 150
            rangelim = (0, 80)
            low = (refdem < cutoff).data
            range_mask[low] = ((np.abs(dz) < rangelim[0]) | (np.abs(dz) > rangelim[1])).filled(False)[low]
        demmask = (demmask | range_mask)

    out = np.ma.array(dem, mask=demmask, fill_value=dem.fill_value)
    return out
334080
def cause_ratio(self, mechanism, purview):
        """"""
        return self._ratio(Direction.CAUSE, mechanism, purview)
1169648
def _cellMask(self, index):
        
        row = index.row()
        col = index.column()
        if (row < 0 or row >= self.rowCount() or col < 0 or col >= self.columnCount()):
            return None

        # The check above should have returned None if the sliced array is None
        assert self._slicedArray is not None, "Sanity check failed."

        nFields = len(self._fieldNames)
        mask = self._slicedArray.mask
        if is_an_array(mask):
            if self._separateFieldOrientation == Qt.Horizontal:
                maskValue = mask[row, col // nFields][self._fieldNames[col % nFields]]
            elif self._separateFieldOrientation == Qt.Vertical:
                maskValue = mask[row // nFields, col][self._fieldNames[row % nFields]]
            else:
                maskValue = mask[row, col]
        else:
            maskValue = mask

        # Here maskValue can still be a list in case of structured arrays. It can even still be
        # a numpy array in case of a structured array with sub arrays as fields
        if is_an_array(maskValue):
            allMasked = np.all(maskValue)
        else:
            try:
                allMasked = all(maskValue)
            except TypeError as ex:
                allMasked = bool(maskValue)

        return allMasked
324840
function checkTree(mp) {
    const paths = mp.map(rule => rule.match);
    paths.forEach(path => checkPath(path));
    if (paths.length <= 1) { // Only one rule, no need to check for shadowing
        return true;
    }
    paths.reduce((a, b) => {
        const [ diffA, diffB ] = keepDifference(a, b);
        if (diffA[0] === '**' && diffA[1] === '*' &&
            !(diffB.length === 1 && diffB[0] === '/')) {
            warn(`Inaccessible paths: "${a.join('/')}" shadows following ` +
                 `paths (will never match). Place more specifics rules on top.`);
        }
        return b;
    });
}
551376
private static void mult(int[] s1, int s1Len, int[] s2, int s2Len, int[] dst) {
        for (int i = 0; i < s1Len; i++) {
            long v = s1[i] & LONG_MASK;
            long p = 0L;
            for (int j = 0; j < s2Len; j++) {
                p += (dst[i + j] & LONG_MASK) + v * (s2[j] & LONG_MASK);
                dst[i + j] = (int) p;
                p >>>= 32;
            }
            dst[i + s2Len] = (int) p;
        }
    }
1209275
function getMatrix(data) {
    var matrix = init(data.version);
    fillFinders(matrix);
    fillAlignAndTiming(matrix);
    fillStub(matrix);

    var penalty = Infinity;
    var bestMask = 0;
    for (var mask = 0; mask < 8; mask++) {
        fillData(matrix, data, mask);
        fillReserved(matrix, data.ec_level, mask);
        var p = calculatePenalty(matrix);
        if (p < penalty) {
            penalty = p;
            bestMask = mask;
        }
    }

    fillData(matrix, data, bestMask);
    fillReserved(matrix, data.ec_level, bestMask);

    return matrix.map(function(row) {
        return row.map(function(cell) {
            return cell & 1;
        });
    });
}
996018
private void calculate(String mask) {
        Matcher matcher = cidrPattern.matcher(mask);

        if (matcher.matches()) {
            matchAddress(matcher);

            /* Create a binary netmask from the number of bits specification /x */
            rangeCheck(Integer.parseInt(matcher.group(5)), 0, NBITS);
        } else {
            throw new IllegalArgumentException("Could not parse [" + mask + "]");
        }
    }
1350650
def prior_H0(self, H0, H0_min=0, H0_max=200):
        
        if H0 < H0_min or H0 > H0_max:
            penalty = -10**15
            return penalty, False
        else:
            return 0, True
1178848
private static int[][] calculateBlackPoints(byte[] luminances,
                                              int subWidth,
                                              int subHeight,
                                              int width,
                                              int height) {
    int maxYOffset = height - BLOCK_SIZE;
    int maxXOffset = width - BLOCK_SIZE;
    int[][] blackPoints = new int[subHeight][subWidth];
    for (int y = 0; y < subHeight; y++) {
      int yoffset = y << BLOCK_SIZE_POWER;
      if (yoffset > maxYOffset) {
        yoffset = maxYOffset;
      }
      for (int x = 0; x < subWidth; x++) {
        int xoffset = x << BLOCK_SIZE_POWER;
        if (xoffset > maxXOffset) {
          xoffset = maxXOffset;
        }
        int sum = 0;
        int min = 0xFF;
        int max = 0;
        for (int yy = 0, offset = yoffset * width + xoffset; yy < BLOCK_SIZE; yy++, offset += width) {
          for (int xx = 0; xx < BLOCK_SIZE; xx++) {
            int pixel = luminances[offset + xx] & 0xFF;
            sum += pixel;
            // still looking for good contrast
            if (pixel < min) {
              min = pixel;
            }
            if (pixel > max) {
              max = pixel;
            }
          }
          // short-circuit min/max tests once dynamic range is met
          if (max - min > MIN_DYNAMIC_RANGE) {
            // finish the rest of the rows quickly
            for (yy++, offset += width; yy < BLOCK_SIZE; yy++, offset += width) {
              for (int xx = 0; xx < BLOCK_SIZE; xx++) {
                sum += luminances[offset + xx] & 0xFF;
              }
            }
          }
        }

        // The default estimate is the average of the values in the block.
        int average = sum >> (BLOCK_SIZE_POWER * 2);
        if (max - min <= MIN_DYNAMIC_RANGE) {
          // If variation within the block is low, assume this is a block with only light or only
          // dark pixels. In that case we do not want to use the average, as it would divide this
          // low contrast area into black and white pixels, essentially creating data out of noise.
          //
          // The default assumption is that the block is light/background. Since no estimate for
          // the level of dark pixels exists locally, use half the min for the block.
          average = min / 2;

          if (y > 0 && x > 0) {
            // Correct the "white background" assumption for blocks that have neighbors by comparing
            // the pixels in this block to the previously calculated black points. This is based on
            // the fact that dark barcode symbology is always surrounded by some amount of light
            // background for which reasonable black point estimates were made. The bp estimated at
            // the boundaries is used for the interior.

            // The (min < bp) is arbitrary but works better than other heuristics that were tried.
            int averageNeighborBlackPoint =
                (blackPoints[y - 1][x] + (2 * blackPoints[y][x - 1]) + blackPoints[y - 1][x - 1]) / 4;
            if (min < averageNeighborBlackPoint) {
              average = averageNeighborBlackPoint;
            }
          }
        }
        blackPoints[y][x] = average;
      }
    }
    return blackPoints;
  }
812745
def _make_bright_pixel_mask(intensity_mean, mask_factor=5.0):
        
        mask = np.zeros((intensity_mean.data.shape), bool)
        nebins = len(intensity_mean.data)
        sum_intensity = intensity_mean.data.sum(0)
        mean_intensity = sum_intensity.mean()
        for i in range(nebins):
            mask[i, 0:] = sum_intensity > (mask_factor * mean_intensity)
        return HpxMap(mask, intensity_mean.hpx)
293934
public void setLightAttenuation(int i, float constant, float liner, float quadratic) {
		float c[] = { constant };
		float l[] = { liner };
		float q[] = { quadratic };
		gl.glEnable(GL2.GL_LIGHTING);
		gl.glEnable(GL2.GL_LIGHT0 + i);
		gl.glLightfv(GL2.GL_LIGHT0 + i, GL2.GL_CONSTANT_ATTENUATION, c, 0);
		gl.glLightfv(GL2.GL_LIGHT0 + i, GL2.GL_LINEAR_ATTENUATION, l, 0);
		gl.glLightfv(GL2.GL_LIGHT0 + i, GL2.GL_QUADRATIC_ATTENUATION, q, 0);
	}
157569
def _get_aeff_corrections(intensity_ratio, mask):
        
        nebins = len(intensity_ratio.data)
        aeff_corrections = np.zeros((nebins))
        for i in range(nebins):
            bright_pixels_intensity = intensity_ratio.data[i][mask.data[i]]
            mean_bright_pixel = bright_pixels_intensity.mean()
            aeff_corrections[i] = 1. / mean_bright_pixel

        print("Aeff correction: ", aeff_corrections)
        return aeff_corrections