JScience v4.3

org.jscience.mathematics.vector
Class SparseVector<F extends Field<F>>

java.lang.Object
  extended by org.jscience.mathematics.vector.Vector<F>
      extended by org.jscience.mathematics.vector.SparseVector<F>
All Implemented Interfaces:
javolution.lang.Immutable, javolution.lang.Realtime, javolution.lang.ValueType, GroupAdditive<Vector<F>>, Structure<Vector<F>>, VectorSpace<Vector<F>,F>

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.

Version:
3.3, January 2, 2007
Author:
Jean-Marie Dautelle

Field Summary
protected static javolution.xml.XMLFormat<SparseVector> XML
          Holds the default XML representation for sparse vectors.
 
Method Summary
 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>>
SparseVector<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>>
SparseVector<F>
valueOf(int dimension, F zero, java.util.Map<javolution.util.Index,F> elements)
          Returns a sparse vector from the specified index to element mapping.
static
<F extends Field<F>>
SparseVector<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>>
SparseVector<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.
 
Methods inherited from class org.jscience.mathematics.vector.Vector
cross, equals, equals, hashCode, minus, toString, toText
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

XML

protected static final javolution.xml.XMLFormat<SparseVector> XML
Holds the default XML representation for sparse vectors. For example:
    <SparseVector dimension="16">
        <Zero class="Complex" real="0.0" imaginary="0.0" />
        <Elements>
            <Index value="4" />
            <Complex real="1.0" imaginary="0.0" />
            <Index value="6" />
            <Complex real="0.0" imaginary="1.0" />
        </Elements>
    </SparseVector>

Method Detail

valueOf

public static <F extends Field<F>> SparseVector<F> valueOf(int dimension,
                                                           F zero,
                                                           int i,
                                                           F element)
Returns a sparse vector having a single element at the specified index.

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.
Returns:
the corresponding vector.

valueOf

public static <F extends Field<F>> SparseVector<F> valueOf(int dimension,
                                                           F zero,
                                                           java.util.Map<javolution.util.Index,F> elements)
Returns a sparse vector from the specified index to element mapping.

Parameters:
dimension - this vector dimension.
zero - the element representing zero.
elements - the index to element mapping.
Returns:
the corresponding vector.

valueOf

public static <F extends Field<F>> SparseVector<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.

Parameters:
that - the vector to convert.
zero - the zero element for the sparse vector to return.
Returns:
SparseVector.valueOf(that, zero, FastComparator.DEFAULT)

valueOf

public static <F extends Field<F>> SparseVector<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. This method can be used to clean up sparse vectors (to remove elements close to zero).

Parameters:
that - the vector to convert.
zero - the zero element for the sparse vector to return.
comparator - the comparator used to determinate zero equality.
Returns:
a sparse vector with zero elements removed.

getZero

public F getZero()
Returns the value of the non-set elements for this sparse vector.

Returns:
the element corresponding to zero.

getDimension

public int getDimension()
Description copied from class: Vector
Returns the number of elements held by this vector.

Specified by:
getDimension in class Vector<F extends Field<F>>
Returns:
this vector dimension.

get

public F get(int i)
Description copied from class: Vector
Returns a single element from this vector.

Specified by:
get in class Vector<F extends Field<F>>
Parameters:
i - the element index (range [0..n[).
Returns:
the element at i.

opposite

public SparseVector<F> opposite()
Description copied from class: Vector
Returns the negation of this vector.

Specified by:
opposite in interface GroupAdditive<Vector<F extends Field<F>>>
Specified by:
opposite in class Vector<F extends Field<F>>
Returns:
-this.

plus

public SparseVector<F> plus(Vector<F> that)
Description copied from class: Vector
Returns the sum of this vector with the one specified.

Specified by:
plus in interface GroupAdditive<Vector<F extends Field<F>>>
Specified by:
plus in class Vector<F extends Field<F>>
Parameters:
that - the vector to be added.
Returns:
this + that.

times

public SparseVector<F> times(F k)
Description copied from class: Vector
Returns the product of this vector with the specified coefficient.

Specified by:
times in interface VectorSpace<Vector<F extends Field<F>>,F extends Field<F>>
Specified by:
times in class Vector<F extends Field<F>>
Parameters:
k - the coefficient multiplier.
Returns:
this · k

times

public F times(Vector<F> that)
Description copied from class: Vector
Returns the dot product of this vector with the one specified.

Specified by:
times in class Vector<F extends Field<F>>
Parameters:
that - the vector multiplier.
Returns:
this · that
See Also:
Wikipedia: Dot Product

copy

public SparseVector<F> copy()
Description copied from class: Vector
Returns a copy of this vector allocated by the calling thread (possibly on the stack).

Specified by:
copy in interface javolution.lang.ValueType
Specified by:
copy in class Vector<F extends Field<F>>
Returns:
an identical and independant copy of this matrix.

JScience v4.3

Copyright © 2006 JScience.