Prev Next

@(@\newcommand{\B}[1]{ {\bf #1} } \newcommand{\R}[1]{ {\rm #1} }@)@
Sparsity Patterns

Syntax
pattern = module_ref sparse_rc()
pattern.resize(nrncnnz)
pattern.nr()
pattern.nc()
pattern.nnz()
pattern.put(krc)
row = pattern.row()
col = pattern.col()
row_major = pattern.row_major()
col_major = pattern.col_major()

module_ref
This is the module reference for the particular language.

pattern
The result has prototype
     sparse_rc 
pattern
It is used to hold a sparsity pattern for a matrix. The sparsity pattern is const except during its constructor, resize, and put.

nr
This argument has prototype
     int 
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
     int 
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
     int 
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 put.

put
This function sets the values
     
row[k] = r
     
col[k] = c
(The name set is used by Cppad, but not used here, because set it is a built-in name in Python.)

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

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

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

row
This result has type
     vec_int 
row
and its size is nnz . For k = 0, ...nnz-1 , row[k] is the row index for the k-th possibly non-zero entry in the matrix.

col
This result has type
     vec_int 
col
and its size is nnz . For k = 0, ...nnz-1 , col[k] is the column index for the k-th possibly non-zero entry in the matrix.

row_major
This vector has prototype
     vec_int 
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
     vec_int 
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
C++ , Octave , Perl , Python .
Input File: lib/sparse.cpp