\n\n\n\nSparseVector\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
\n\n\n\n\n
\n
\n
\n\n\n\n
\n
org.jscience.mathematics.vector
\n

## Class SparseVector<F extends Field<F>>

\n
\n
\n
\n
\n
\n
• \n
\n
All Implemented Interfaces:
\n
javolution.lang.Immutable, javolution.lang.Realtime, javolution.lang.ValueType, GroupAdditive<Vector<F>>, Structure<Vector<F>>, VectorSpace<Vector<F>,F>
\n
\n
\n
\n
`public final class SparseVector<F extends Field<F>>\nextends Vector<F>`
\n

This class represents a sparse vector.

\n

Sparse vectors can be created using an index-to-element mapping or \n by adding single elements sparse vectors together.

\n
• \n
\n
\n
\n
\n
• \n\n
\n
• \n\n\n

### Method Summary

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
Methods
Modifier and TypeMethod and Description
`SparseVector<F>``copy()`\n
Returns a copy of this vector \n `allocated` \n by the calling thread (possibly on the stack).
\n
`F``get(int i)`\n
Returns a single element from this vector.
\n
`int``getDimension()`\n
Returns the number of elements held by this vector.
\n
`F``getZero()`\n
Returns the value of the non-set elements for this sparse vector.
\n
`SparseVector<F>``opposite()`\n
Returns the negation of this vector.
\n
`SparseVector<F>``plus(Vector<F> that)`\n
Returns the sum of this vector with the one specified.
\n
`SparseVector<F>``times(F k)`\n
Returns the product of this vector with the specified coefficient.
\n
`F``times(Vector<F> that)`\n
Returns the dot product of this vector with the one specified.
\n
`static <F extends Field<F>> SparseVector<F>``valueOf(int dimension,\n F zero,\n int i,\n F element)`\n
Returns a sparse vector having a single element at the specified index.
\n
`static <F extends Field<F>> SparseVector<F>``valueOf(int dimension,\n F zero,\n Map<javolution.util.Index,F> elements)`\n
Returns a sparse vector from the specified index to element mapping.
\n
`static <F extends Field<F>> SparseVector<F>``valueOf(Vector<F> that,\n F zero)`\n
Returns a sparse vector equivalent to the specified vector but with \n the zero elements removed removed using a default object equality \n comparator.
\n
`static <F extends Field<F>> SparseVector<F>``valueOf(Vector<F> that,\n F zero,\n javolution.util.FastComparator<? super F> comparator)`\n
Returns a sparse vector equivalent to the specified vector but with \n the zero elements removed using the specified object equality comparator.
\n
\n
\n
• \n\n\n

### Methods inherited from class org.jscience.mathematics.vector.Vector

\n`cross, equals, equals, hashCode, minus, toString, toText`
• \n
\n
\n
• \n\n\n

### Methods inherited from class java.lang.Object

\n`getClass, notify, notifyAll, wait, wait, wait`
• \n
\n
• \n
\n
• \n
\n
\n
\n
\n
• \n\n
\n
• \n\n\n

### Method Detail

\n\n\n\n\n\n
\n
• \n

#### valueOf

