public class SparseVector extends java.lang.Object implements java.lang.Iterable<VectorEntry>
Constructor and Description |
---|
SparseVector(int capcity)
Construct a sparse vector with its maximum capacity
|
SparseVector(int capcity,
double[] array)
Construct a sparse vector with its maximum capacity, filled with given
data array
|
SparseVector(SparseVector sv)
Construct a sparse vecto by deeply copying another vector
|
Modifier and Type | Method and Description |
---|---|
void |
add(int idx,
double val)
Add a value to entry [idx]
|
boolean |
contains(int idx)
Check if a vector contains a specific index
|
double |
get(int idx)
Retrieve a value at entry [idx]
|
int |
getCount()
Number of entries in the sparse structure
|
double[] |
getData()
Returns the internal data
|
int[] |
getIndex()
Returns the indices
|
double |
inner(DenseVector vec) |
double |
inner(SparseVector vec) |
java.util.Iterator<VectorEntry> |
iterator() |
double |
mean() |
void |
set(int idx,
double val)
Set a value to entry [idx]
|
int |
size() |
double |
sum() |
java.util.Map<java.lang.Integer,java.lang.Double> |
toMap() |
java.lang.String |
toString() |
public SparseVector(int capcity)
capcity
- maximum size of the sparse vectorpublic SparseVector(int capcity, double[] array)
capcity
- maximum size of the sparse vectorarray
- input datapublic SparseVector(SparseVector sv)
public boolean contains(int idx)
idx
- the idex to searchpublic double[] getData()
public int[] getIndex()
public int getCount()
public void set(int idx, double val)
public void add(int idx, double val)
public double get(int idx)
public double inner(SparseVector vec)
public double inner(DenseVector vec)
public double sum()
public double mean()
public int size()
public java.util.Iterator<VectorEntry> iterator()
iterator
in interface java.lang.Iterable<VectorEntry>
public java.lang.String toString()
toString
in class java.lang.Object
public java.util.Map<java.lang.Integer,java.lang.Double> toMap()