public class SequentialAccessSparseVector extends AbstractVector
Implements vector that only stores non-zero doubles as a pair of parallel arrays (OrderedIntDoubleMapping),
one int[], one double[]. If there are k non-zero elements in the vector, this implementation has
O(log(k)) random-access read performance, and O(k) random-access write performance, which is far below that
of the hashmap based RandomAccessSparseVector
. This
class is primarily used for operations where the all the elements will be accessed in a read-only fashion
sequentially: methods which operate not via get() or set(), but via iterateNonZero(), such as (but not limited
to) :
OrderedIntDoubleMapping
AbstractVector.LocalElement
Vector.Element
lengthSquared
Constructor and Description |
---|
SequentialAccessSparseVector()
For serialization purposes only.
|
SequentialAccessSparseVector(int cardinality) |
SequentialAccessSparseVector(int cardinality,
int size) |
SequentialAccessSparseVector(SequentialAccessSparseVector other) |
SequentialAccessSparseVector(SequentialAccessSparseVector other,
boolean shallowCopy) |
SequentialAccessSparseVector(Vector other) |
Modifier and Type | Method and Description |
---|---|
SequentialAccessSparseVector |
clone()
Return a copy of the recipient
|
double |
getIteratorAdvanceCost()
Gets an estimate of the cost (in number of operations) it takes to advance an iterator through the nonzero
elements of this vector.
|
double |
getLookupCost()
Gets an estimate of the cost (in number of operations) it takes to lookup a random element in this vector.
|
int |
getNumNondefaultElements()
Return the number of values in the recipient which are not the default value.
|
int |
getNumNonZeroElements()
Return the number of non zero elements in the vector.
|
double |
getQuick(int index)
Warning! This takes O(log n) time as it does a binary search behind the scenes!
Only use it when STRICTLY necessary.
|
void |
incrementQuick(int index,
double increment)
Increment the value at the given index by the given value.
|
boolean |
isAddConstantTime()
Return true iff adding a new (nonzero) element takes constant time for this vector.
|
boolean |
isDense() |
boolean |
isSequentialAccess() |
Iterator<Vector.Element> |
iterateNonZero()
Iterates over all non-zero elements.
|
Iterator<Vector.Element> |
iterator()
Iterates over all elements * NOTE: Implementations may choose to reuse the Element returned for performance
reasons, so if you need a copy of it, you should call
AbstractVector.getElement(int) for the given index |
SequentialAccessSparseVector |
like()
Return an empty vector of the same underlying class as the receiver
|
protected Matrix |
matrixLike(int rows,
int columns)
Subclasses must override to return an appropriately sparse or dense result
|
void |
mergeUpdates(OrderedIntDoubleMapping updates)
Merge a set of (index, value) pairs into the vector.
|
void |
setQuick(int index,
double value)
Warning! This takes O(log n) time as it does a binary search behind the scenes!
Only use it when STRICTLY necessary.
|
String |
toString() |
aggregate, aggregate, all, asFormatString, assign, assign, assign, assign, assign, assign, createOptimizedCopy, cross, divide, dot, dotSelf, equals, get, getDistanceSquared, getElement, getLengthSquared, hashCode, invalidateCachedLength, logNormalize, logNormalize, logNormalize, maxValue, maxValueIndex, minus, minValue, minValueIndex, nonZeroes, norm, normalize, normalize, plus, plus, set, size, sparseVectorToString, times, times, toString, viewPart, zSum
public SequentialAccessSparseVector()
public SequentialAccessSparseVector(int cardinality)
public SequentialAccessSparseVector(int cardinality, int size)
public SequentialAccessSparseVector(Vector other)
public SequentialAccessSparseVector(SequentialAccessSparseVector other, boolean shallowCopy)
public SequentialAccessSparseVector(SequentialAccessSparseVector other)
protected Matrix matrixLike(int rows, int columns)
AbstractVector
matrixLike
in class AbstractVector
rows
- the row cardinalitycolumns
- the column cardinalitypublic SequentialAccessSparseVector clone()
Vector
clone
in interface Vector
clone
in class AbstractVector
public void mergeUpdates(OrderedIntDoubleMapping updates)
Vector
updates
- an ordered mapping of indices to values to be merged in.public String toString()
toString
in class AbstractVector
public boolean isDense()
public boolean isSequentialAccess()
public double getQuick(int index)
index
- an int index.public void setQuick(int index, double value)
index
- an int index.value
- a double value to setpublic void incrementQuick(int index, double increment)
Vector
incrementQuick
in interface Vector
incrementQuick
in class AbstractVector
index
- an int index into the receiverincrement
- sets the value at the given index to value + increment;public SequentialAccessSparseVector like()
Vector
public int getNumNondefaultElements()
Vector
public int getNumNonZeroElements()
Vector
getNumNonZeroElements
in interface Vector
getNumNonZeroElements
in class AbstractVector
public double getLookupCost()
Vector
public double getIteratorAdvanceCost()
Vector
public boolean isAddConstantTime()
Vector
public Iterator<Vector.Element> iterateNonZero()
AbstractVector
AbstractVector.getElement(int)
for the given indexiterateNonZero
in class AbstractVector
Iterator
over all non-zero elementspublic Iterator<Vector.Element> iterator()
AbstractVector
AbstractVector.getElement(int)
for the given indexiterator
in class AbstractVector
Iterator
over all elementsCopyright © 2008–2015 The Apache Software Foundation. All rights reserved.