Ejemplo n.º 1
0
  @Test
  public void testSparseListMatrix() {
    List<SparseDoubleVector> vectors = new ArrayList<SparseDoubleVector>();
    for (double[] values : VALUES) vectors.add(new CompactSparseVector(values));
    Matrix m = new ListMatrix<SparseDoubleVector>(vectors);
    assertEquals(VALUES.length, m.rows());
    assertEquals(VALUES[0].length, m.columns());
    for (int r = 0; r < m.rows(); ++r)
      for (int c = 0; c < m.columns(); ++c) assertEquals(VALUES[r][c], m.get(r, c), .0001);

    m.set(0, 0, 0);
    assertEquals(0, vectors.get(0).get(0), .0001);

    for (int r = 0; r < m.rows(); ++r) assertEquals(vectors.get(r), m.getRowVector(r));
  }
Ejemplo n.º 2
0
 public static void testSet(Matrix m) {
   int rows = m.rows();
   int cols = m.columns();
   for (int trials = 0; trials < 100; ++trials) {
     int i = (int) (rows * Math.random());
     int j = (int) (cols * Math.random());
     double v = Math.random();
     m.set(i, j, v);
     assertEquals(v, m.get(i, j), 0.01);
   }
 }