Commit 40108e63 authored by Kirill Terekhov's avatar Kirill Terekhov

More unit tests

parent f3e09d65
......@@ -15,11 +15,12 @@ endif(USE_MPI)
add_test(NAME autodiff_test000_hessian_sin COMMAND $<TARGET_FILE:autodiff_test000> 0)
add_test(NAME autodiff_test000_hessian_sin_mixed COMMAND $<TARGET_FILE:autodiff_test000> 1)
add_test(NAME autodiff_test000_hessian_cos_mixed COMMAND $<TARGET_FILE:autodiff_test000> 2)
add_test(NAME autodiff_test000_hessian_sin_of_poly COMMAND $<TARGET_FILE:autodiff_test000> 1)
add_test(NAME autodiff_test000_hessian_cos_of_poly COMMAND $<TARGET_FILE:autodiff_test000> 2)
add_test(NAME autodiff_test000_hessian_sin_mult COMMAND $<TARGET_FILE:autodiff_test000> 3)
add_test(NAME autodiff_test000_hessian_cos_mult COMMAND $<TARGET_FILE:autodiff_test000> 4)
add_test(NAME autodiff_test000_hessian_sqrt_mixed COMMAND $<TARGET_FILE:autodiff_test000> 5)
add_test(NAME autodiff_test000_hessian_poly COMMAND $<TARGET_FILE:autodiff_test000> 6)
add_test(NAME autodiff_test000_hessian_sin_poly COMMAND $<TARGET_FILE:autodiff_test000> 7)
add_test(NAME autodiff_test000_hessian_minus_sin_poly COMMAND $<TARGET_FILE:autodiff_test000> 8)
add_test(NAME autodiff_test000_hessian_const_minus_sin_of_poly COMMAND $<TARGET_FILE:autodiff_test000> 8)
add_test(NAME autodiff_test000_hessian_const_minus_cos_of_poly COMMAND $<TARGET_FILE:autodiff_test000> 9)
......@@ -155,7 +155,58 @@ int main(int argc,char ** argv)
_dydy = -(4*cos(2*((_x - 0.5)*(_x - 0.5) + (_y - 0.5)*(_y - 0.5))) - 16*(_y - 0.5)*(_y - 0.5)*sin(2.0*((_x - 0.5)*(_x - 0.5) + (_y - 0.5)*(_y - 0.5))));
f = 1.0-sin(2*((x-0.5)*(x-0.5)+(y-0.5)*(y-0.5)));
}
else if( test == 9 )
{
_dx = (4 *(_x - 0.5)*sin(2*((_x - 0.5)*(_x - 0.5) + (_y - 0.5)*(_y - 0.5))));
_dy = (4 *(_y - 0.5)*sin(2*((_x - 0.5)*(_x - 0.5) + (_y - 0.5)*(_y - 0.5))));
_dxdx = 4*sin(2*((_x - 0.5)*(_x - 0.5) + (_y - 0.5)*(_y - 0.5))) + 16*(_x - 0.5)*(_x - 0.5)*cos(2.0*((_x - 0.5)*(_x - 0.5) + (_y - 0.5)*(_y - 0.5)));
_dxdy = 32*(_x-0.5)*(_y-0.5)*cos(2*((_x-0.5)*(_x-0.5)+(_y-0.5)*(_y-0.5)));
_dydy = 4*sin(2*((_x - 0.5)*(_x - 0.5) + (_y - 0.5)*(_y - 0.5))) + 16*(_y - 0.5)*(_y - 0.5)*cos(2.0*((_x - 0.5)*(_x - 0.5) + (_y - 0.5)*(_y - 0.5)));
f = 1.0-cos(2*((x-0.5)*(x-0.5)+(y-0.5)*(y-0.5)));
}
else if( test == 10 )
{
_dx = sin(2*((_x-0.5)*(_x-0.5)+(_y-0.5)*(_y-0.5)))+4 *(_x - 0.5)*_x*cos(2*((_x - 0.5)*(_x - 0.5) + (_y - 0.5)*(_y - 0.5)));
_dy = 4 *_x*(_y - 0.5)*cos(2*((_x - 0.5)*(_x - 0.5) + (_y - 0.5)*(_y - 0.5)));
_dxdx = 8*(_x-0.5)*cos(2.0*((_x - 0.5)*(_x - 0.5) + (_y - 0.5)*(_y - 0.5))) + 4*_x*cos(2*((_x - 0.5)*(_x - 0.5) + (_y - 0.5)*(_y - 0.5))) - 16*_x*(_x - 0.5)*(_x - 0.5)*sin(2.0*((_x - 0.5)*(_x - 0.5) + (_y - 0.5)*(_y - 0.5)));
_dxdy = 8*(_y-0.5)*cos(2*((_x-0.5)*(_x-0.5)+(_y-0.5)*(_y-0.5)))-4*(_x-0.5)*_x*sin(2*((_x-0.5)*(_x-0.5)+(_y-0.5)*(_y-0.5)));
_dydy = 4*_x*cos(2*((_x-0.5)*(_x-0.5)+(_y-0.5)*(_y-0.5))) - 16*_x*(_y-0.5)*(_y-0.5)*sin(2*((_x-0.5)*(_x-0.5)+(_y-0.5)*(_y-0.5)));
f = sin(2*((x-0.5)*(x-0.5)+(y-0.5)*(y-0.5)))*x;
}
else if( test == 11 )
{
//f = sin(x)*y
//Expected Jacobian
// 0: y cos(x)
// 1: sin(x)
//Expected Hessian
// 0,0: -y*sin(x)
// 0,1: 2*cos(x)
// 1,1: 0
_dx = sin(_x*_x+_y) + 2*_x*_x*cos(_x*_x+_y);
_dy = _x*cos(_x*_x+_y);
_dxdx = 6*_x*cos(_x*_x+_y) - 4*_x*_x*_x*sin(_x*_x+_y);
_dxdy = 2*cos(_x*_x+_y) - 4*_x*_x*sin(_x*_x+_y);
_dydy = -_x*sin(_x*_x+_y);
f = sin(x*x+y)*x;
}
else if( test == 12 )
{
//f = sin(x)*y
//Expected Jacobian
// 0: y cos(x)
// 1: sin(x)
//Expected Hessian
// 0,0: -y*sin(x)
// 0,1: 2*cos(x)
// 1,1: 0
_dx = sin(_x*_x+_y*_y) + 2*_x*_x*cos(_x*_x+_y*_y);
_dy = 2*_x*_y*cos(_x*_x+_y*_y);
_dxdx = 6*_x*cos(_x*_x+_y*_y) - 4*_x*_x*_x*sin(_x*_x+_y*_y);
_dxdy = 4*_y*(cos(_x*_x+_y*_y) - 2*_x*_x*sin(_x*_x+_y*_y));
_dydy = 2*_x*(cos(_x*_x+_y*_y)-2*_y*_y*sin(_x*_x+_y*_y));
f = sin(x*x+y*y)*x;
}
double dx = f.GetRow()[0];
double dy = f.GetRow()[1];
double dxdx = f.GetHessianRow()[Sparse::HessianRow::make_index(0,0)];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment