I am writting a c++ program in which I define a function $$\displaystyle F(t) = \sum_{i}r_i\,H(t-t_i)$$ where $H$ is the heaviside function, $t_i$ are optimal parameters which are mutable.

The program is derived by automatic differentiation using ADOL-C. I am wondering whether I should be careful when I am implementing the function $f$ regarding branching and looping.

I would create the function:

template <class Tdouble> Tdouble myfunF ( Tdouble t, Tdouble *tis, int nbti)
  Tdouble res = 0.; 
  double ri = 0.; 
  for(int id=0;i<nbti;++i)
    ri = ...;  
    if (t>ti){ 
      res = res + ri; 
  return res ;

The Tdouble type is similar to the adouble type in ADOL-C. How to analyze if this construction is suitable for automatic differentiation using ADOL-C and rewrite the code ?

  • 1
    $\begingroup$ yikesabee. Does any automatic differentiation package handle distributional derivatives correctly? (Only useful under an integral, right?) IIRC, Griewank only discusses non-differentiable functions like abs. $\endgroup$
    – user14717
    May 23, 2019 at 19:06

1 Answer 1


I used "condassign(a,b,c,d)" for branching in ADOL-C


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.