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}} }@)@
Row and Column Index Sparsity Patterns

Syntax
# include <cppad/utility/sparse_rc.hpp>
sparse_rc<SizeVector>  empty
sparse_rc<SizeVector>  pattern(nrncnnz)
target = pattern
resize(nrncnnz)
pattern.set(krc)
pattern.nr()
pattern.nc()
pattern.nnz()
const SizeVectorrowpattern.row() )
const SizeVectorcolpattern.col() )
row_major = pattern.row_major()
col_major = pattern.col_major()

SizeVector
We use SizeVector to denote SimpleVector class with elements of type size_t.

empty
This is an empty sparsity pattern. 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 object is used to hold a sparsity pattern for a matrix. The sparsity pattern is const except during its constructor, resize, and set.

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

nr
This argument has prototype
     size_t 
nr
It specifies the number of rows in the sparsity pattern. The function call nr() returns the value of nr .

nc
This argument has prototype
     size_t 
nc
It specifies the number of columns in the sparsity pattern. The function call nc() returns the value of nc .

nnz
This argument has prototype
     size_t 
nnz
It specifies the number of possibly non-zero index pairs in the sparsity pattern. The function call nnz() returns the value of nnz .

resize
The current sparsity pattern is lost and a new one is started with the specified parameters. The elements in the row and col vectors should be assigned using set.

set
This function sets the values
     
row[k] = r
     
col[k] = c

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

r
This argument has type
     size_t 
r
It specifies the value assigned to row[k] and must be less than nr .

c
This argument has type
     size_t 
c
It specifies the value assigned to col[k] and must be less than nc .

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

col
This vector has size nnz and col[k] is the column index of the k-th possibly non-zero index pair in the sparsity pattern.

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_rc.cpp contains an example and test of this class. It returns true if it succeeds and false otherwise.
Input File: cppad/utility/sparse_rc.hpp