Prev Next sparse_rc_xam.m Headings

@(@\newcommand{\B}[1]{ {\bf #1} } \newcommand{\R}[1]{ {\rm #1} }@)@
Octave: Sparsity Patterns: Example and Test
function ok = sparse_rc_xam()
     %
     % load the Cppad Swig library
     m_cppad
     %
     % initialize return variable
     ok = true;
     % -----------------------------------------------------------------------
     %
     % create a sparsity pattern
     pattern = m_cppad.sparse_rc();
     %
     nr = 6;
     nc = 5;
     nnz = 4;
     %
     % resize
     pattern.resize(nr, nc, nnz);
     %
     ok = ok && pattern.nr()  == nr ;
     ok = ok && pattern.nc()  == nc ;
     ok = ok && pattern.nnz() == nnz ;
     %
     % indices corresponding to upper-diagonal
     for k = [ 0 :(nnz-1) ]
          pattern.put(k, k, k+1);
     end
     %
     % row and column indices
     row = pattern.row();
     col = pattern.col();
     %
     % check row and column indices
     for k = [ 0 :(nnz-1) ]
          ok = ok && row(k) == k;
          ok = ok && col(k) == k+1;
     end
     %
     % 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 = [ 0 :(nnz-1) ]
          ok = ok && row_major(k) == k;
          ok = ok && col_major(k) == k;
     end
     %
     return;
end

Input File: build/lib/example/octave/sparse_rc_xam.m