public class SparseVector extends java.lang.Object implements Vector
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.
Constructor and Description |
---|
SparseVector(int size,
int[] indices,
double[] values) |
Modifier and Type | Method and Description |
---|---|
static double |
apply(int i) |
int |
argmax()
Find the index of a maximal element.
|
static Vector |
compressed() |
SparseVector |
copy()
Makes a deep copy of this vector.
|
boolean |
equals(java.lang.Object other) |
void |
foreachActive(scala.Function2<java.lang.Object,java.lang.Object,scala.runtime.BoxedUnit> f)
Applies a function
f to all the active elements of dense and sparse 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.
|
static DenseVector |
toDense() |
java.lang.String |
toJson()
Converts the vector to a JSON string.
|
SparseVector |
toSparse()
Converts this vector to a sparse vector with all explicit zeros removed.
|
java.lang.String |
toString() |
static scala.Option<scala.Tuple3<java.lang.Object,int[],double[]>> |
unapply(SparseVector sv) |
double[] |
values() |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
apply, compressed, toDense
public static scala.Option<scala.Tuple3<java.lang.Object,int[],double[]>> unapply(SparseVector sv)
public static double apply(int i)
public static DenseVector toDense()
public static Vector compressed()
public int size()
Vector
public int[] indices()
public double[] values()
public java.lang.String toString()
toString
in class java.lang.Object
public double[] toArray()
Vector
public SparseVector copy()
Vector
public void foreachActive(scala.Function2<java.lang.Object,java.lang.Object,scala.runtime.BoxedUnit> f)
Vector
f
to all the active elements of dense and sparse vector.
foreachActive
in interface Vector
f
- the function takes two parameters where the first parameter is the index of
the vector with type Int
, and the second parameter is the corresponding value
with type Double
.public boolean equals(java.lang.Object other)
public int hashCode()
Vector
java.util.Arrays.hashCode
.public int numActives()
Vector
numActives
in interface Vector
public int numNonzeros()
Vector
numNonzeros
in interface Vector
public SparseVector toSparse()
Vector
public int argmax()
Vector