Component-wise matrix subtraction: m1 = m1 - m2,
overwriting the existing matrix m1.

@param m1 Input matrix
@param m2 another matrix
@return m1 - m2, overwriting m1
341740
public static double[][] minusEquals(final double[][] m1, final double[][] m2) {
    final int columndimension = getColumnDimensionality(m1);
    assert getRowDimensionality(m1) == getRowDimensionality(m2) && columndimension == getColumnDimensionality(m2) : ERR_MATRIX_DIMENSIONS;
    for(int i = 0; i < m1.length; i++) {
      final double[] row1 = m1[i], row2 = m2[i];
      for(int j = 0; j < columndimension; j++) {
        row1[j] -= row2[j];
      }
    }
    return m1;
  }
379682
public static void transpose( DMatrix5x5 m ) {
        double tmp;
        tmp = m.a12; m.a12 = m.a21; m.a21 = tmp;
        tmp = m.a13; m.a13 = m.a31; m.a31 = tmp;
        tmp = m.a14; m.a14 = m.a41; m.a41 = tmp;
        tmp = m.a15; m.a15 = m.a51; m.a51 = tmp;
        tmp = m.a23; m.a23 = m.a32; m.a32 = tmp;
        tmp = m.a24; m.a24 = m.a42; m.a42 = tmp;
        tmp = m.a25; m.a25 = m.a52; m.a52 = tmp;
        tmp = m.a34; m.a34 = m.a43; m.a43 = tmp;
        tmp = m.a35; m.a35 = m.a53; m.a53 = tmp;
        tmp = m.a45; m.a45 = m.a54; m.a54 = tmp;
    }
870897
public static double[][] getMatrix(final double[][] m1, final int r0, final int r1, final int c0, final int c1) {
    assert r0 <= r1 && c0 <= c1 : ERR_INVALID_RANGE;
    assert r1 <= m1.length && c1 <= m1[0].length : ERR_MATRIX_DIMENSIONS;
    final int rowdim = r1 - r0, coldim = c1 - c0;
    final double[][] X = new double[rowdim][coldim];
    for(int i = r0; i < r1; i++) {
      System.arraycopy(m1[i], c0, X[i - r0], 0, coldim);
    }
    return X;
  }
956647
@Override
    public Matrix applyCommon(Matrix a, Matrix b) {
        int n = a.rows() * b.rows();
        int m = a.columns() * b.columns();
        int p = b.rows();
        int q = b.columns();

        Matrix result = a.blankOfShape(n, m);

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                result.set(i, j, a.get(i / p, j / q) * b.get(i % p, j % q));
            }
        }

        return result;
    }
552664
public static void transpose( DMatrix4x4 m ) {
        double tmp;
        tmp = m.a12; m.a12 = m.a21; m.a21 = tmp;
        tmp = m.a13; m.a13 = m.a31; m.a31 = tmp;
        tmp = m.a14; m.a14 = m.a41; m.a41 = tmp;
        tmp = m.a23; m.a23 = m.a32; m.a32 = tmp;
        tmp = m.a24; m.a24 = m.a42; m.a42 = tmp;
        tmp = m.a34; m.a34 = m.a43; m.a43 = tmp;
    }
1248634
public Matrix4d m22(double m22) {
        this.m22 = m22;
        properties &= ~PROPERTY_ORTHONORMAL;
        if (m22 != 1.0)
            properties &= ~(PROPERTY_IDENTITY | PROPERTY_TRANSLATION);
        return this;
    }
648075
public static double[][] transposeTimes(final double[][] m1, final double[][] m2) {
    final int rowdim1 = m1.length, coldim1 = getColumnDimensionality(m1);
    final int coldim2 = getColumnDimensionality(m2);
    assert m2.length == rowdim1 : ERR_MATRIX_INNERDIM;
    final double[][] re = new double[coldim1][coldim2];
    final double[] Bcolj = new double[rowdim1];
    for(int j = 0; j < coldim2; j++) {
      // Make a linear copy of column j from B
      for(int k = 0; k < rowdim1; k++) {
        Bcolj[k] = m2[k][j];
      }
      // multiply it with each row from A
      for(int i = 0; i < coldim1; i++) {
        double s = 0;
        for(int k = 0; k < rowdim1; k++) {
          s += m1[k][i] * Bcolj[k];
        }
        re[i][j] = s;
      }
    }
    return re;
  }
