net.sourceforge.combean.mathprog.linalg
Class SparseDoubleVector

Package class diagram package SparseDoubleVector
java.lang.Object
  extended by net.sourceforge.combean.mathprog.linalg.SparseDoubleVector
All Implemented Interfaces:
SparseVec<NoLabel>, SparseVector

public class SparseDoubleVector
extends Object
implements SparseVector

A simple implementation of a sparse vector of doubles, consisting of an array of doubles values and an array of int indices.


Constructor Summary
SparseDoubleVector(int dimension, int[] indices, double[] values)
          Constructor.
SparseDoubleVector(int dimension, int index, double value)
          Constructor for a sparse vector with a single non-zero element.
 
Method Summary
 int getDimension()
          Get the dimension of the vector.
 int[] getIndices()
           
 int getNumIterations()
          Return the number of entries of the vector through which the iterator returned by getIterator() iterates.
 double[] getValues()
           
 VectorIterator<NoLabel> iterator()
          Get an iterator which iterates through all non-zero entries of the vector.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SparseDoubleVector

public SparseDoubleVector(int dimension,
                          int[] indices,
                          double[] values)
Constructor.

Parameters:
values -
indices -

SparseDoubleVector

public SparseDoubleVector(int dimension,
                          int index,
                          double value)
Constructor for a sparse vector with a single non-zero element.

Parameters:
dimension - the dimension of the vector.
index - the index of the non-zero element.
value - the value of the non-zero element.
Method Detail

getDimension

public int getDimension()
Description copied from interface: SparseVector
Get the dimension of the vector.

Specified by:
getDimension in interface SparseVector
Returns:
the dimension of the vector.

iterator

public VectorIterator<NoLabel> iterator()
Description copied from interface: SparseVec
Get an iterator which iterates through all non-zero entries of the vector. The iteration must stop after exactly getNumNonZeroEntries() steps. An implementation may choose to also return zero entries during the iteration. In that case, these entries must also be counted by getNumIterations(); The iteration does not have to return the values in order of increasing indices.

Specified by:
iterator in interface SparseVec<NoLabel>
Returns:
an iterator for the non-zero entries.

getNumIterations

public int getNumIterations()
Description copied from interface: SparseVec
Return the number of entries of the vector through which the iterator returned by getIterator() iterates.

Specified by:
getNumIterations in interface SparseVec<NoLabel>
Returns:
the number of iterations of getIterator.

getIndices

public final int[] getIndices()
Returns:
Returns the indices.

getValues

public final double[] getValues()
Returns:
Returns the values.