This function combines two ranges of three values from the color array into a row.
18802
function appendColorRow( rangeA, rangeB )
			{
				for ( var i = rangeA ; i < rangeA + 3 ; i++ )
				{
					var row = table.$.insertRow( -1 );

					for ( var j = rangeB ; j < rangeB + 3 ; j++ )
					{
						for ( var n = 0 ; n < 6 ; n++ )
						{
							appendColorCell( row, '#' + aColors[j] + aColors[n] + aColors[i] );
						}
					}
				}
			}
642947
public static void concatRows(DMatrixRMaj a , DMatrixRMaj b , DMatrixRMaj output ) {
        int rows = a.numRows + b.numRows;
        int cols = Math.max(a.numCols , b.numCols);

        output.reshape(rows,cols);
        output.zero();

        insert(a,output,0,0);
        insert(b,output,a.numRows,0);
    }
459985
function(color1, color2, factor) {
		if (arguments.length < 3) { factor = 0.5; }
		var result = color1.slice();
		for (var i=0;i<3;i++) {
			result[i] = Math.round(result[i] + factor*(color2[i]-color1[i]));
		}
		return result;
	}
1266446
private static int mergeSameBuckets(double[] values, double[] weights, int nextIndex)
    {
        sort(values, weights, nextIndex);

        int current = 0;
        for (int i = 1; i < nextIndex; i++) {
            if (values[current] == values[i]) {
                weights[current] += weights[i];
            }
            else {
                current++;
                values[current] = values[i];
                weights[current] = weights[i];
            }
        }
        return current + 1;
    }
421707
def union(rasters):
    
    if sum([rasters[0].x_cell_size == i.x_cell_size for i in rasters]) == len(rasters) \
       and sum([rasters[0].y_cell_size == i.y_cell_size for i in rasters]) == len(rasters)\
       and sum([rasters[0].projection.ExportToProj4() == i.projection.ExportToProj4() for i in rasters]) == len(rasters):
        if sum([rasters[0].nodata_value == i.nodata_value for i in rasters]) == len(rasters):
            ndv = rasters[0].nodata_value
        else:
            ndv = np.nan
        if ndv == None:
            ndv = np.nan
        if sum([rasters[0].datatype == i.datatype for i in rasters]) == len(rasters):
            datatype = rasters[0].datatype
        else:
            datatype = None
        projection = rasters[0].projection
        lonmin = min([i.xmin for i in rasters])
        lonmax = max([i.xmax for i in rasters])
        latmin = min([i.ymin for i in rasters])
        latmax = max([i.ymax for i in rasters])
        shape = (np.abs(np.floor((latmax-latmin)/rasters[0].y_cell_size)).astype(int), np.floor((lonmax-lonmin)/rasters[0].x_cell_size).astype(int))
        out = ndv*np.ones(shape)
        outmask = np.ones(shape).astype(bool)
        for i in rasters:
            (row, col) = map_pixel(i.xmin, i.ymax, rasters[0].x_cell_size, rasters[0].y_cell_size, lonmin, latmax)
            out[row:row+i.shape[0], col:col+i.shape[1]] = np.where(i.raster.data != i.nodata_value, i.raster.data,\
                                                         out[row:row+i.shape[0], col:col+i.shape[1]])
            outmask[row:row+i.shape[0], col:col+i.shape[1]] = np.where(i.raster.mask == False, False,\
                                                         outmask[row:row+i.shape[0], col:col+i.shape[1]])
        out = np.ma.masked_array(out, mask=outmask, fill_value=ndv)
        return GeoRaster(out, (lonmin, rasters[0].x_cell_size, 0.0, latmax, 0.0, rasters[0].y_cell_size), nodata_value=ndv, projection=projection, datatype=datatype)
    else:
        raise RasterGeoError('Rasters need to have same pixel sizes. Use the aggregate or dissolve functions to generate correct GeoRasters')
1337316
function Fixed2DArray(rows, cols, defaultValue) {
  if(rows <= 0 || cols <= 0){
    throw new Error('fixed-2d-array: Must have more then 0 rows and 0 columns.');
  }

  this._width = cols;
  this._height = rows;
  this._grid = [];

  for (var i = 0; i < rows; i++) {
    this._grid[i] = [];
    for (var j = 0; j < cols; j++) {
      this._grid[i][j] = defaultValue;
    }
  }
}
1037486
function(startRow, endRow, startCol, endCol) {
            	var x = [];
            	
            	if(endRow == 0)
            	    endRow = this.rows();
            	
            	if(endCol == 0)
            	    endCol = this.cols();

            	for(i = startRow; i <= endRow; i++) {
            	    var row = [];

            	    for(j = startCol; j <= endCol; j++) {
            		row.push(this.e(i, j));
            	    }

            	    x.push(row);
            	}

            	return $M(x);
                }
