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

Constructor Index

 o SparseVectorDouble(int)
Initialize a sparse vector of a given dimension.
 o SparseVectorDouble(int, int)
Initialize a sparse vector of a given dimension and nonzeros.
 o SparseVectorDouble(int, int, double[], int[])
Initialize a sparse vector of dimension N, with nz nonzeros, given values from val[] and integer positions in ind[].

Method Index

 o add(SparseVectorDouble)
 o add_eq(double[], SparseVectorDouble)
 o copy()
Create a copy of an existing sparse vector.
 o find(int)
Find out if a sparse vector contains an entry at a a given position in it's dense representation.
 o gather(double[])
 o gather(double[], int[], int[])
Pick off certain elements from a long dense vector and put them into nonzero values (val).
 o get(int)
 o get_index(int)
 o get_val(int)
 o num_nonzeros()
Determine the number of entries (nonzeros) in sparse vector.
 o print()
 o scatter(double[], SparseVectorDouble)
 o set(int, double)
 o set_index(int, int)
 o set_value(int, double)
 o set_value_index(int, double, int)
 o size()
Return the dimension of the sparse vector.

Constructors

 o 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.)
 o 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.
 o 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[].

Methods

 o copy
 public SparseVectorDouble copy()
Create a copy of an existing sparse vector.

 o 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.
 o get
 public final double get(int position)
 o get_val
 public final double get_val(int position)
 o set_value
 public final void set_value(int position,
                             double val)
 o get_index
 public final int get_index(int position)
 o set_index
 public final void set_index(int position,
                             int index)
 o set_value_index
 public final void set_value_index(int position,
                                   double val,
                                   int ind)
 o set
 public final void set(int position,
                       double val)
 o add_eq
 public static void add_eq(double x[],
                           SparseVectorDouble S)
 o scatter
 public void scatter(double x[],
                     SparseVectorDouble S)
 o add
 public SparseVectorDouble add(SparseVectorDouble S)
 o print
 public void print()
 o 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
 o gather
 public SparseVectorDouble gather(double x[])
 o size
 public int size()
Return the dimension of the sparse vector.

 o 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