public abstract class VectorBinaryAssign
Abstract class encapsulating different algorithms that perform the Vector operations assign().
x.assign(y, f), for x and y Vectors and f a DoubleDouble function:
- applies the function f to every element in x and y, f(xi, yi)
- assigns xi = f(xi, yi) for all indices i
The names of variables, methods and classes used here follow the following conventions:
The vector being assigned to (the left hand side) is called this or x.
The right hand side is called that or y.
The function to be applied is called f.
The different algorithms take into account the different characteristics of vector classes:
- whether the vectors support sequential iteration (isSequential())
- whether the vectors support constant-time additions (isAddConstantTime())
- what the lookup cost is (getLookupCost())
- what the iterator advancement cost is (getIteratorAdvanceCost())
The names of the actual classes (they're nested in VectorBinaryAssign) describe the used for assignment.
The most important optimization is iterating just through the nonzeros (only possible if f(0, 0) = 0).
There are 4 main possibilities:
- iterating through the nonzeros of just one vector and looking up the corresponding elements in the other
- iterating through the intersection of nonzeros (those indices where both vectors have nonzero values)
- iterating through the union of nonzeros (those indices where at least one of the vectors has a nonzero value)
- iterating through all the elements in some way (either through both at the same time, both one after the other,
looking up both, looking up just one).
Then, there are two additional sub-possibilities:
- if a new value can be added to x in constant time (isAddConstantTime()), the *Inplace updates are used
- otherwise (really just for SequentialAccessSparseVectors right now), the *Merge updates are used, where
a sorted list of (index, value) pairs is merged into the vector at the end.
The internal details are not important and a particular algorithm should generally not be called explicitly.
The best one will be selected through assignBest(), which is itself called through Vector.assign().
See https://docs.google.com/document/d/1g1PjUuvjyh2LBdq2_rKLIcUiDbeOORA1sCJiSsz-JVU/edit# for a more detailed
This is the method that should be used when assigning. It selects the best algorithm and applies it.
Note that it does NOT invalidate the cached length of the Vector and should only be used through the wrapprs