1 # ifndef CPPAD_SPEED_SPARSE_HES_FUN_HPP
2 # define CPPAD_SPEED_SPARSE_HES_FUN_HPP
175 template <
class Float,
class FloatVector>
178 const FloatVector& x ,
185 CheckNumericType<Float>();
190 "sparse_hes_fun: p != 0 and p != 2"
193 size_t K = row.
size();
198 {
for(k = 0; k < K; k++)
204 for(i = 0; i < n; i++)
206 for(k = 0; k < K; k++)
207 {
if( row[k] == col[k] )
210 diagonal[ row[k] ] = k;
216 for(k = 0; k < K; k++)
217 { factor[k] = Float(1);
218 for(
size_t k1 = 0; k1 < K; k1++)
219 {
bool reflected =
true;
220 reflected &= k != k1;
221 reflected &= row[k] != col[k];
222 reflected &= row[k] == col[k1];
223 reflected &= col[k] == row[k1];
225 factor[k] = Float(2);
230 for(k = 0; k < K; k++)
233 t =
exp( x[i] * x[j] );
243 fp[k] += ( Float(2) + Float(4) * x[i] * x[i] ) * t;
247 fp[k] += factor[k] * ( Float(1) + x[i] * x[j] ) * t;
248 if( diagonal[i] != K )
249 {
size_t ki = diagonal[i];
250 fp[ki] += x[j] * x[j] * t;
252 if( diagonal[j] != K )
253 {
size_t kj = diagonal[j];
254 fp[kj] += x[i] * x[i] * t;
#define CPPAD_ASSERT_KNOWN(exp, msg)
Check that exp is true, if not print msg and terminate execution.
void sparse_hes_fun(size_t n, const FloatVector &x, const CppAD::vector< size_t > &row, const CppAD::vector< size_t > &col, size_t p, FloatVector &fp)
Define the CppAD error checking macros (all of which begin with CPPAD_ASSERT_)
AD< Base > exp(const AD< Base > &x)
size_t size(void) const
number of elements currently in this vector.
#define CPPAD_ASSERT_UNKNOWN(exp)
Check that exp is true, if not terminate execution.
File used to define CppAD::vector and CppAD::vectorBool.