![]() |
Prev | Next | sparse_rcv_xam.cpp | Headings |
# include <cstdio> # include <string> # include <cppad/swig/cppad_swig.hpp> bool sparse_rcv_xam(void) { using cppad_swig::a_double; using cppad_swig::vec_bool; using cppad_swig::vec_int; using cppad_swig::vec_double; using cppad_swig::vec_a_double; using cppad_swig::a_fun; using cppad_swig::sparse_rc; using cppad_swig::sparse_rcv; using cppad_swig::sparse_jac_work; using cppad_swig::sparse_hes_work; using std::string; // // initialize return variable bool ok = true; //------------------------------------------------------------------------ // // create sparsity pattern for n by n identity matrix sparse_rc pattern = cppad_swig::sparse_rc(); int n = 5; pattern.resize(n, n, n); for(int k = 0; k < n; k++) { pattern.put(k, k, k); } // // create n by n sparse representation of identity matrix sparse_rcv matrix = cppad_swig::sparse_rcv(pattern); for(int k = 0; k < n; k++) { matrix.put(k, 1.0); } // // row, column indices vec_int row = matrix.row(); vec_int col = matrix.col(); vec_double val = matrix.val(); // // check results for(int k = 0; k < n; k++) { ok = ok && row[k] == k; ok = ok && col[k] == k; ok = ok && val[k] == 1.0; } // // For this case, row_major and col_major order are same as original order vec_int row_major = matrix.row_major(); vec_int col_major = matrix.col_major(); for(int k = 0; k < n; k++) { ok = ok && row_major[k] == k; ok = ok && col_major[k] == k; } // return( ok ); }