A.1.6.3 Using Sparse Matrices in Oct-Files

Most of the same operators and functions for sparse matrices that are available from the Octave interpreter are also available within oct-files. The basic means of extracting a sparse matrix from an octave_value, and returning it as an octave_value, can be seen in the following example.

octave_value_list retval;

SparseMatrix sm = args(0).sparse_matrix_value ();
SparseComplexMatrix scm = args(1).sparse_complex_matrix_value ();
SparseBoolMatrix sbm = args(2).sparse_bool_matrix_value ();
…
retval(2) = sbm;
retval(1) = scm;
retval(0) = sm;

The conversion to an octave_value is handled by the sparse octave_value constructors, and so no special care is needed.