Add a factor times one column to another column

@param matrix
the matrix to modify
@param diag
coordinate on the diagonal
@param fromRow
first row to process
@param col
column to process
@param factor
factor to multiply
350775
public static void addColTimes(double[][] matrix, int diag, int fromRow, int col, double factor) {
		int rows = matrix.length;
		double[] r = null;
		for (int row = fromRow; row < rows; row++) {
			r = matrix[row];
			r[col] -= factor * r[diag];
		}
	}
43160
public static void insertColumn(DMatrixRMaj P, int col, GeoTuple3D_F64 a) {
		P.unsafe_set(0,col,a.x);
		P.unsafe_set(1,col,a.y);
		P.unsafe_set(2,col,a.z);
	}
429423
public static void diag( DMatrix5x5 input , DMatrix5 out ) {
        out.a1 = input.a11;
        out.a2 = input.a22;
        out.a3 = input.a33;
        out.a4 = input.a44;
        out.a5 = input.a55;
    }
1145792
public static void multRow(Matrix A, int i, double c)
    {
        multRow(A, i, 0, A.cols(), c);
    }
74443
public static Matrix createMatrix(int rowCount, int colCount) {
		if (rowCount<=0 || colCount<=0) throw new IllegalArgumentException();
		if (colCount==1)
			return createVector(rowCount);
		else if (rowCount==2 && colCount==2)
			return createMatrix2();
		else if (rowCount==3 && colCount==3)
			return createMatrix3();
		else
			return new MatrixImpl(rowCount, colCount);
	}
395984
public double[] getColumn(int col) {
    double[] column = new double[numRows];
    int offset = translate(0, col, numRows);
    for (int i = 0; i < column.length; i++) {
      column[i] = matrix[offset + i];
    }
    return column;
  }
123512
public static Matrix diag(Vec a)
    {
        DenseMatrix A = new DenseMatrix(a.length(), a.length());
        for(Iterator<IndexValue> iter = a.getNonZeroIterator(); iter.hasNext();)
        {
            IndexValue iv = iter.next();
            A.set(iv.getIndex(), iv.getIndex(), iv.getValue());
        }
            
        return A;
    }
925732
private static function getCofactors(Matrix $matrix)
    {
        $cofactors = self::getMinors($matrix);
        $dimensions = $matrix->rows;

        $cof = 1;
        for ($i = 0; $i < $dimensions; ++$i) {
            $cofs = $cof;
            for ($j = 0; $j < $dimensions; ++$j) {
                $cofactors[$i][$j] *= $cofs;
                $cofs = -$cofs;
            }
            $cof = -$cof;
        }

        return new Matrix($cofactors);
    }
912904
public static void multRow(Matrix A, int i, double[] c)
    {
        if(A.cols() != c.length)
            throw new ArithmeticException("Can not perform row update, length miss match " + A.cols() + " and " + c.length);
        multRow(A, i, 0, c.length, c);
    }
1056318
public static double varianceDoublematrixColumn( double[][] matrix, int column, double mean )

    {

        double variance;

        variance = 0;

        for( int i = 0; i < matrix.length; i++ ) {
            variance += (matrix[i][column] - mean) * (matrix[i][column] - mean);
        }

        return variance / matrix.length;

    }
1357969
def _matrix_add_column(matrix, column, default=0):
    
    height_difference = len(column) - len(matrix)

    # The width of the matrix is the length of its longest row.
    width = max(len(row) for row in matrix) if matrix else 0

    # For now our offset is 0. We may need to shift our column down later.
    offset = 0

    # If we need extra rows, add them to the top of the matrix.
    if height_difference > 0:
        for _ in range(height_difference):
            matrix.insert(0, [default] * width)

    # If the column is shorter, we'll need to shift it down.
    if height_difference < 0:
        offset = -height_difference
        #column = ([default] * offset) + column

    for index, value in enumerate(column):
        # The row index is the index in the column plus our offset.
        row_index = index + offset
        row = matrix[row_index]

        # If this row is short, pad it with default values.
        width_difference = width - len(row)
        row.extend([default] * width_difference)

        row.append(value)
