Prev Next

@(@\newcommand{\W}[1]{ \; #1 \; } \newcommand{\R}[1]{ {\rm #1} } \newcommand{\B}[1]{ {\bf #1} } \newcommand{\D}[2]{ \frac{\partial #1}{\partial #2} } \newcommand{\DD}[3]{ \frac{\partial^2 #1}{\partial #2 \partial #3} } \newcommand{\Dpow}[2]{ \frac{\partial^{#1}}{\partial {#2}^{#1}} } \newcommand{\dpow}[2]{ \frac{ {\rm d}^{#1}}{{\rm d}\, {#2}^{#1}} }@)@This is cppad-20221105 documentation. Here is a link to its current documentation .
Convert A CppAD Sparse Matrix to an Eigen Sparse Matrix

Syntax
# include <cppad/utility/sparse2eigen.hpp>
sparse2eigen(sourcedestination)

Prototype

template <class SizeVector, class ValueVector, int Options>
void sparse2eigen(
const CppAD::sparse_rcv<SizeVector, ValueVector>&               source       ,
Eigen::SparseMatrix<typename ValueVector::value_type, Options>& destination  )

Include
If include_eigen is specified on the cmake command line, the file cppad/utility/sparse2eigen.hpp is included by cppad/cppad.hpp. In any case, it can also be included separately with out the rest of the CppAD routines. Including this file defines this version of the sparse2eigen within the CppAD namespace.

SizeVector
We use SizeVector to denote a SimpleVector class with elements of size_t.

ValueVector
We use ValueVector to denote a SimpleVector class with elements of type value_type .

Options
We use Options to denote either Eigen::RowMajor of Eigen::ColMajor.

value_type
The type of elements of elements in source and destination must be the same. We use value_type to denote this type.

source
This is the CppAD sparse matrix that is being converted to eigen format.

destination
This is the Eigen sparse matrix that is the result of the conversion.

Compressed
The result matrix destination is in compressed format. For example, let
    size_t 
           nnz       = source.nnz();
    const 
s_vector&   s_value   = source.val();
    const 
value_typed_value   = destination.valuePtr();
    const 
s_vector&   row_major = source.row_major();
    const 
s_vector&   col_major = source.col_major();
It follows that, for k = 0 , ...nnz : If Options is Eigen::RowMajor,
    
d_value[k] == s_valuerow_major[k] ]
If Options is Eigen::ColMajor,
    
d_value[k] == s_valuecol_major[k] ]

Example
The file sparse2eigen.cpp contains an example and test of sparse2eigen.cpp It return true if the test passes and false otherwise.
Input File: include/cppad/utility/sparse2eigen.hpp