@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 matrixMultiplyTest() {
        //4x4 matrices
        DenseMatrix a = generateA();
        DenseMatrix b = generateB();
        DenseMatrix c = generateC();

        //4x7 matrix
        DenseMatrix d = generateD();

        //7x3 matrix
        DenseMatrix e = generateE();

        //3x4 matrix
        DenseMatrix f = generateF();

        //4x7 output
        DenseMatrix ad = generateAD();
        assertEquals(ad,a.matrixMultiply(d));
        DenseMatrix bd = generateBD();
        assertEquals(bd,b.matrixMultiply(d));
        DenseMatrix cd = generateCD();
        assertEquals(cd,c.matrixMultiply(d));

        //3x4 output
        DenseMatrix fa = generateFA();
        assertEquals(fa,f.matrixMultiply(a));
        DenseMatrix fb = generateFB();
        assertEquals(fb,f.matrixMultiply(b));
        DenseMatrix fc = generateFC();
        assertEquals(fc,f.matrixMultiply(c));

        //4x3 output
        DenseMatrix de = generateDE();
        assertEquals(de,d.matrixMultiply(e));

        //3x7 output
        DenseMatrix fd = generateFD();
        assertEquals(fd,f.matrixMultiply(d));

        //7x4 output
        DenseMatrix ef = generateEF();
        assertEquals(ef,e.matrixMultiply(f));

        //4x4 output
        DenseMatrix def = generateDEF();
        assertEquals(def,d.matrixMultiply(e).matrixMultiply(f));
    }