Prev Next sparse_jac_fun.hpp Headings

@(@\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 .
Source: sparse_jac_fun
# ifndef CPPAD_SPARSE_JAC_FUN_HPP
# define CPPAD_SPARSE_JAC_FUN_HPP
# include <cppad/core/cppad_assert.hpp>
# include <cppad/utility/check_numeric_type.hpp>
# include <cppad/utility/vector.hpp>

// following needed by gcc under fedora 17 so that exp(double) is defined
# include <cppad/base_require.hpp>

namespace CppAD {
    template <class Float, class FloatVector>
    void sparse_jac_fun(
        size_t                       m    ,
        size_t                       n    ,
        const FloatVector&           x    ,
        const CppAD::vector<size_t>& row  ,
        const CppAD::vector<size_t>& col  ,
        size_t                       p    ,
        FloatVector&                 fp   )
    {
        // check numeric type specifications
        CheckNumericType<Float>();
        // check value of p
        CPPAD_ASSERT_KNOWN(
            p == 0 || p == 1,
            "sparse_jac_fun: p != 0 and p != 1"
        );
        size_t K = row.size();
        CPPAD_ASSERT_KNOWN(
            K >= m,
            "sparse_jac_fun: row.size() < m"
        );
        size_t i, j, k;

        if( p == 0 )
            for(i = 0; i < m; i++)
                fp[i] = Float(0);

        Float t;
        for(k = 0; k < K; k++)
        {   i    = row[k];
            j    = col[k];
            t    = exp( x[j] * x[j] / 2.0 );
            switch(p)
            {
                case 0:
                fp[i] += t;
                break;

                case 1:
                fp[k] = t * x[j];
                break;
            }
        }
    }
}
# endif

Input File: omh/sparse_jac_fun.omh