Prev Next

@(@\newcommand{\B}[1]{ {\bf #1} } \newcommand{\R}[1]{ {\rm #1} }@)@
Sparse Matrices

Syntax
matrix    = cppad_py::sparse_rcv(pattern)
nr        = matrix.nr()
nc        = matrix.nc()
nnz       = matrix.nnz()
matrix.put(kv)
row       = matrix.row()
col       = matrix.col()
val       = matrix.val()
row_major = matrix.row_major()
col_major = matrix.col_major()

pattern
This argument has prototype
     const sparse_rc& 
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.

nr
This return value is an int and is the number of rows in the matrix.

nc
This return value is an int and is the number of columns in the matrix.

nnz
This return value is an int and is the number of possibly non-zero values in the matrix.

put
This function sets the value
     
val[k] = v
(The name set is used by Cppad, but not used here, because set it is a built-in name in Python.)

k
This is a non-negative int and must be less than nnz .

v
This argument has type float and specifies the value assigned to val[k] .

row
This result is a numpy vector with int elements 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 is a numpy vector with int elements 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.

val
This result is a numpy vector with float elements and its size is nnz . For k = 0, ...nnz-1 , val[k] is the value of the k-th possibly non-zero entry in the matrix (the value may be zero).

row_major
This result is a numpy vector with int elements 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 result is a numpy vector with int elements 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
sparse_rcv_xam.py
Input File: lib/python/sparse_rcv.py