![]() |
Prev | Next | sparse_rc_xam.pm | Headings |
package sparse_rc_xam; sub sparse_rc_xam() { # check for standard perl programming conventions use strict; use warnings; # # load the Cppad Swig library use pm_cppad; # # initilaize return variable my $ok = 1; # --------------------------------------------------------------------- # # create a sparsity pattern my $pattern = new pm_cppad::sparse_rc(); # my $nr = 6; my $nc = 5; my $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(my $k = 0; $k < $nnz; $k++) { $pattern->put($k, $k, $k+1); } # # row and column indices my $row = $pattern->row(); my $col = $pattern->col(); # # check row and column indices for(my $k = 0; $k < $nnz; $k++) { $ok = $ok && $row->get($k) == $k; $ok = $ok && $col->get($k) == $k+1; } # # For this case, row_major and col_major order are same as original order my $row_major = $pattern->row_major(); my $col_major = $pattern->col_major(); for(my $k = 0; $k < $nnz; $k++) { $ok = $ok && $row_major->get($k) == $k; $ok = $ok && $col_major->get($k) == $k; } # return( $ok ); }