386399
public Matrix3f set(Vector3fc col0, Vector3fc col1, Vector3fc col2) {
        if (col0 instanceof Vector3f &&
            col1 instanceof Vector3f &&
            col2 instanceof Vector3f) {
            MemUtil.INSTANCE.set(this, (Vector3f) col0, (Vector3f) col1, (Vector3f) col2);
        } else {
            setVector3fc(col0, col1, col2);
        }
        return this;
    }
233649
public void makeReferences(CellRow row, CellCol col, CellSqr sqr) {
        this.cellRow = row;
        this.cellCol = col;
        this.cellSqr = sqr;
        this.exCells = new HashSet<Cell>();
        this.exCells.addAll(this.cellRow.getCells());
        this.exCells.addAll(this.cellCol.getCells());
        this.exCells.addAll(this.cellSqr.getCells());
        this.exCells.remove(this);
    }
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]];
        }
    }
533367
public static void mult( double a[] , int offsetA ,
                             DMatrixSparseCSC B ,
                             double c[] , int offsetC )
    {
        if( a.length-offsetA < B.numRows)
            throw new IllegalArgumentException("Length of 'a' isn't long enough");
        if( c.length-offsetC < B.numCols)
            throw new IllegalArgumentException("Length of 'c' isn't long enough");

        for (int k = 0; k < B.numCols; k++) {
            int idx0 = B.col_idx[k  ];
            int idx1 = B.col_idx[k+1];

            double sum = 0;
            for (int indexB = idx0; indexB < idx1; indexB++) {
                sum += a[offsetA+B.nz_rows[indexB]]*B.nz_values[indexB];
            }
            c[offsetC+k] = sum;
        }
    }
367879
public void multT(DoubleMatrix bMat, DoubleMatrix cMat, boolean transposeA, boolean transposeB) {
        if (!transposeA) {            
            throw new IllegalArgumentException("Multiplication where this matrix NOT transposed is not implemented.");
        }
        
        SparseRowDoubleMatrix.checkMultDimensions(this.viewTranspose(), transposeB ? bMat.viewTranspose() : bMat, cMat);

        int numRowsC = cMat.getNumRows();
        int numColsC = cMat.getNumColumns();
        
        if (bMat instanceof DenseDoubleMatrix) {
            DenseDoubleMatrix denseBMat = (DenseDoubleMatrix) bMat;
            for (int row = 0; row < numRowsC; row++) {
                for (int col = 0; col < numColsC; col++) {
                    if (transposeB) {
                        cMat.set(row, col, this.cols[row].dot(denseBMat.matrix[col]));
                    } else {
                        cMat.set(row, col, this.cols[row].dot(denseBMat.matrix, col));
                    }
                }
            }
        } else if (bMat instanceof SparseColDoubleMatrix && !transposeB) {
            SparseColDoubleMatrix sparseBMat = (SparseColDoubleMatrix) bMat;
            for (int row = 0; row < numRowsC; row++) {
                for (int col = 0; col < numColsC; col++) {
                    cMat.set(row, col, this.cols[row].dot(sparseBMat.cols[col]));
                }
            }
        } else if (bMat instanceof SparseRowDoubleMatrix && transposeB) {
            SparseRowDoubleMatrix sparseBMat = (SparseRowDoubleMatrix) bMat;
            for (int row = 0; row < numRowsC; row++) {
                for (int col = 0; col < numColsC; col++) {
                    cMat.set(row, col, this.cols[row].dot(sparseBMat.rows[col]));
                }
            }
        } else {
            throw new IllegalArgumentException("unhandled type: " + bMat.getClass().getCanonicalName());
        }
    }
40383
public void copyFactor(DDF ddf, List<String> columns)  throws DDFException {

    // if there is no columns to recompute factor info
    if (columns == null) {
      columns = new ArrayList<String>();
    }

    for (Schema.Column col : ddf.getSchema().getColumns()) {
      if (this.getDDF().getColumn(col.getName()) != null && col.getColumnClass() == Schema.ColumnClass.FACTOR) {
        // Set corresponding column as factor
        this.getDDF().getSchemaHandler().setAsFactor(col.getName());
        // if not in list of columns to re-compute factors
        // then we just copy existing factor info to the new ones
        if (!columns.contains(col.getName())) {
          // copy existing factor column info
          this.getDDF().getSchemaHandler().setFactorLevels(col.getName(), col.getOptionalFactor());
        }
      }
    }
    this.getDDF().getSchemaHandler().computeFactorLevelsAndLevelCounts();
  }