@Test
public void testcopy() {

    Matrix M = new Matrix(11, 10);
    M.randomize();
    boolean[] rsel = new boolean[M.getRowsCount()];
    boolean[] csel = new boolean[M.getColumnsCount()];
    for (int i = 0; i < rsel.length; ++i) {
        if (i % 3 == 0) {
            rsel[i] = true;
        }
    }
    for (int i = 0; i < csel.length; ++i) {
        if (i % 2 == 0) {
            csel[i] = true;
        }
    }
    Matrix M2 = M.clone();
    int[] irsel = new int[]{1, 2, 3, 5};
    int[] icsel = new int[]{1, 3, 5, 8};
    Matrix mr = Matrix.selectRows(M.subMatrix(), rsel);
    M2.subMatrix().copyRows(mr.subMatrix(), rsel);
    assertTrue(M2.equals(M));
    Matrix mc = Matrix.selectColumns(M.subMatrix(), csel);
    M2.subMatrix().copyColumns(mc.subMatrix(), csel);
    assertTrue(M2.equals(M));
    Matrix m = Matrix.select(M.subMatrix(), rsel, csel);
    M2.subMatrix().copy(m.subMatrix(), rsel, csel);
    assertTrue(M2.equals(M));
    mr = Matrix.selectRows(M.subMatrix(), irsel);
    M2.subMatrix().copyRows(mr.subMatrix(), irsel);
    assertTrue(M2.equals(M));
    mc = Matrix.selectColumns(M.subMatrix(), icsel);
    M2.subMatrix().copyColumns(mc.subMatrix(), icsel);
    assertTrue(M2.equals(M));
    m = Matrix.select(M.subMatrix(), irsel, icsel);
    M2.subMatrix().copy(m.subMatrix(), irsel, icsel);
    assertTrue(M2.equals(M));
}