@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 identityTest() {
        DenseMatrix a = generateA();
        DenseMatrix b = generateB();
        DenseMatrix c = generateC();
        DenseMatrix d = generateD();
        DenseMatrix e = generateE();
        DenseMatrix f = generateF();
        DenseMatrix eye = identity(10);
        DenseMatrix eye4 = identity(4);
        DenseMatrix eye3 = identity(3);
        DenseMatrix eye7 = identity(7);

        // Identity matrix tests
        assertEquals(eye,eye.matrixMultiply(eye));
        assertEquals(eye4,eye4.matrixMultiply(eye4));
        assertEquals(eye3,eye3.matrixMultiply(eye3));
        assertEquals(eye7,eye7.matrixMultiply(eye7));

        // 4x4 tests
        assertEquals(a,a.matrixMultiply(eye4));
        assertEquals(b,b.matrixMultiply(eye4));
        assertEquals(c,c.matrixMultiply(eye4));
        assertEquals(a,eye4.matrixMultiply(a));
        assertEquals(b,eye4.matrixMultiply(b));
        assertEquals(c,eye4.matrixMultiply(c));

        // 4x7 tests
        assertEquals(d,d.matrixMultiply(eye7));
        assertEquals(d,eye4.matrixMultiply(d));

        // 7x3 tests
        assertEquals(e,e.matrixMultiply(eye3));
        assertEquals(e,eye7.matrixMultiply(e));

        // 3x4 tests
        assertEquals(f,f.matrixMultiply(eye4));
        assertEquals(f,eye3.matrixMultiply(f));
    }