コード例 #1
0
  @Override
  public Vector apply(SparseVector a, SparseVector b) {
    VectorIterator these = a.nonZeroIterator();
    VectorIterator those = b.nonZeroIterator();
    VectorIterator both = these.orElseSubtract(those);

    return both.toVector(factory);
  }
コード例 #2
0
 @Override
 public Vector apply(DenseVector a, SparseVector b) {
   Vector result = a.copy(factory);
   VectorIterator it = b.nonZeroIterator();
   while (it.hasNext()) {
     it.next();
     result.update(it.index(), Vectors.asMinusFunction(it.get()));
   }
   return result;
 }
コード例 #3
0
 @Override
 public Vector apply(SparseVector a, DenseVector b) {
   Vector result = b.multiply(-1.0, factory);
   VectorIterator it = a.nonZeroIterator();
   while (it.hasNext()) {
     it.next();
     result.update(it.index(), Vectors.asPlusFunction(it.get()));
   }
   return result;
 }