org.apache.spark.mllib.linalg
Class SparseVector

Object
  extended by org.apache.spark.mllib.linalg.SparseVector
All Implemented Interfaces:
java.io.Serializable, Vector

public class SparseVector
extends Object
implements Vector

A sparse vector represented by an index array and an value array.

param: size size of the vector. param: indices index array, assume to be strictly increasing. param: values value array, must have the same length as the index array.

See Also:
Serialized Form

Constructor Summary
SparseVector(int size, int[] indices, double[] values)
           
 
Method Summary
 SparseVector copy()
          Makes a deep copy of this vector.
 int hashCode()
          Returns a hash code value for the vector.
 int[] indices()
           
 int numActives()
          Number of active entries.
 int numNonzeros()
          Number of nonzero elements.
 int size()
          Size of the vector.
 double[] toArray()
          Converts the instance to a double array.
 SparseVector toSparse()
          Converts this vector to a sparse vector with all explicit zeros removed.
 String toString()
           
static scala.Option<scala.Tuple3<Object,int[],double[]>> unapply(SparseVector sv)
           
 double[] values()
           
 
Methods inherited from class Object
equals, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.apache.spark.mllib.linalg.Vector
apply, compressed, equals, toDense
 

Constructor Detail

SparseVector

public SparseVector(int size,
                    int[] indices,
                    double[] values)
Method Detail

unapply

public static scala.Option<scala.Tuple3<Object,int[],double[]>> unapply(SparseVector sv)

size

public int size()
Description copied from interface: Vector
Size of the vector.

Specified by:
size in interface Vector
Returns:
(undocumented)

indices

public int[] indices()

values

public double[] values()

toString

public String toString()
Overrides:
toString in class Object

toArray

public double[] toArray()
Description copied from interface: Vector
Converts the instance to a double array.

Specified by:
toArray in interface Vector
Returns:
(undocumented)

copy

public SparseVector copy()
Description copied from interface: Vector
Makes a deep copy of this vector.

Specified by:
copy in interface Vector
Returns:
(undocumented)

hashCode

public int hashCode()
Description copied from interface: Vector
Returns a hash code value for the vector. The hash code is based on its size and its nonzeros in the first 16 entries, using a hash algorithm similar to java.util.Arrays.hashCode.

Specified by:
hashCode in interface Vector
Overrides:
hashCode in class Object
Returns:
(undocumented)

numActives

public int numActives()
Description copied from interface: Vector
Number of active entries. An "active entry" is an element which is explicitly stored, regardless of its value. Note that inactive entries have value 0.

Specified by:
numActives in interface Vector
Returns:
(undocumented)

numNonzeros

public int numNonzeros()
Description copied from interface: Vector
Number of nonzero elements. This scans all active values and count nonzeros.

Specified by:
numNonzeros in interface Vector
Returns:
(undocumented)

toSparse

public SparseVector toSparse()
Description copied from interface: Vector
Converts this vector to a sparse vector with all explicit zeros removed.

Specified by:
toSparse in interface Vector
Returns:
(undocumented)