net.sourceforge.combean.mathprog.linalg.statics
Class SparseVectorConverter

Package class diagram package SparseVectorConverter
java.lang.Object
  extended by net.sourceforge.combean.mathprog.linalg.statics.SparseVectorConverter

public final class SparseVectorConverter
extends Object

Collection of static helper functions to convert SparseVectors to plain Java arrays.


Constructor Summary
SparseVectorConverter()
           
 
Method Summary
static double[] convertToDoubleArray(int dim, SparseVec<NoLabel> vec)
          Convert SparseVec to plain double array
static double[] convertToDoubleArray(int dim, VectorIterator<NoLabel> itVec)
          Convert a sparse vector given by an iterator over its components to a plain double array
static double[] convertToDoubleArray(SparseVector vec)
          Convert SparseVec to plain double array, giving the double array the exact dimension of the sparse vector.
static
<T> void
convertToIndexAndDoubleArray(SparseVec<T> vec, int[] indexArr, double[] valueArr)
          Convert an SparseVec to two plain Java arrays, one containing the indices of non-zero entries and a double array containing their values.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SparseVectorConverter

public SparseVectorConverter()
Method Detail

convertToDoubleArray

public static double[] convertToDoubleArray(int dim,
                                            VectorIterator<NoLabel> itVec)
Convert a sparse vector given by an iterator over its components to a plain double array

Parameters:
dim - the dimension of the dense output double array
itVec - the iterator over the entries in the sparse vector
Returns:
the entries represented by itVec as double array

convertToDoubleArray

public static double[] convertToDoubleArray(int dim,
                                            SparseVec<NoLabel> vec)
Convert SparseVec to plain double array

Parameters:
dim - desired dimension of the output array. must be big enough such that all entries in vec fit into the output
vec - the vector to be converted
Returns:
vec as double array

convertToDoubleArray

public static double[] convertToDoubleArray(SparseVector vec)
Convert SparseVec to plain double array, giving the double array the exact dimension of the sparse vector.

Parameters:
vec - the vector to be converted
Returns:
vec as double array

convertToIndexAndDoubleArray

public static <T> void convertToIndexAndDoubleArray(SparseVec<T> vec,
                                                    int[] indexArr,
                                                    double[] valueArr)
Convert an SparseVec to two plain Java arrays, one containing the indices of non-zero entries and a double array containing their values.

Parameters:
vec - the vector to be converted
indexArr - the index array to be filled. must be large enough to accomodate all entries of vec.
valueArr - the value array to be filled. must be large enough to accomodate all entries of vec.