Use of autodiff inside of classes and with class methods. #261
Unanswered
anthony-walker
asked this question in
Q&A
Replies: 1 comment
-
Hi @anthony-walker , please try the following (I could not test at the moment, but this should give you an idea of what to do instead). Eigen::MatrixXd scratch::jac()
{
VectorXreal x(5); // the input vector x with 5 variables
x << 1, 2, 3, 4, 5; // x = [1, 2, 3, 4, 5]
VectorXreal p(3); // the input parameter vector p with 3 variables
p << 1, 2, 3; // p = [1, 2, 3]
real q = -2; // the input parameter q as a single variable
VectorXreal F; // the output vector F = f(x, p, q) evaluated together with Jacobian below
auto fun = [&](const VectorXreal& x, const VectorXreal& p, const real& q) -> VectorXreal
{
return f(x, p, q);
};
Eigen::MatrixXd Jx = jacobian(fun, wrt(x), at(x, p, q), F); // evaluate the function and the Jacobian matrix Jx = dF/dx
Eigen::MatrixXd Jp = jacobian(fun, wrt(p), at(x, p, q), F); // evaluate the function and the Jacobian matrix Jp = dF/dp
Eigen::MatrixXd Jq = jacobian(fun, wrt(q), at(x, p, q), F); // evaluate the function and the Jacobian matrix Jq = dF/dq
Eigen::MatrixXd Jqpx = jacobian(fun, wrt(q, p, x), at(x, p, q), F); // evaluate the function and the Jacobian matrix Jqpx = [dF/dq, dF/dp, dF/dx]
return Jqpx;
} As you see above, you create a lambda function |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am trying to use
autodiff
inside of a class. So, I took one of the examples and adapted it to the class below. However, this seems to be an issue and references a deleted function. Compiling the following code with followingg++
statement give the error. Is there any way around this?Beta Was this translation helpful? Give feedback.
All reactions