public boolean eq(Matrix B) {
        Matrix A = this;
        boolean isEqual = false;
        if (B.M != A.M || B.N != A.N) throw new RuntimeException("Illegal matrix dimensions.");
        for (int i = 0; i < M; i++)
            for (int j = 0; j < N; j++)
                isEqual = A.data[i][j] == B.data[i][j];
        return isEqual;
    }