Prev Next sparse_rcv_xam.py Headings

@(@\newcommand{\B}[1]{ {\bf #1} } \newcommand{\R}[1]{ {\rm #1} }@)@
Python: Sparsity Patterns: Example and Test
def sparse_rcv_xam() :
     #
     # load the Cppad Swig library
     import py_cppad
     #
     # initialize return variable
     ok = True
     # ---------------------------------------------------------------------
     #
     # create sparsity pattern for n by n identity matrix
     pattern = py_cppad.sparse_rc()
     n = 5
     pattern.resize(n, n, n)
     for k in range( n ) :
          pattern.put(k, k, k)
     #
     #
     # create n by n sparse representation of identity matrix
     matrix = py_cppad.sparse_rcv(pattern)
     for k in range( n ) :
          matrix.put(k, 1.0)
     #
     #
     # row, column indices
     row = matrix.row()
     col = matrix.col()
     val = matrix.val()
     #
     # check results
     for k in range( n ) :
          ok = ok and row[k] == k
          ok = ok and col[k] == k
          ok = ok and val[k] == 1.0
     #
     #
     # For this case, row_major and col_major order are same as original order
     row_major = matrix.row_major()
     col_major = matrix.col_major()
     for k in range( n ) :
          ok = ok and row_major[k] == k
          ok = ok and col_major[k] == k
     #
     #
     return( ok )
#

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