1258580
function crop(data, rows, cols, nRows, nCols) {

    if (rows === nRows && cols === nCols) {
        //Do nothing. Returns the same input!!! Be careful
        return data;
    }

    var output = new Array(nCols * nRows);

    var shiftR = Math.floor((rows - nRows) / 2);
    var shiftC = Math.floor((cols - nCols) / 2);
    var destinyRow, sourceRow, i, j;
    for (i = 0; i < nRows; i++) {
        destinyRow = i * nCols;
        sourceRow = (i + shiftR) * cols;
        for (j = 0; j < nCols; j++) {
            output[destinyRow + j] = data[sourceRow + (j + shiftC)];
        }
    }

    return output;
}
863886
public static float[] getHSLArray(int r, int g, int b) {
        float[] hsl = new float[3];
        float h, s, l;

        float rf = r / MAX;
        float gf = g / MAX;
        float bf = b / MAX;

        float minRGB = Math.min(rf, Math.min(gf, bf));
        float maxRGB = Math.max(rf, Math.max(gf, bf));

        float delta = maxRGB - minRGB;

        l = (maxRGB + minRGB) / 2;

        if (delta == 0) {
            h = 0;
            s = 0.0f;
        } else {
            s = (l <= 0.5) ? (delta / (maxRGB + minRGB)) : (delta / (2 - maxRGB - minRGB));

            float hue;

            if (rf == maxRGB) {
                hue = ((gf - bf) / 6) / delta;
            } else if (gf == maxRGB) {
                hue = (1.0f / 3) + ((bf - rf) / 6) / delta;
            } else {
                hue = (2.0f / 3) + ((rf - gf) / 6) / delta;
            }

            if (hue < 0) {
                hue += 1;
            } else if (hue > 1) {
                hue -= 1;
            }

            h = (int) (hue * 360);
        }

        hsl[0] = h;
        hsl[1] = s;
        hsl[2] = l;

        return hsl;
    }
1170117
public static void multRows(double[] diag, int offset, DMatrixSparseCSC A) {
        if( diag.length < A.numRows )
            throw new IllegalArgumentException("Array is too small. "+diag.length+" < "+A.numCols);

        for (int i = 0; i < A.nz_length; i++) {
            A.nz_values[i] *= diag[A.nz_rows[i+offset]];
        }
    }
1125824
public static void multRows(double[] values, DMatrixRMaj A) {
        if( values.length < A.numRows ) {
            throw new IllegalArgumentException("Not enough elements in values.");
        }

        int index = 0;
        for (int row = 0; row < A.numRows; row++) {
            double v = values[row];
            for (int col = 0; col < A.numCols; col++, index++) {
                A.data[index] *= v;
            }
        }
    }
480595
public void setColorRange(int firstIndex, int lastIndex, int color1, int color2) {
		for (int i = firstIndex; i <= lastIndex; i++)
			map[i] = ImageMath.mixColors((float)(i-firstIndex)/(lastIndex-firstIndex), color1, color2);
	}
