@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); }
@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; }
@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; }