Thanks for the thourogh explanation. I definitely need to write a few test cases to get familiar with the overall approach. I tried to implement the test for the F32
, and looks like it has some problems as you mentioned, or maybe I am missing something (also: probably we should move with this discussion somewhere else). I wrote a test for the function value and it fails to compile with
error: no matching function for call to 'F32(stan::math::fvar<double>&, double&, double&, double&, double&, double&)'
fvar<double> r = F32(a1,a2c,a3c,b1c,b2c,zc);
the test code being:
TEST(Fwd, F32) {
using stan::math::fvar;
using stan::math::F32;
using stan::math::exp;
fvar<double> a1(1.0, 1.0);
fvar<double> a2(1.0, 1.0);
fvar<double> a3(1.0, 1.0);
fvar<double> b1(1.0, 1.0);
fvar<double> b2(1.0, 1.0);
fvar<double> z(0.6, 1.0);
double a1c = 1.0;
double a2c = 1.0;
double a3c = 1.0;
double b1c = 1.0;
double b2c = 1.0;
double zc = 0.6;
fvar<double> r = F32(a1,a2c,a3c,b1c,b2c,zc);
EXPECT_FLOAT_EQ(F32(1.0,1.0,1.0,1.0,1.0,0.6), r.val_);
}
meaning that it can’t instantiate with different argument types or at least that is how I understand it?
Next, I tried to tackle the distance
function for the fwd mode, here is the full code. I would really appriciate some comments, to see if I’m on the right track. Well, this test also fails, the problem being the value of the derivative, if you set both argument values to be equal. As I understand, the explicit derivative d/dx1
of the distance function should be (x1-x2)/abs(x1-x2)
. Now, this should result in NaN
if you put the same value for x1
and x2
, but it results in the derivative being 0. Why is that?