public class CompactSparseVector extends AbstractDoubleVector implements SparseDoubleVector, Serializable, Iterable<DoubleEntry>
Vector instance that keeps only the non-zero values in memory,
 thereby saving space at the expense of time.
  See SparseDoubleArray for details on how the sparse
 representation is implemented.
| Constructor and Description | 
|---|
| CompactSparseVector()Creates a  CompactSparseVectorthat grows to the maximum size set
 byDouble.MAX_VALUE. | 
| CompactSparseVector(double[] array)Create a  CompactSparseVectorfrom an array, saving only the non
 zero entries. | 
| CompactSparseVector(int length)Create a  CompactSparseVectorwith the given size, having no
 non-zero values. | 
| CompactSparseVector(int[] nonZeroIndices,
                   double[] values,
                   int length)Create a  CompactSparseVectorusing the indices and their
 respecitve values. | 
| CompactSparseVector(SparseDoubleVector v)Create a  CompactSparseVectorfrom an array, saving only the non
 zero entries. | 
| Modifier and Type | Method and Description | 
|---|---|
| double | add(int index,
   double delta)Throws an  UnsupportedOperationExceptionif called (vector is
 unmodifiable). | 
| double | get(int index)Returns the value of this vector at the given index. | 
| int[] | getNonZeroIndices()Returns all the indices whose values are non-zero | 
| Iterator<DoubleEntry> | iterator()Returns an iterator over all the non-zero indices and values in this
 vector. | 
| int | length()Return the size of the  Vector. | 
| double | magnitude()Returns the magnitude of this vector | 
| void | set(double[] values) | 
| void | set(int index,
   double value)Throws an  UnsupportedOperationExceptionif called (vector is
 unmodifiable). | 
| double[] | toArray()Returns a double array representing this vector. | 
equals, getValue, hashCode, set, toStringclone, finalize, getClass, notify, notifyAll, wait, wait, waitgetValuepublic CompactSparseVector()
CompactSparseVector that grows to the maximum size set
 by Double.MAX_VALUE.public CompactSparseVector(int length)
CompactSparseVector with the given size, having no
 non-zero values.length - The length of this CompactSparseVector.public CompactSparseVector(double[] array)
CompactSparseVector from an array, saving only the non
 zero entries.array - The double array to produce a sparse vector from.public CompactSparseVector(SparseDoubleVector v)
CompactSparseVector from an array, saving only the non
 zero entries.array - The double array to produce a sparse vector from.public CompactSparseVector(int[] nonZeroIndices,
                   double[] values,
                   int length)
CompactSparseVector using the indices and their
 respecitve values.indices - an sorted array of positive values representing the
        non-zero indices of the arrayvalues - an array of values that correspond their respective indiceslength - the total length of the arraypublic double add(int index,
         double delta)
UnsupportedOperationException if called (vector is
 unmodifiable).add in interface DoubleVectoradd in class AbstractDoubleVectorindex - index to change.delta - the amount to change by.public Iterator<DoubleEntry> iterator()
iterator in interface Iterable<DoubleEntry>public double get(int index)
get in interface DoubleVectorindex - index to retrieve.public int[] getNonZeroIndices()
getNonZeroIndices in interface SparseVector<Double>public int length()
Vector.public double magnitude()
magnitude in interface Vector<Double>magnitude in class AbstractDoubleVectorpublic void set(double[] values)
public void set(int index,
       double value)
UnsupportedOperationException if called (vector is
 unmodifiable).set in interface DoubleVectorset in class AbstractDoubleVectorindex - index to set.value - value to set in the vector.public double[] toArray()
toArray in interface DoubleVectortoArray in class AbstractDoubleVectordouble array of this vector.Copyright © 2012. All Rights Reserved.