public BigMatrix submatrix(int i, int j, int k, int l) {
        if (i < 0 || i >= m || k < i || k >= m || j < 0 || j >= n || l < j || l >= n) {
            throw new IllegalArgumentException(String.format("Invalid submatrix range (%d:%d, %d:%d) of %d x %d", i, k, j, l, m, n));
        }

        long offset = index(i, j);
        long length = index(k, l) - offset + 1;
        DoublePointer B = A.getPointer(offset).limit(length);

        if (layout() == COL_MAJOR) {
            return new BigMatrix(k - i + 1, l - j + 1, ld, B);
        } else {
            return new RowMajor(k - i + 1, l - j + 1, ld, B);
        }
    }
@Test
    public void testSubmatrix() {
        BigMatrix sub = matrix.submatrix(0, 1, 2, 2);
        System.out.println(matrix);
        System.out.println(sub);
        assertEquals(3, sub.nrow());
        assertEquals(2, sub.ncol());
        assertEquals(0.4, sub.get(0,0), 1E-7);
        assertEquals(0.8, sub.get(2,1), 1E-7);

        BigMatrix sub2 = sub.submatrix(0, 0, 1, 1);
        assertEquals(2, sub2.nrow());
        assertEquals(2, sub2.ncol());
        assertEquals(0.4, sub.get(0,0), 1E-7);
        assertEquals(0.3, sub.get(1,1), 1E-7);
    }