public final class SparseVector<F extends Field<F>> extends Vector<F>
This class represents a sparse vector.
Sparse vectors can be created using an index-to-element mapping or by adding single elements sparse vectors together.
| Modifier and Type | Method and Description |
|---|---|
SparseVector<F> |
copy()
Returns a copy of this vector
allocated
by the calling thread (possibly on the stack). |
F |
get(int i)
Returns a single element from this vector.
|
int |
getDimension()
Returns the number of elements held by this vector.
|
F |
getZero()
Returns the value of the non-set elements for this sparse vector.
|
SparseVector<F> |
opposite()
Returns the negation of this vector.
|
SparseVector<F> |
plus(Vector<F> that)
Returns the sum of this vector with the one specified.
|
SparseVector<F> |
times(F k)
Returns the product of this vector with the specified coefficient.
|
F |
times(Vector<F> that)
Returns the dot product of this vector with the one specified.
|
static <F extends Field<F>> |
valueOf(int dimension,
F zero,
int i,
F element)
Returns a sparse vector having a single element at the specified index.
|
static <F extends Field<F>> |
valueOf(int dimension,
F zero,
Map<javolution.util.Index,F> elements)
Returns a sparse vector from the specified index to element mapping.
|
static <F extends Field<F>> |
valueOf(Vector<F> that,
F zero)
Returns a sparse vector equivalent to the specified vector but with
the zero elements removed removed using a default object equality
comparator.
|
static <F extends Field<F>> |
valueOf(Vector<F> that,
F zero,
javolution.util.FastComparator<? super F> comparator)
Returns a sparse vector equivalent to the specified vector but with
the zero elements removed using the specified object equality comparator.
|
public static <F extends Field<F>> SparseVector<F> valueOf(int dimension, F zero, int i, F element)
dimension - this vector dimension.zero - the element representing zero.i - the index value of this vector single element.element - the element at the specified index.public static <F extends Field<F>> SparseVector<F> valueOf(int dimension, F zero, Map<javolution.util.Index,F> elements)
dimension - this vector dimension.zero - the element representing zero.elements - the index to element mapping.public static <F extends Field<F>> SparseVector<F> valueOf(Vector<F> that, F zero)
that - the vector to convert.zero - the zero element for the sparse vector to return.SparseVector.valueOf(that, zero, FastComparator.DEFAULT)public static <F extends Field<F>> SparseVector<F> valueOf(Vector<F> that, F zero, javolution.util.FastComparator<? super F> comparator)
that - the vector to convert.zero - the zero element for the sparse vector to return.comparator - the comparator used to determinate zero equality.public F getZero()
public int getDimension()
VectorgetDimension in class Vector<F extends Field<F>>public F get(int i)
Vectorpublic SparseVector<F> opposite()
Vectorpublic SparseVector<F> plus(Vector<F> that)
Vectorpublic SparseVector<F> times(F k)
Vectorpublic F times(Vector<F> that)
Vectorpublic SparseVector<F> copy()
Vectorallocated
by the calling thread (possibly on the stack).