<div dir="ltr"><div><div><div><div><div><div><div><div><div><div><div>Hello,<br><br></div>I have a small program using Adol-c (adapted from the examples) to determine a sparse Hessian of a linear function using parameters with the new mkparam function.<br><br></div>I have notice that if I use the operator += in my model then my program will produce an incorrect sparsity pattern for the hessian.<br></div>If that operation is replaced with "x = x + ..." then it produces the correct result.<br></div>I've checked my program with valgrind and nothing came up.<br><br></div>I'm using adolc 2.6.0 in ubuntu 15.10.<br></div><br></div>Here is the example program:<br>//*************************************************************************************************<br><br>#include <adolc/adolc.h><br>#include <adolc/sparse/sparsedrivers.h><br><br>using namespace std;<br><br>#define tag 1<br><br>adouble feval_ad(adouble *x) {<br>    adouble res;<br><br>    res = 0;<br>    res += x[2] * x[0];<br>    res += x[3] * x[1];<br><br>    return res;<br>}<br><br>int main(int argc, char **argv) {<br>    int n = 2;<br>    std::vector<double> pars(2);<br>    int nx = n + pars.size();<br><br>    double f, x[nx];<br>    adouble fad, xad[nx];<br>    //double f, x[n];<br>    //adouble fad, xad[n];<br><br>    int i;<br><br>/****************************************************************************/<br>/*******                function evaluation                   ***************/<br>/****************************************************************************/<br><br>    for(i=0;i<n;i++)<br>        x[i] = log(1.0+i);<br><br>    /* Tracing of function f(x) */<br><br>    trace_on(tag);<br>    for(i=0;i<n;i++)<br>        xad[i] <<= x[i];<br><br>    for (i = n; i < nx; ++i) {<br>       xad[i] = ::mkparam(pars[i - n]);<br>    }<br><br>    fad = feval_ad(xad);<br><br>    fad >>= f;<br>    trace_off();<br><br>    printf("\n f = %e\n\n\n",f);<br><br><br>/****************************************************************************/<br>/*******       sparse Hessians, complete driver              ***************/<br>/****************************************************************************/<br><br>    /* coordinate format for Hessian */<br>    unsigned int    *rind  = NULL;<br>    unsigned int    *cind  = NULL;<br>    double *values = NULL;<br>    int nnz;<br>    int options[2];<br><br>    options[0] = 0;          /*                               safe mode (default) */<br>    options[1] = 0;          /*                       indirect recovery (default) */<br><br>    ::set_param_vec(tag, pars.size(), pars.data());<br><br>    sparse_hess(tag, n, 0, x, &nnz, &rind, &cind, &values, options);<br><br>    printf("In sparse format:\n");<br>    for (i=0;i<nnz;i++)<br>        printf("%2d %2d %10.6f\n\n",rind[i],cind[i],values[i]);<br><br>    free(rind); rind = NULL;<br>    free(cind); cind = NULL;<br>    free(values); values = NULL;<br>}<br>//*************************************************************************************************<br><br></div>It prints out:<br><br><br> f = 0.000000e+00<br><br><br>In sparse format:<br> 0  0   0.000000<br><br> 1  1   0.000000<br><br><br></div>But the hessian shouldn't have any elements.<br></div>Could anyone help me figure out the problem with my code?<br><br>Thanks for your help!<br><br></div><div>João Leal<br></div><div><div><div><br></div></div></div></div>