Inserts a given {@code that} (B) into this matrix (A). The original
values are overwritten by the new ones.

@param that the matrix to insert, from the first row and column
@return a matrix with the parameter inserted into it
546142
public Matrix insert(Matrix that) {
        return insert(that, 0, 0, 0, 0, that.rows(), that.columns());
    }
1080216
public static Basic2DMatrix block(Matrix a, Matrix b, Matrix c, Matrix d) {
        if ((a.rows() != b.rows()) || (a.columns() != c.columns()) ||
            (c.rows() != d.rows()) || (b.columns() != d.columns())) {
            throw new IllegalArgumentException("Sides of blocks are incompatible!");
        }

        int rows = a.rows() + c.rows();
        int columns = a.columns() + b.columns();
        double[][] array = new double[rows][columns];

        for (int i = 0; i < rows; i++) {
            for (int j = 0; j < columns; j++) {
                if ((i < a.rows()) && (j < a.columns())) {
                    array[i][j] = a.get(i, j);
                }
                if ((i < a.rows()) && (j > a.columns())) {
                    array[i][j] = b.get(i, j);
                }
                if ((i > a.rows()) && (j < a.columns())) {
                    array[i][j] = c.get(i, j);
                }
                if ((i > a.rows()) && (j > a.columns())) {
                    array[i][j] = d.get(i, j);
                }
            }
        }

        return new Basic2DMatrix(array);
    }
573221
public SubstitutionMatrix<AminoAcidCompound> getSubstitutionMatrix() {
		if ( substitutionMatrix == null){
			substitutionMatrix = SubstitutionMatrixHelper.getMatrixFromAAINDEX(DEFAULT_SUBSTITUTION_MATRIX);

		}
		return substitutionMatrix;
	}
277697
public Matrix getIminus() {
        Matrix Iminus = new Matrix(size, size);
        int i, j;
        for (i = 0; i < size; i++)
            for (j = 0; j < size; j++)
                Iminus.matrix[i][j] = 0d;
        for (i = 1; i < size; i++)
            Iminus.matrix[i][i - 1] = Math.sqrt(J * J + J - (J - i) * (J - i) - (J - i));
        return Iminus;
    }
240913
public Matrix4 set (DoubleBuffer buf) {
        m00 = buf.get(); m01 = buf.get(); m02 = buf.get(); m03 = buf.get();
        m10 = buf.get(); m11 = buf.get(); m12 = buf.get(); m13 = buf.get();
        m20 = buf.get(); m21 = buf.get(); m22 = buf.get(); m23 = buf.get();
        m30 = buf.get(); m31 = buf.get(); m32 = buf.get(); m33 = buf.get();
        return this;
    }
425211
public Matrix4f set(Matrix4fc m) {
        if (m instanceof Matrix4f) {
            MemUtil.INSTANCE.copy((Matrix4f) m, this);
        } else {
            setMatrix4fc(m);
        }
        this._properties(m.properties());
        return this;
    }
1240852
public static void byRow(Matrix m) {
        for (int i = 0; i < m.rows(); ++i) {
            double rowSum = 0;
            for (int j = 0; j < m.columns(); ++j)
                rowSum += m.get(i,j);

            // Skip row whose sume is zero.
            if (rowSum == 0) 
                continue;
            for (int j = 0; j < m.columns(); ++j)
                m.set(i,j, m.get(i,j) / rowSum);
        }
    }
484086
public static <A, B> These<A, B> b(B b) {
        return new _B<>(b);
    }
557752
public static final DoubleMatrix1D add(DoubleMatrix1D v1, DoubleMatrix1D v2, double c){
		if(v1.size()!=v2.size()){
			throw new IllegalArgumentException("wrong vectors dimensions");
		}
		DoubleMatrix1D ret = DoubleFactory1D.dense.make(v1.size());
		for(int i=0; i<ret.size(); i++){
			ret.setQuick(i, v1.getQuick(i) + c*v2.getQuick(i));
		}

		return ret;
	}
925695
public static ImmutableMatrix identity(final int size) {
		if (size <= 0) throw new IllegalArgumentException("Invalid size");
		return create(new ImmutableData(size, size) {
			@Override
			public double getQuick(int row, int col) {
				return row == col ? 1 : 0;
			}
		});
	}
439845
public static SimpleMatrix convertSimple( DMatrixRBlock A ) {
        DMatrixRMaj B = ConvertDMatrixStruct.convert(A, null);

        return SimpleMatrix.wrap(B);
    }
1335331
public void insertIntoThis(int insertRow, int insertCol, T B) {
        convertType.specify(this,B);
        B = convertType.convert(B);

        // See if this type's need to be changed or not
        if( convertType.commonType == getType() ) {
            insert(B.mat,mat,insertRow,insertCol);
        } else {
            T A = convertType.convert(this);
            A.insert(B.mat,A.mat,insertRow,insertCol);
            setMatrix(A.mat);
        }
    }
895740
public static Basic1DMatrix from2DArray(double[][] array) {
        int rows = array.length;
        int columns = array[0].length;
        double[] array1D = new double[rows * columns];

        int offset = 0;
        for (int i = 0; i < rows; i++) {
            System.arraycopy(array[i], 0, array1D, offset, columns);
            offset += columns;
        }

        return new Basic1DMatrix(rows, columns, array1D);
    }
1067062
public Matrix times(Matrix B) {
        Matrix A = this;
        if (A.N != B.M) {
            throw new RuntimeException("Illegal matrix dimensions.");
        }
        Matrix C = new Matrix(A.M, B.N);
        for (int i = 0; i < C.M; i++) {
            for (int j = 0; j < C.N; j++) {
                for (int k = 0; k < A.N; k++) {
                    C.data[i][j] += A.data[i][k] * B.data[k][j];
                }
            }
        }
        return C;
    }
232948
public static function setColumn(array $matrix, $column, $value, $insertIfMissing = true, $overwrite = true)
    {
        // validate input
        if (self::countMinDepth($matrix) < 2) {
            throw new UnexpectedValueException('Can not set columns on one dimensional array');
        }
        if (!is_scalar($column)) {
            throw new InvalidArgumentException('Invalid column');
        }
        if (!is_bool($insertIfMissing)) {
            throw new InvalidArgumentException('Insert if missing indicator must be a boolean');
        }
        if (!is_bool($overwrite)) {
            throw new InvalidArgumentException('Overwrite indicator must be a boolean');
        }

        foreach ($matrix as $key => $row) {
            if (isset($row[$column]) || array_key_exists($column, $row)) {
                $matrix[$key][$column] = ($overwrite ? $value : $matrix[$key][$column]);
            } elseif ($insertIfMissing) {
                $matrix[$key][$column] = $value;
            }
        }

        return $matrix;
    }
368991
public Matrix3x2f set(Matrix3x2fc m) {
        if (m instanceof Matrix3x2f) {
            MemUtil.INSTANCE.copy((Matrix3x2f) m, this);
        } else {
            setMatrix3x2fc(m);
        }
        return this;
    }
263940
public void copyTo(Matrix other)
    {
        if (this.rows() != other.rows() || this.cols() != other.cols())
            throw new ArithmeticException("Matrices are not of the same dimension");
        for(int i = 0; i < rows(); i++)
            this.getRowView(i).copyTo(other.getRowView(i));
    }