\n
`public static <F extends Field<F>> SparseVector<F> valueOf(int dimension,\n                                           F zero,\n                                           int i,\n                                           F element)`
\n
Returns a sparse vector having a single element at the specified index.
\n
Parameters:
`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.
\n
Returns:
the corresponding vector.
\n
• \n
\n\n\n\n\n\n
\n
• \n

#### valueOf

\n
`public static <F extends Field<F>> SparseVector<F> valueOf(int dimension,\n                                           F zero,\n                                           Map<javolution.util.Index,F> elements)`
\n
Returns a sparse vector from the specified index to element mapping.
\n
Parameters:
`dimension` - this vector dimension.
`zero` - the element representing zero.
`elements` - the index to element mapping.
\n
Returns:
the corresponding vector.
\n
• \n
\n\n\n\n\n\n
\n
• \n

#### valueOf

\n
`public static <F extends Field<F>> SparseVector<F> valueOf(Vector<F> that,\n                                           F zero)`
\n
Returns a sparse vector equivalent to the specified vector but with \n the zero elements removed removed using a default object equality \n comparator.
\n
Parameters:
`that` - the vector to convert.
`zero` - the zero element for the sparse vector to return.
\n
Returns:
`SparseVector.valueOf(that, zero, FastComparator.DEFAULT)`
\n
• \n
\n\n\n\n\n\n
\n
• \n

#### valueOf

\n
`public static <F extends Field<F>> SparseVector<F> valueOf(Vector<F> that,\n                                           F zero,\n                                           javolution.util.FastComparator<? super F> comparator)`
\n
Returns a sparse vector equivalent to the specified vector but with \n the zero elements removed using the specified object equality comparator.\n This method can be used to clean up sparse vectors (to remove elements\n close to zero).
\n
Parameters:
`that` - the vector to convert.
`zero` - the zero element for the sparse vector to return.
`comparator` - the comparator used to determinate zero equality.
\n
Returns:
a sparse vector with zero elements removed.
\n
• \n
\n\n\n\n
\n
• \n

#### getZero

\n
`public F getZero()`
\n
Returns the value of the non-set elements for this sparse vector.
\n
Returns:
the element corresponding to zero.
\n
• \n
\n\n\n\n
\n
• \n

#### getDimension

\n
`public int getDimension()`
\n
Description copied from class: `Vector`
\n
Returns the number of elements held by this vector.
\n
\n
Specified by:
\n
`getDimension` in class `Vector<F extends Field<F>>`
\n
Returns:
this vector dimension.
\n
• \n
\n\n\n\n
\n
• \n

#### get

\n
`public F get(int i)`
\n
Description copied from class: `Vector`
\n
Returns a single element from this vector.
\n
\n
Specified by:
\n
`get` in class `Vector<F extends Field<F>>`
\n
Parameters:
`i` - the element index (range [0..n[).
\n
Returns:
the element at `i`.
\n
• \n
\n\n\n\n
\n
• \n

#### opposite

\n
`public SparseVector<F> opposite()`
\n
Description copied from class: `Vector`
\n
Returns the negation of this vector.
\n
\n
Specified by:
\n
`opposite` in interface `GroupAdditive<Vector<F extends Field<F>>>`
\n
Specified by:
\n
`opposite` in class `Vector<F extends Field<F>>`
\n
Returns:
`-this`.
\n
• \n
\n\n\n\n
\n
• \n

#### plus

\n
`public SparseVector<F> plus(Vector<F> that)`
\n
Description copied from class: `Vector`
\n
Returns the sum of this vector with the one specified.
\n
\n
Specified by:
\n
`plus` in interface `GroupAdditive<Vector<F extends Field<F>>>`
\n
Specified by:
\n
`plus` in class `Vector<F extends Field<F>>`
\n
Parameters:
`that` - the vector to be added.
\n
Returns:
`this + that`.
\n
• \n
\n\n\n\n\n\n
\n
• \n

#### times

\n
`public SparseVector<F> times(F k)`
\n
Description copied from class: `Vector`
\n
Returns the product of this vector with the specified coefficient.
\n
\n
Specified by:
\n
`times` in interface `VectorSpace<Vector<F extends Field<F>>,F extends Field<F>>`
\n
Specified by:
\n
`times` in class `Vector<F extends Field<F>>`
\n
Parameters:
`k` - the coefficient multiplier.
\n
Returns:
`this \xc2\xb7 k`
\n
• \n
\n\n\n\n
\n
• \n

#### times

\n
`public F times(Vector<F> that)`
\n
Description copied from class: `Vector`
\n
Returns the dot product of this vector with the one specified.
\n
\n
Specified by:
\n
`times` in class `Vector<F extends Field<F>>`
\n
Parameters:
`that` - the vector multiplier.
\n
Returns:
`this \xc2\xb7 that`
\n Wikipedia: Dot Product
\n
• \n
\n\n\n\n
\n
• \n

#### copy

\n
`public SparseVector<F> copy()`
\n
Description copied from class: `Vector`
\n
Returns a copy of this vector \n `allocated` \n by the calling thread (possibly on the stack).
\n
\n
Specified by:
\n
`copy` in interface `javolution.lang.ValueType`
\n
Specified by:
\n
`copy` in class `Vector<F extends Field<F>>`
\n
Returns:
an identical and independant copy of this matrix.
\n
• \n
\n
• \n
\n
• \n
\n
\n
\n\n\n
\n\n\n\n\n
\n
\n
\n\n\n