[ADOL-C] Using ADOLC on a function performing an interpolation

Kshitij Kulshreshtha kshitij at math.upb.de
Fri Dec 7 10:44:59 EST 2012


Hello Pierre,

If you would consider trying out the latest developments in ADOL-C from svn

svn co https://projects.coin-or.org/svn/ADOL-C/trunk

There is a new class called advector which encapsulates arrays of adoubles.

I understand that your locate() function looks for the index i which has
the maximal value in x_tab less than x. And I suppose x_tab is a sorted
array. Is that correct?

You can write an ADOL-C version of locate as follows:

adouble locate(const adouble& ax, const advector& ax_tab) {
    adouble index = 0;
    for (int i=0; i < ax_tab.size(); i++)
       index += (ax > ax_tab[i]);
    return (index - 1.0);
}


Then you can call:

adouble i = locate(ax, ax_tab);

adouble ay =  ay_tab[i] +  (ay_tab[i+1] - ay_tab[i]) * (ax - ax_tab[i])
                   / (ax_tab[i+1] - ax_tab[i]);

This would not require any retaping as long as the size of ax_tab and
ay_tab remains the same.

I hope this helps.

Regards.
Kshitij Kulshreshtha.

As on 2012-12-07 15:50h, Pierre Martinon did write:
> Hi everyone,
> 
> I have been using AdolC in conjunction with Ipopt for some time, and
> recently came across a problem.
> I need to compute a basic linear 1D interpolation, which looks like
> 
> ----------------------------
> // Note: x is a Tdouble, x_tab and y_tab are double arrays
> 
> // find position of x in x_tab
> int i = locate(x,x_tab);
> 
> // perform linear interpolation
> Tdouble y = y_tab[i] +  (y_tab[i+1] - y_tab[i]) * (x - x_tab[i]) /
> (x_tab[i+1] - x_tab[i]);
> 
> ----------------------------
> 
> The problem is that the 'locate' function contains branching instructions.
> As the function is called tens of thousands of time, I don't think
> retaping is an option.
> Is there a way to tell AdolC to just ignore this function and consider
> the index 'i' as a constant ?
> If not, is there another way to write the interpolation so that AdolC
> can handle it ?
> 
> Thanks,
> Pierre Martinon
> _______________________________________________
> ADOL-C mailing list
> ADOL-C at list.coin-or.org
> http://list.coin-or.org/mailman/listinfo/adol-c

-- 
Dr. Kshitij Kulshreshtha

Institut für Mathematik,
Universität Paderborn,
Warburger Straße 100,
33098 Paderborn.

Büro: A3.235

Privatanschrift:
Arnikaweg 62
33100 Paderborn.


More information about the ADOL-C mailing list