# 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