コード例 #1
0
  public void testCreateUniformRandom_Diagonal() {
    System.out.println("createUniformRandom");

    int M = random.nextInt(10) + 1;
    int N = M + 1;
    DiagonalMatrixFactoryMTJ factory = this.createFactory();
    try {
      factory.createUniformRandom(M, N, -RANGE, RANGE, random);
      fail("Cannot create non-suare matrix");
    } catch (Exception e) {
      System.out.println("Good: " + e);
    }

    DiagonalMatrixMTJ m = factory.createUniformRandom(M, M, -RANGE, RANGE, random);
    assertNotNull(m);
    assertEquals(M, m.getDimensionality());
    for (int i = 0; i < M; i++) {
      for (int j = 0; j < M; j++) {
        double v = m.getElement(i, j);
        if (i == j) {
          assertTrue(-RANGE <= v);
          assertTrue(v <= RANGE);
        } else {
          assertEquals(0.0, v);
        }
      }
    }
  }
コード例 #2
0
 /** Test of createMatrix method, of class DiagonalMatrixFactoryMTJ. */
 public void testCreateMatrix_int() {
   System.out.println("createMatrix");
   DiagonalMatrixFactoryMTJ instance = this.createFactory();
   int M = random.nextInt(10) + 1;
   DiagonalMatrixMTJ result = instance.createMatrix(M);
   assertNotNull(result);
   assertEquals(M, result.getDimensionality());
 }
コード例 #3
0
 /** Test of diagonalValues method, of class DiagonalMatrixFactoryMTJ. */
 public void testDiagonalValues() {
   System.out.println("diagonalValues");
   double[] diagonal = {random.nextGaussian(), random.nextGaussian(), random.nextGaussian()};
   DiagonalMatrixFactoryMTJ instance = this.createFactory();
   DiagonalMatrixMTJ result = instance.diagonalValues(diagonal);
   assertEquals(diagonal.length, result.getDimensionality());
   for (int i = 0; i < diagonal.length; i++) {
     assertEquals(diagonal[i], result.getElement(i));
   }
 }