All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class jnt.linear_algebra.CoordinateSparseMatrixDouble

java.lang.Object
   |
   +----jnt.linear_algebra.CoordinateSparseMatrixDouble

public class CoordinateSparseMatrixDouble
extends Object
A coordinate-storage representation of sparse matrices in which the nonzeros at location A[i][j] are stored explicity. No order is imposed on the storage order. and basic algebraic operations.

The nonzero value, together with its offset are stored. Thus, the 5-element matrix

   
0   1   0
4   2   0
0   0   7
could be represented by the following contstructor:
double val[] = new double[3];
int    row[] = new int[3];
int    col[] = new int[3];

val[0] = 1.0; col[0] = 0; row[0] = 1; val[1] = 4.0; col[1] = 1; row[1] = 0; val[2] = 2.0; col[2] = 1; row[2] = 1; val[3] = 7.0; col[3] = 2; row[3] = 2;
CoordinateSparseMatrixDouble S = new CoordinateSparseMatrixDouble(3, 3, 4, val, row, col);
or, equivalently
CoordinateSparseMatrixDouble S = new 
CoordinateSparseMatrixDouble(3, 3, 4);

for (int i=0; i<3; i++) S.set_ith_element(i, row[i], col[i], val[i]);

General set/get functions which treat the matrix as dense, are available but are not very efficient (i.e. they have an O(nz) cost).

S.set(i,j, val);        // equivalent to A[i][j] = val;
v = S.get(i,j);         // equivalent to v = A[i][j];

The elements are unoreded, and offsets begin at 0. Note, also, that coordinate matrix representations are not unique -- the elements are unordered, and explicit zeros could be stored.

Version:
0.5
Author:
Roldan Pozo

Constructor Index

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

Method Index

 o col()
Return vector of column indices as a contiguous array.
 o col(int)
 o copy()
Create a copy of an existing sparse vector.
 o M()
Return the first dimension of the sparse matrix.
 o mult(double[])
Compute A*x
 o mult(double[], double[])
Compute y += A*x;
 o N()
Return the second dimension of the sparse matrix.
 o num_nonzeros()
Return the number of number of nonzeros in sparse matrix.
 o print()
 o readfile(String)
Read a sparse matrix from an ASCII text file.
 o readfile(String, int)
Reads sparse form file, similar to readfile(String) but has an optional base-offset parameter to denote the starting position of matrix indices.
 o row()
Return vector of row indices as a contiguous array.
 o row(int)
 o val()
Return vector of nonzero values.
 o val(int)
 o write()
 o write(CoordinateSparseMatrixDouble)

Constructors

 o CoordinateSparseMatrixDouble
 public CoordinateSparseMatrixDouble(int M,
                                     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 CoordinateSparseMatrixDouble
 public CoordinateSparseMatrixDouble(int M,
                                     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 CoordinateSparseMatrixDouble
 public CoordinateSparseMatrixDouble(int M,
                                     int N,
                                     int nz,
                                     int row[],
                                     int col[],
                                     double val[])
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 CoordinateSparseMatrixDouble copy()
Create a copy of an existing sparse vector.

 o val
 public final double[] val()
Return vector of nonzero values.

NOTE: this access method is here for efficiency. It should be used by 'trusted' apps only, because it essentially bypasses the 'private' status of these variables.

 o val
 public final double val(int i)
 o row
 public final int[] row()
Return vector of row indices as a contiguous array.

NOTE: this access method is here for efficiency. It should be used by 'trusted' apps only, because it essentially bypasses the 'private' status of these variables.

 o row
 public final int row(int i)
 o col
 public final int col(int i)
 o col
 public final int[] col()
Return vector of column indices as a contiguous array.

NOTE: this access method is here for efficiency. It should be used by 'trusted' apps only, because it essentially bypasses the 'private' status of these variables.

 o mult
 public final double[] mult(double x[])
Compute A*x

 o mult
 public final void mult(double y[],
                        double x[])
Compute y += A*x;

Parameters:
x - the vector to multiply
y - the vector to update
 o print
 public void print()
 o write
 public static void write(CoordinateSparseMatrixDouble S)
 o write
 public void write()
 o readfile
 public static CoordinateSparseMatrixDouble readfile(String s) throws IOException
Read a sparse matrix from an ASCII text file. The file format lists the matrix size (M, N), the number of nonzeros (nz), followed by the triplet (i, j, a_ij) for each nonzero. For example,
5 7 3
1 1 2.0
3 4 9.9
6 3 7.5
denotes the 5x7 sparse matrix with 3 nonzeros:

The base offsets are assumed to be zero (ie. A[0][0] is the first element), but can be overridden by an optional base-offset. (see readfile(String, int).)

 o readfile
 public static CoordinateSparseMatrixDouble readfile(String s,
                                                     int base_offset) throws IOException
Reads sparse form file, similar to readfile(String) but has an optional base-offset parameter to denote the starting position of matrix indices. For example, a value of 1 denotes that the index pair "1 1" is the first element of the matrix. Typically, this value is zero for Java/C/C++ arrays.

This option is here mainly for compatibility with Matrix-Market files and other data formats that use 1-based offsets.

 o M
 public int M()
Return the first dimension of the sparse matrix.

 o N
 public int N()
Return the second dimension of the sparse matrix.

 o num_nonzeros
 public int num_nonzeros()
Return the number of number of nonzeros in sparse matrix.


All Packages  Class Hierarchy  This Package  Previous  Next  Index