Open TomSemblanet opened 3 years ago
The problem, and solution, for CppAD is described here: https://coin-or.github.io/CppAD/doc/pow_int.htm Note that CppAD uses types to distinguish the two cases (because c++ is a strongly typed language).
In python, where a variable might hold different types of values, I think it would be better to have a pow_int(x, y) function where x is an a_double and y is an int.
Would this be of use to you ?
Ok, I'll implement it thanks
I guess this means it would be of use to you (and others) so I will implement it.
Sorry ! Ok :)
My testing has turned up an interesting result. It seems that the way CppAD computes the derivatives of the logarithms works even for negative values; i.e., you should be getting the correct derivatives when the base is negative. The only problem is when the base is zero. Is this what you are seeing ?
The addition of the pow_int function should resolve this issue; see https://bradbell.github.io/cppad_py/doc/xsrst/a_double_binary.html#pow-int
The following example show the difference between the two power functions: https://bradbell.github.io/cppad_py/doc/xsrst/check_for_nan_xam_py.html
Please close this issue if this is satisfactory for you.
I use this code to compute the Jacobian of the function t_fun.
The following print output show that the computation of derivatives using
<variable>**<power>
doesn't work properly.Indeed, if I replace
return x**2
byreturn [x_**2 for x_ in x]
it still doesn't work but withreturn [x_*x_ for x_ in x]
it works well. Hope I can help to highlight some bugs.