869655
public Matrix4x3d m21(double m21) {
        this.m21 = m21;
        properties &= ~PROPERTY_ORTHONORMAL;
        if (m21 != 0.0)
            properties &= ~(PROPERTY_IDENTITY | PROPERTY_TRANSLATION);
        return this;
    }
320991
public Matrix multiply(Matrix m) throws MatrixException
    {
        // Validate m's dimensions.
        if (nCols != m.nRows) {
            throw new MatrixException(
                                MatrixException.INVALID_DIMENSIONS);
        }

        double pv[][] = new double[nRows][m.nCols];  // product values

        // Compute values of the product.
        for (int r = 0; r < nRows; ++r) {
            for (int c = 0; c < m.nCols; ++c) {
                double dot = 0;
                for (int k = 0; k < nCols; ++k) {
                    dot += values[r][k] * m.values[k][c];
                }
                pv[r][c] = dot;
            }
        }

        return new Matrix(pv);
    }
421638
public Matrix4x3f m21(float m21) {
        this.m21 = m21;
        properties &= ~PROPERTY_ORTHONORMAL;
        if (m21 != 0.0f)
            properties &= ~(PROPERTY_IDENTITY | PROPERTY_TRANSLATION);
        return this;
    }
920441
public static double[][] appendColumns(final double[][] m1, final double[][] m2) {
    final int columndimension = getColumnDimensionality(m1);
    final int ccolumndimension = getColumnDimensionality(m2);
    assert m1.length == m2.length : "m.getRowDimension() != column.getRowDimension()";

    final int rcolumndimension = columndimension + ccolumndimension;
    final double[][] result = new double[m1.length][rcolumndimension];
    for(int i = 0; i < rcolumndimension; i++) {
      // FIXME: optimize - excess copying!
      if(i < columndimension) {
        setCol(result, i, getCol(m1, i));
      }
      else {
        setCol(result, i, getCol(m2, i - columndimension));
      }
    }
    return result;
  }
152214
def mult_matrix(m1, m0):
    (a1, b1, c1, d1, e1, f1) = m1
    (a0, b0, c0, d0, e0, f0) = m0
    """"""
    return (a0*a1+c0*b1,    b0*a1+d0*b1,
            a0*c1+c0*d1,    b0*c1+d0*d1,
            a0*e1+c0*f1+e0, b0*e1+d0*f1+f0)
985030
public static final double[] getZYZEuler(Matrix m) {
		double m22 = m.get(2,2);
		double rY = Math.toDegrees(Math.acos(m22));
		double rZ1, rZ2;
		if (m22 > .999d || m22 < -.999d) {
			rZ1 = Math.toDegrees(Math.atan2(m.get(1,0),  m.get(1,1)));
			rZ2 = 0;
		} else {
			rZ1 = Math.toDegrees(Math.atan2(m.get(2,1), -m.get(2,0)));
			rZ2 = Math.toDegrees(Math.atan2(m.get(1,2),  m.get(0,2)));
		}
		return new double[] {rZ1,rY,rZ2};
	}
1280143
public Matrix subtract(Matrix B)
    {
        Matrix toReturn = getThisSideMatrix(B);
        toReturn.mutableSubtract(1.0, B);
        return toReturn;
    }
470691
public Matrix subtract(double c)
    {
        Matrix toReturn = getThisSideMatrix(null);
        toReturn.mutableSubtract(c);
        return toReturn;
    }
623048
public Matrix mtimes(Matrix m2) {
		if (m2 instanceof DenseDoubleMatrix2D) {
			final DenseDoubleMatrix2D result = new BlockDenseDoubleMatrix2D((int) getRowCount(),
					(int) m2.getColumnCount(), layout.blockStripe, BlockOrder.ROWMAJOR);
			Mtimes.DENSEDOUBLEMATRIX2D.calc(this, (DenseDoubleMatrix2D) m2, result);
			return result;
		} else {
			return super.mtimes(m2);
		}
	}
491891
public static function mul(array $m1, array $m2): array
    {
        $res = [];
        foreach ($m1 as $i => $val) {
            $res[] = $val * $m2[$i];
        }

        return $res;
    }