Prev Next sparse_rcv_xam.m Headings

@(@\newcommand{\B}[1]{ {\bf #1} } \newcommand{\R}[1]{ {\rm #1} }@)@
Octave: Sparsity Patterns: Example and Test
function ok = sparse_rcv_xam()
     %
     % load the Cppad Swig library
     m_cppad
     %
     % initialize return variable
     ok = true;
     % -----------------------------------------------------------------------
     %
     % create sparsity pattern for n by n identity matrix
     pattern = m_cppad.sparse_rc();
     n = 5;
     pattern.resize(n, n, n);
     for k = [ 0 :(n-1) ]
          pattern.put(k, k, k);
     end
     %
     % create n by n sparse representation of identity matrix
     matrix = m_cppad.sparse_rcv(pattern);
     for k = [ 0 :(n-1) ]
          matrix.put(k, 1.0);
     end
     %
     % row, column indices
     row = matrix.row();
     col = matrix.col();
     val = matrix.val();
     %
     % check results
     for k = [ 0 :(n-1) ]
          ok = ok && row(k) == k;
          ok = ok && col(k) == k;
          ok = ok && val(k) == 1.0;
     end
     %
     % 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 = [ 0 :(n-1) ]
          ok = ok && row_major(k) == k;
          ok = ok && col_major(k) == k;
     end
     %
     return;
end

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