Prev Next sparse_rc_xam.py Headings

@(@\newcommand{\B}[1]{ {\bf #1} } \newcommand{\R}[1]{ {\rm #1} }@)@
Python: Sparsity Patterns: Example and Test
def sparse_rc_xam() :
     #
     # load the Cppad Swig library
     import py_cppad
     #
     # initialize return variable
     ok = True
     # ---------------------------------------------------------------------
     #
     # create a sparsity pattern
     pattern = py_cppad.sparse_rc()
     #
     nr = 6
     nc = 5
     nnz = 4
     #
     # resize
     pattern.resize(nr, nc, nnz)
     #
     ok = ok and pattern.nr()  == nr 
     ok = ok and pattern.nc()  == nc 
     ok = ok and pattern.nnz() == nnz 
     #
     # indices corresponding to upper-diagonal
     for k in range( nnz ) :
          pattern.put(k, k, k+1)
     #
     #
     # row and column indices
     row = pattern.row()
     col = pattern.col()
     #
     # check row and column indices
     for k in range( nnz ) :
          ok = ok and row[k] == k
          ok = ok and col[k] == k+1
     #
     #
     # For this case, row_major and col_major order are same as original order
     row_major = pattern.row_major()
     col_major = pattern.col_major()
     for k in range( nnz ) :
          ok = ok and row_major[k] == k
          ok = ok and col_major[k] == k
     #
     #
     return( ok )
#

Input File: build/lib/example/python/sparse_rc_xam.py