401311
function toColor(v1, v2, v3, v4, v5) {
    var _r, _g, _b, _a, R, G, B, rgb, options;
    if (v1 === undefined) {
        _r = _g = _b = 0;
        _a = 1;
    } else if (Array.isArray(v1)) {
        options = v2 || {};
        _r = v1[0] !== undefined ? v1[0] : 0;
        _g = v1[1] !== undefined ? v1[1] : 0;
        _b = v1[2] !== undefined ? v1[2] : 0;
        _a = v1[3] !== undefined ? v1[3] : options.base || 1;
    } else if (v1.r !== undefined) {
        options = v2 || {};
        _r = v1.r;
        _g = v1.g;
        _b = v1.b;
        _a = v1.a !== undefined ? v1.a : options.base || 1;
    } else if (typeof v1 === 'string') {
        if (v1.indexOf('#') === 0) {
            return v1;
        }
        if (v1.indexOf('rgb') === 0) {
            return v1;
        }
        if (colors.indexOf(v1) !== -1) {
            return v1;
        }
    } else if (typeof v1 === 'number') {
        if (arguments.length === 1) { // Grayscale value
            _r = _g = _b = v1;
            _a = 1;
        } else if (arguments.length === 2) { // Gray and alpha or options
            _r = _g = _b = v1;
            if (typeof v2 === 'number') {
                _a = v2;
            } else {
                options = v2;
                _a = options.base || 1;
            }
        } else if (arguments.length === 3) { // RGB or gray, alpha and options
            if (typeof v3 === 'number') {
                _r = v1;
                _g = v2;
                _b = v3;
                _a = 1;
            } else {
                _r = _g = _b = v1;
                _a = v2;
                options = v3;
            }
        } else if (arguments.length === 4) { // RGB and alpha or options
            _r = v1;
            _g = v2;
            _b = v3;
            if (typeof v4 === 'number') {
                _a = v4;
            } else {
                options = v4 || {};
                _a = options.base || 1;
            }
        } else { // RGBA + options
            _r = v1;
            _g = v2;
            _b = v3;
            _a = v4;
            options = v5;
        }
    }

    if (!(typeof _r === 'number' &&
        typeof _g === 'number' &&
        typeof _b === 'number' &&
        typeof _a === 'number')) {
        throw new Error('Invalid color arguments');
    }

    options = options || {};

    // The base option allows you to specify values in a different range.
    if (options.base !== undefined) {
        _r /= options.base;
        _g /= options.base;
        _b /= options.base;
        _a /= options.base;
    }
    R = Math.round(_r * 255);
    G = Math.round(_g * 255);
    B = Math.round(_b * 255);
    return 'rgba(' + R + ', ' + G + ', ' + B + ', ' + _a + ')';
}
729411
def convert_rgb_to_rgba(self, row, result):
        
        for i in range(len(row) // 3):
            for j in range(3):
                result[(4 * i) + j] = row[(3 * i) + j]
357066
protected function getRGBFromRange($r, $g, $b, $range) {
		#	get randomized rgb values on a specific range from a agiven value

		if (!$range) {
			return array($r, $g, $b);
		}

		$range = round($range / 2);
		$color = array();

		# red
		$min = $r - $range;
		$max = $r + $range;

		if ($min < 0) {
			$min = 0;
		}

		if ($max > 255) {
			$max = 255;
		}

		$color['r'] = $color[0] = rand($min, $max);

		# Green
		$min = $g - $range;
		$max = $g + $range;

		if ($min < 0) {
			$min = 0;
		}

		if ($max > 255) {
			$max = 255;
		}

		$color['g'] = $color[1] = rand($min, $max);

		# blue
		$min = $b - $range;
		$max = $b + $range;

		if ($min < 0) {
			$min = 0;
		}

		if ($max > 255) {
			$max = 255;
		}

		$color['b'] = $color[2] = rand($min, $max);

		return $color;
	}
366304
private Color getCellColour(double data, double min, double max) {
    double range = max - min;
    double position = data - min;

    // What proportion of the way through the possible values is that.
    double percentPosition = position / range;

    // Which colour group does that put us in.
    // int colourPosition = getColourPosition(percentPosition);

    int r = (int) (255 * red(percentPosition * 2 - 1));
    int g = (int) (255 * green(percentPosition * 2 - 1));
    int b = (int) (255 * blue(percentPosition * 2 - 1));

    // int r = lowValueColour.getRed();
    // int g = lowValueColour.getGreen();
    // int b = lowValueColour.getBlue();
    //
    // // Make n shifts of the colour, where n is the colourPosition.
    // for (int i = 0; i < colourPosition; i++) {
    // int rDistance = r - highValueColour.getRed();
    // int gDistance = g - highValueColour.getGreen();
    // int bDistance = b - highValueColour.getBlue();
    //
    // if ((Math.abs(rDistance) >= Math.abs(gDistance))
    // && (Math.abs(rDistance) >= Math.abs(bDistance))) {
    // // Red must be the largest.
    // r = changeColourValue(r, rDistance);
    // }
    // else if (Math.abs(gDistance) >= Math.abs(bDistance)) {
    // // Green must be the largest.
    // g = changeColourValue(g, gDistance);
    // }
    // else {
    // // Blue must be the largest.
    // b = changeColourValue(b, bDistance);
    // }
    // }

    return new Color(r, g, b);
  }
905416
private void sameValueMergeRows(MergeRow mergeRowAnn, int itemSize, Cell fromCell) {
        String lastValue = PoiUtil.getCellStringValue(fromCell);
        int preRow = fromCell.getRowIndex();
        val col = fromCell.getColumnIndex();
        int i = preRow + 1;

        for (final int ii = preRow + itemSize; i < ii; ++i) {
            val cell = sheet.getRow(i).getCell(col);
            val cellValue = PoiUtil.getCellStringValue(cell);
            if (StringUtils.equals(cellValue, lastValue)) continue;

            directMergeRows(mergeRowAnn, preRow, i - 1, col);
            lastValue = cellValue;
            preRow = i;
        }

        directMergeRows(mergeRowAnn, preRow, i - 1, col);
    }