Closed
Description
Hello, Thank you for open sourced this great project!
I'm trying to play with the reverse mode with some simple code on getting the Hessian of hypot
function. The result was not reasonable. Is there anything wrong on my code or how I should use the interface? Any help would be much appreciated.
Here are my sample code,
#include <autodiff/reverse/var.hpp>
#include <iostream>
using namespace autodiff;
int main() {
var x = 1.0;
var y = 1.0;
var u = hypot(x, y);
// var u = sqrt(x * x + y * y);
auto [ux, uy] = derivativesx(u, wrt(x, y));
auto [uxx, uxy] = derivativesx(ux, wrt(x, y));
auto [uyx, uyy] = derivativesx(uy, wrt(x, y));
std::cout << "u = " << u << std::endl;
std::cout << "ux = " << ux << "\nuy = " << uy << std::endl;
std::cout << "[uxx, uxy] = [" << uxx << ", " << uxy << "]\n"
<< "[uyx, uyy] = [" << uyx << ", " << uyy << "]" << std::endl;
}
And my result is,
u = 1.41421
ux = 0.707107
uy = 0.707107
[uxx, uxy] = [0.707107, 0]
[uyx, uyy] = [0, 0.707107]
While when I'm using var u = sqrt(x * x + y * y)
instead of var u = hypot(x, y)
, the result looks good as,
u = 1.41421
ux = 0.707107
uy = 0.707107
[uxx, uxy] = [0.353553, -0.353553]
[uyx, uyy] = [-0.353553, 0.353553]
Metadata
Metadata
Assignees
Labels
No labels