Prev Next

@(@\newcommand{\W}[1]{ \; #1 \; } \newcommand{\R}[1]{ {\rm #1} } \newcommand{\B}[1]{ {\bf #1} } \newcommand{\D}[2]{ \frac{\partial #1}{\partial #2} } \newcommand{\DD}[3]{ \frac{\partial^2 #1}{\partial #2 \partial #3} } \newcommand{\Dpow}[2]{ \frac{\partial^{#1}}{\partial {#2}^{#1}} } \newcommand{\dpow}[2]{ \frac{ {\rm d}^{#1}}{{\rm d}\, {#2}^{#1}} }@)@
Sparse Matrix Row, Column, Value Representation

Syntax
# include <cppad/utility/sparse_rcv.hpp>
sparse_rcv<SizeVectorValueVector>  empty
sparse_rcv<SizeVectorValueVector>  matrix(pattern)
target = matrix
matrix.set(kv)
nr = matrix.nr()
nc = matrix.nc()
nnz = matrix.nnz()
const SizeVectorrowmatrix.row() )
const SizeVectorcolmatrix.col() )
const ValueVectorvalmatrix.val() )
row_major = matrix.row_major()
col_major = matrix.col_major()

SizeVector
We use SizeVector to denote the SimpleVector class corresponding to pattern .

ValueVector
We use ValueVector to denote the SimpleVector class corresponding to val .

empty
This is an empty sparse matrix object. To be specific, the corresponding number of rows nr , number of columns nc , and number of possibly non-zero values nnz , are all zero.

pattern
This argument has prototype
     const sparse_rc<
SizeVector>& pattern
It specifies the number of rows, number of columns and the possibly non-zero entries in the matrix .

matrix
This is a sparse matrix object with the sparsity specified by pattern . Only the val vector can be changed. All other values returned by matrix are fixed during the constructor and constant there after. The val vector is only changed by the constructor and the set function. There is one exception to the rule, where matrix corresponds to target for an assignment statement.

target
The target of the assignment statement must have prototype
     sparse_rcv<
SizeVectorValueVector>  target
After this assignment statement, target is an independent copy of matrix ; i.e. it has all the same values as matrix and changes to target do not affect matrix .

nr
This return value has prototype
     size_t 
nr
and is the number of rows in matrix .

nc
This argument and return value has prototype
     size_t 
nc
and is the number of columns in matrix .

nnz
We use the notation nnz to denote the number of possibly non-zero entries in matrix .

set
This function sets the value
     
val[k] = v

k
This argument has type
     size_t 
k
and must be less than nnz .

v
This argument has type
     const 
ValueVector::value_type& v
It specifies the value assigned to val[k] .

row
This vector has size nnz and row[k] is the row index of the k-th possibly non-zero element in matrix .

col
This vector has size nnz and col[k] is the column index of the k-th possibly non-zero element in matrix

val
This vector has size nnz and val[k] is value of the k-th possibly non-zero entry in the sparse matrix (the value may be zero).

row_major
This vector has prototype
     
SizeVector row_major
and its size nnz . It sorts the sparsity pattern in row-major order. To be specific,
     
colrow_major[k] ] <= colrow_major[k+1] ]
and if colrow_major[k] ] == colrow_major[k+1] ] ,
     
rowrow_major[k] ] < rowrow_major[k+1] ]
This routine generates an assert if there are two entries with the same row and column values (if NDEBUG is not defined).

col_major
This vector has prototype
     
SizeVector col_major
and its size nnz . It sorts the sparsity pattern in column-major order. To be specific,
     
rowcol_major[k] ] <= rowcol_major[k+1] ]
and if rowcol_major[k] ] == rowcol_major[k+1] ] ,
     
colcol_major[k] ] < colcol_major[k+1] ]
This routine generates an assert if there are two entries with the same row and column values (if NDEBUG is not defined).

Example
The file sparse_rcv.cpp contains an example and test of this class. It returns true if it succeeds and false otherwise.
Input File: cppad/utility/sparse_rcv.hpp