All Packages Class Hierarchy This Package Previous Next Index
Class jnt.linear_algebra.SparseVectorDouble
java.lang.Object
|
+----jnt.linear_algebra.SparseVectorDouble
- public class SparseVectorDouble
- extends Object
Provides a compact representation of numerical sparse vectors
and basic algebraic operations.
The nonzero value, together with its offset are stored.
Thus, the 5-element vector [0.0, 2.1, 0.0, 7.0, 3.5]
(with three nonzeros) could be represented as a sparse
vector by the following contstructor:
double val[] = new double[3];
int ind[] = new int[3];
val[0] = 2.1; ind[0] = 1;
val[1] = 7.0; ind[1] = 3;
val[2] = 3.5; ind[2] = 4;
SparseVectorDouble S = new SparseVectorDouble(5, 3, val, ind);
or, more elegantly
SparseVectorDouble S = new SparseVectorDouble(5, 3);
S.set(1, 2.1);
S.set(3, 7.0);
S.set(4, 3.5);
The elements are unoreded, and offsets begin at 0.
Note, also, that sparse vector representations are not
unique -- the elements are unordered, and explicit zeros
could be stored.
- Version:
- 0.5
- Author:
- Roldan Pozo
-
SparseVectorDouble(int)
- Initialize a sparse vector of a given dimension.
-
SparseVectorDouble(int, int)
- Initialize a sparse vector of a given dimension and nonzeros.
-
SparseVectorDouble(int, int, double[], int[])
- Initialize a sparse vector of dimension N, with nz nonzeros,
given values from
val[]
and integer positions
in ind[]
.
-
add(SparseVectorDouble)
-
-
add_eq(double[], SparseVectorDouble)
-
-
copy()
- Create a copy of an existing sparse vector.
-
find(int)
- Find out if a sparse vector contains an entry at a
a given position in it's dense representation.
-
gather(double[])
-
-
gather(double[], int[], int[])
- Pick off certain elements from a long dense vector
and put them into nonzero values (val).
-
get(int)
-
-
get_index(int)
-
-
get_val(int)
-
-
num_nonzeros()
- Determine the number of entries (nonzeros)
in sparse vector.
-
print()
-
-
scatter(double[], SparseVectorDouble)
-
-
set(int, double)
-
-
set_index(int, int)
-
-
set_value(int, double)
-
-
set_value_index(int, double, int)
-
-
size()
- Return the dimension of the sparse vector.
SparseVectorDouble
public SparseVectorDouble(int N)
- Initialize a sparse vector of a given dimension. No storage space
for nonzeros is actually created.
- Parameters:
- N - the dimension of the vector (not the
number of nonzeros.)
SparseVectorDouble
public SparseVectorDouble(int N,
int nz)
- Initialize a sparse vector of a given dimension and nonzeros.
- Parameters:
- N - the dimension of the vector.
- nz - the number of nonzeros.
SparseVectorDouble
public SparseVectorDouble(int N,
int nz,
double val[],
int index[])
- Initialize a sparse vector of dimension N, with nz nonzeros,
given values from
val[]
and integer positions
in ind[]
.
- Parameters:
- N - the dimension of the vector.
- nz - the number of nonzeros.
- val[nz] - vector of nonzero values
- ind[nz] - vector of positions of elements in val[].
copy
public SparseVectorDouble copy()
- Create a copy of an existing sparse vector.
find
public int find(int position)
- Find out if a sparse vector contains an entry at a
a given position in it's dense representation.
- Parameters:
- position - (in): offset of dense vector to find.
- Returns:
- offset in compressed format, if found; -1, otherwise.
get
public final double get(int position)
get_val
public final double get_val(int position)
set_value
public final void set_value(int position,
double val)
get_index
public final int get_index(int position)
set_index
public final void set_index(int position,
int index)
set_value_index
public final void set_value_index(int position,
double val,
int ind)
set
public final void set(int position,
double val)
add_eq
public static void add_eq(double x[],
SparseVectorDouble S)
scatter
public void scatter(double x[],
SparseVectorDouble S)
add
public SparseVectorDouble add(SparseVectorDouble S)
print
public void print()
gather
public static void gather(double val[],
int ind[],
int x[])
- Pick off certain elements from a long dense vector
and put them into nonzero values (val). The positions
to pick out are listed in ind. For example,
if ind = (1, 2, 4) and x= ( 3.1, 4.2, 5.3, 6.4, 7.5)
then val wolud be set to ( 4.2, 5.3, 7.5 )
- Parameters:
- val - (out) vector of nonzeros
- ind - (in) vector of indicies
- x - (in) the dense vector to extract from
gather
public SparseVectorDouble gather(double x[])
size
public int size()
- Return the dimension of the sparse vector.
num_nonzeros
public int num_nonzeros()
- Determine the number of entries (nonzeros)
in sparse vector.
- Returns:
- the number of explicitly-stored elemented in
the sparse vector.
All Packages Class Hierarchy This Package Previous Next Index