Hi,
I haven’t looked very closely to the code, but the first thing is that with floating points, the precision is going to be very very bad. All the tests we do for gradients are actually done in double precision to be sure.