@Override
    public DenseMatrix matrixMultiply(Matrix other) {
        if (dim2 == other.getDimension1Size()) {
            if (other instanceof DenseMatrix) {
                DenseMatrix otherDense = (DenseMatrix) other;
                double[][] output = new double[dim1][otherDense.dim2];

                for (int i = 0; i < dim1; i++) {
                    for (int j = 0; j < otherDense.dim2; j++) {
                        output[i][j] = columnRowDot(i,j,otherDense);
                    }
                }

                return new DenseMatrix(output);
            } else if (other instanceof DenseSparseMatrix) {
                DenseSparseMatrix otherSparse = (DenseSparseMatrix) other;
                int otherDim2 = otherSparse.getDimension2Size();
                double[][] output = new double[dim1][otherDim2];

                for (int i = 0; i < dim1; i++) {
                    for (int j = 0; j < otherDim2; j++) {
                        output[i][j] = columnRowDot(i,j,otherSparse);
                    }
                }

                return new DenseMatrix(output);
            } else {
                throw new IllegalArgumentException("Unknown matrix type " + other.getClass().getName());
            }
        } else {
            throw new IllegalArgumentException("Invalid matrix dimensions, this.shape=" + Arrays.toString(shape) + ", other.shape = " + Arrays.toString(other.getShape()));
        }
    }
@Test
    public void matrixMatrixThisTransposeTest() {
        //4x4 matrices
        DenseMatrix a = generateA();
        DenseMatrix b = generateB();
        DenseMatrix c = generateC();

        DenseMatrix aTa = generateATA();
        assertEquals(aTa,a.matrixMultiply(a,true,false));
        DenseMatrix aTb = generateATB();
        assertEquals(aTb,a.matrixMultiply(b,true,false));
        DenseMatrix aTc = generateATC();
        assertEquals(aTc,a.matrixMultiply(c,true,false));

        DenseMatrix bTa = generateBTA();
        assertEquals(bTa,b.matrixMultiply(a,true,false));
        DenseMatrix bTb = generateBTB();
        assertEquals(bTb,b.matrixMultiply(b,true,false));
        DenseMatrix bTc = generateBTC();
        assertEquals(bTc,b.matrixMultiply(c,true,false));

        DenseMatrix cTa = generateCTA();
        assertEquals(cTa,c.matrixMultiply(a,true,false));
        DenseMatrix cTb = generateCTB();
        assertEquals(cTb,c.matrixMultiply(b,true,false));
        DenseMatrix cTc = generateCTC();
        assertEquals(cTc,c.matrixMultiply(c,true,false));
    }