コード例 #1
0
 public void testPlusDouble() throws Exception {
   Vector val = test.plus(1);
   assertEquals("size", test.size(), val.size());
   for (int i = 0; i < test.size(); i++) {
     if (i % 2 == 0) {
       assertEquals("get [" + i + ']', 1.0, val.get(i));
     } else {
       assertEquals("get [" + i + ']', values[i / 2] + 1.0, val.get(i));
     }
   }
 }
コード例 #2
0
 public void testDivideDouble() throws Exception {
   Vector val = test.divide(3);
   assertEquals("size", test.size(), val.size());
   for (int i = 0; i < test.size(); i++) {
     if (i % 2 == 0) {
       assertEquals("get [" + i + ']', 0.0, val.get(i));
     } else {
       assertEquals("get [" + i + ']', values[i / 2] / 3.0, val.get(i), EPSILON);
     }
   }
 }
コード例 #3
0
 public void testTimesVector() throws Exception {
   Vector val = test.times(test);
   assertEquals("size", test.size(), val.size());
   for (int i = 0; i < test.size(); i++) {
     if (i % 2 == 0) {
       assertEquals("get [" + i + ']', 0.0, val.get(i));
     } else {
       assertEquals("get [" + i + ']', values[i / 2] * values[i / 2], val.get(i));
     }
   }
 }
コード例 #4
0
  public void testMinus() throws Exception {
    Vector val = test.minus(test);
    assertEquals("size", test.size(), val.size());
    for (int i = 0; i < test.size(); i++) {
      assertEquals("get [" + i + ']', 0.0, val.get(i));
    }

    val = test.minus(test).minus(test);
    assertEquals("cardinality", test.size(), val.size());
    for (int i = 0; i < test.size(); i++) {
      assertEquals("get [" + i + ']', 0.0, val.get(i) + test.get(i));
    }

    Vector val1 = test.plus(1);
    val = val1.minus(test);
    for (int i = 0; i < test.size(); i++) {
      assertEquals("get [" + i + ']', 1.0, val.get(i));
    }

    val1 = test.plus(-1);
    val = val1.minus(test);
    for (int i = 0; i < test.size(); i++) {
      assertEquals("get [" + i + ']', -1.0, val.get(i));
    }
  }
コード例 #5
0
 public void testAssignDoubleArray() throws Exception {
   double[] array = new double[test.size()];
   test.assign(array);
   for (int i = 0; i < values.length; i++) {
     assertEquals("value[" + i + ']', 0.0, test.getQuick(i));
   }
 }
コード例 #6
0
 public void testAssignVector() throws Exception {
   Vector other = new DenseVector(test.size());
   test.assign(other);
   for (int i = 0; i < values.length; i++) {
     assertEquals("value[" + i + ']', 0.0, test.getQuick(i));
   }
 }
コード例 #7
0
 public void testSparseDoubleVectorInt() throws Exception {
   Vector val = new RandomAccessSparseVector(4);
   assertEquals("size", 4, val.size());
   for (int i = 0; i < 4; i++) {
     assertEquals("get [" + i + ']', 0.0, val.get(i));
   }
 }
コード例 #8
0
 public void testViewPart() throws Exception {
   Vector part = test.viewPart(1, 2);
   assertEquals("part size", 2, part.getNumNondefaultElements());
   for (int i = 0; i < part.size(); i++) {
     assertEquals("part[" + i + ']', test.get(i + 1), part.get(i));
   }
 }
コード例 #9
0
 public void testTimesVectorCardinality() {
   try {
     test.times(new DenseVector(test.size() + 1));
     fail("expected exception");
   } catch (CardinalityException e) {
   }
 }
コード例 #10
0
 public void testGetOver() {
   try {
     test.get(test.size());
     fail("expected exception");
   } catch (IndexException e) {
   }
 }
コード例 #11
0
 public void testAssignDoubleArrayCardinality() {
   double[] array = new double[test.size() + 1];
   try {
     test.assign(array);
     fail("cardinality exception expected");
   } catch (CardinalityException e) {
   }
 }
コード例 #12
0
 public void testAssignVectorCardinality() {
   Vector other = new DenseVector(test.size() - 1);
   try {
     test.assign(other);
     fail("cardinality exception expected");
   } catch (CardinalityException e) {
   }
 }
コード例 #13
0
 public void testGet() throws Exception {
   for (int i = 0; i < test.size(); i++) {
     if (i % 2 == 0) {
       assertEquals("get [" + i + ']', 0.0, test.get(i));
     } else {
       assertEquals("get [" + i + ']', values[i / 2], test.get(i));
     }
   }
 }
コード例 #14
0
 public void testNormalize() throws Exception {
   Vector val = test.normalize();
   double mag = Math.sqrt(1.1 * 1.1 + 2.2 * 2.2 + 3.3 * 3.3);
   for (int i = 0; i < test.size(); i++) {
     if (i % 2 == 0) {
       assertEquals("get [" + i + ']', 0.0, val.get(i));
     } else {
       assertEquals("dot", values[i / 2] / mag, val.get(i));
     }
   }
 }
コード例 #15
0
 public void testGetDistanceSquared() {
   Vector other = new RandomAccessSparseVector(test.size());
   other.set(1, -2);
   other.set(2, -5);
   other.set(3, -9);
   other.set(4, 1);
   double expected = test.minus(other).getLengthSquared();
   assertTrue(
       "a.getDistanceSquared(b) != a.minus(b).getLengthSquared",
       Math.abs(expected - test.getDistanceSquared(other)) < 10.0E-7);
 }
コード例 #16
0
 public void testSet() throws Exception {
   test.set(3, 4.5);
   for (int i = 0; i < test.size(); i++) {
     if (i % 2 == 0) {
       assertEquals("get [" + i + ']', 0.0, test.get(i));
     } else if (i == 3) {
       assertEquals("set [" + i + ']', 4.5, test.get(i));
     } else {
       assertEquals("set [" + i + ']', values[i / 2], test.get(i));
     }
   }
 }
コード例 #17
0
 public void testCrossProduct() {
   Matrix result = test.cross(test);
   assertEquals("row size", test.size(), result.size()[0]);
   assertEquals("col size", test.size(), result.size()[1]);
   for (int row = 0; row < result.size()[0]; row++) {
     for (int col = 0; col < result.size()[1]; col++) {
       assertEquals(
           "cross[" + row + "][" + col + ']',
           test.getQuick(row) * test.getQuick(col),
           result.getQuick(row, col));
     }
   }
 }
コード例 #18
0
 public void testLike() {
   Vector other = test.like();
   assertTrue("not like", test.getClass().isAssignableFrom(other.getClass()));
   assertEquals("size", test.size(), other.size());
 }
コード例 #19
0
 public void testDecodeVector() throws Exception {
   Vector val = AbstractVector.decodeVector(test.asFormatString());
   for (int i = 0; i < test.size(); i++) {
     assertEquals("get [" + i + ']', test.get(i), val.get(i));
   }
 }
コード例 #20
0
 public void testCardinality() {
   assertEquals("size", 7, test.size());
 }
コード例 #21
0
 public void testCopy() throws Exception {
   Vector copy = test.clone();
   for (int i = 0; i < test.size(); i++) {
     assertEquals("copy [" + i + ']', test.get(i), copy.get(i));
   }
 }