@Test
  public void testBug27() {
    double[] tfVector = {0.0, 0.5, 0.0, 0.4, 0.0};
    DenseVector dense = new DenseVector(tfVector, false);
    SparseVector vectorTF = new SparseVector(dense);
    vectorTF.compact();

    assertTrue(vectorTF.getUsed() == 2); // vectorTF.getUsed() returns 5

    for (Iterator<VectorEntry> it = vectorTF.iterator(); it.hasNext(); ) {
      VectorEntry ve = it.next();
      int index = ve.index();
      double value = ve.get();
      assertTrue(tfVector[index] == value);
    }
  }
  @Test
  public void testGetRawData() {
    SparseVector vector = new SparseVector(Integer.MAX_VALUE);
    double[] data = vector.getRawData();
    assertTrue(data != null);
    assertTrue(data.length == 0);
    assertSame(data, vector.data);
    assertEquals(data.length, vector.getRawIndex().length);

    vector.set(2, 1.0);
    vector.set(1, 0.0);
    vector.set(4, 2.0);

    data = vector.getRawData();
    assertSame(data, vector.data);
    assertEquals(data.length, vector.getRawIndex().length);

    // In this case, the raw index is larger than the used, so the raw
    // indices have more entries than the other one.
    assertTrue(data.length > vector.getUsed());
    assertTrue(data.length > vector.getIndex().length);
  }
  @Override
  public Vector transMultAdd(double alpha, Vector x, Vector y) {
    if (!(x instanceof DenseVector) || !(y instanceof DenseVector))
      return super.transMultAdd(alpha, x, y);

    checkTransMultAdd(x, y);

    double[] xd = ((DenseVector) x).getData(), yd = ((DenseVector) y).getData();

    // y = 1/alpha * y
    y.scale(1. / alpha);

    // y = A'x + y
    for (int i = 0; i < numRows; ++i) {
      SparseVector v = rowD[i];
      int[] index = v.getIndex();
      double[] data = v.getData();
      int length = v.getUsed();
      for (int j = 0; j < length; ++j) yd[index[j]] += data[j] * xd[i];
    }

    // y = alpha*y = alpha * A'x + y
    return y.scale(alpha);
  }