@Test
public void testSetData() throws IOException {

  File f = File.createTempFile("matrix", ".m");
  f.deleteOnExit();
  Random gen = RandomUtils.getRandom();
  Matrix m0 = new SparseRowMatrix(10, 21);
  for (MatrixSlice row : m0) {
    int len = (int) Math.ceil(-15 * Math.log(1 - gen.nextDouble()));
    for (int i = 0; i < len; i++) {
      row.vector().set(gen.nextInt(21), 1);
    }
  }
  FileBasedSparseBinaryMatrix.writeMatrix(f, m0);
  FileBasedSparseBinaryMatrix m = new FileBasedSparseBinaryMatrix(10, 21);
  m.setData(f);
  for (MatrixSlice row : m) {
    Vector diff = row.vector().minus(m0.viewRow(row.index()));
    double error = diff.norm(1);
    if (error > 1.0e-14) {
      System.out.printf("%s\n", diff);
    }
    assertEquals(0, error, 1.0e-14);
  }
}