autodiff icon indicating copy to clipboard operation
autodiff copied to clipboard

Error in meta.hpp

Open bharswami opened this issue 1 year ago • 7 comments

template<typename Fun, typename... Args> using ReturnType = std::invoke_result_t<Fun, Args...>;

**Severity Code Description Project File Line Suppression State Details Error C2039 'invoke_result_t': is not a member of 'std' jacobian_autodiff_test Line 65 **

I am not sure what the error is due to. But I didn't use the path for Eigen3, I used eigen headers from the root directory of the source code available in the eigen website.

bharswami avatar Jun 09 '24 13:06 bharswami

Hi, thanks for reporting this issue. Please provide more details - I cannot reproduce this issue here. Are you using the cmake build system of autodiff? Are you using c++-17 or higher?

allanleal avatar Jun 10 '24 08:06 allanleal

Yes. That was the issue. The C++ standard in my VS was set to C++ 14. I changed it to the latest and that worked. What about the time complexity of the Jacobian computation that I am trying? For m functions and n variables, it is O(m*n)?

bharswami avatar Jun 10 '24 11:06 bharswami

For the order discussion, see here https://github.com/autodiff/autodiff/discussions/341#discussioncomment-9726508

allanleal avatar Jun 10 '24 11:06 allanleal

Can you please have a look at the code below? I have implemented Jacobian (same as one of the examples) inside a class member function and it seems to throw errors. Severity Code Description Project File Line Suppression State Details Error C3867 'myClass::f': non-standard syntax; use '&' to create a pointer to member jacobian_autodiff_test Severity Code Description Project File Line Suppression State Details Error C2672 'jacobian': no matching overloaded function found jacobian_autodiff_test

// C++ includes #include // autodiff include #include <autodiff/forward/real.hpp> #include <autodiff/forward/real/eigen.hpp> using Eigen::MatrixXd; using namespace autodiff; class myClass { public: // The vector function with parameters for which the Jacobian is needed VectorXreal f(const VectorXreal& x, const VectorXreal& p, const real& q) { return x * p.sum() * exp(q); } void calcJac() {

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

MatrixXd Jx = jacobian(f, wrt(x), at(x, p, q), F);         // evaluate the function and the Jacobian matrix Jx = dF/dx
MatrixXd Jp = jacobian(f, wrt(p), at(x, p, q), F); // evaluate the function and the Jacobian matrix Jp = dF/dp
MatrixXd Jq = jacobian(f, wrt(q), at(x, p, q), F);         // evaluate the function and the Jacobian matrix Jq = dF/dq
MatrixXd Jqpx = jacobian(f, wrt(q, p, x), at(x, p, q), F); // evaluate the function and the Jacobian matrix Jqpx = [dF/dq, dF/dp, dF/dx]

std::cout << "F = \n"
          << F << std::endl; // print the evaluated output vector F
std::cout << "Jx = \n"
          << Jx(0) << std::endl; // print the evaluated Jacobian matrix dF/dx
std::cout << "Jp = \n"
          << Jp << std::endl; // print the evaluated Jacobian matrix dF/dp
std::cout << "Jq = \n"
          << Jq << std::endl; // print the evaluated Jacobian matrix dF/dq
std::cout << "Jqpx = \n"
          << Jqpx << std::endl; // print the evaluated Jacobian matrix [dF/dq, dF/dp, dF/dx]

} }; int main() { myClass mC; mC.calcJac(); return 0; }

bharswami avatar Jun 11 '24 09:06 bharswami

I think you need to make myClass::f() static, so it doesn't expect this as the first argument, and pass it to jacobian as &myClass::f.

yut23 avatar Jun 13 '24 20:06 yut23

Also see https://github.com/autodiff/autodiff/discussions/261#discussioncomment-3989220

yut23 avatar Jun 13 '24 20:06 yut23

Yes. That was the issue. The C++ standard in my VS was set to C++ 14. I changed it to the latest and that worked. What about the time complexity of the Jacobian computation that I am trying? For m functions and n variables, it is O(m*n)?

I also have this error. And i am sure i have set c++17 +. But it has error ,too. Tht error is :namespace "std" has no member "invoke_result_t"

xiaowu1018 avatar Jul 04 '24 08:07 xiaowu1018