Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change template function definition to support Visual Studio #22

Closed
MonkeyDied opened this issue Apr 2, 2019 · 9 comments
Closed

Change template function definition to support Visual Studio #22

MonkeyDied opened this issue Apr 2, 2019 · 9 comments

Comments

@MonkeyDied
Copy link

When compiling the mpc example using VS2013 on Win10, the following error occurred.

fatal error C1001: An internal error has occurred in the compiler.
(compiler file 'msc1.cpp', line 1325)
...

After some testing I found that it seems to be a problem with the template parsing for functions of the following form.
template<int n> ret_type some_function(Eigen::Matrix<c_float, n, 1>& arg)

This could be remedied by changing the definition to the following.
template<class T, int n> ret_type some_function(Eigen::Matrix<T, n, 1>& arg)

For example, in Data.hpp & Data.tpp, there is a function called setGradient. The current version and the suggested revised version are as follows.
/*current*/ template<int n> bool Data::setGradient(Eigen::Matrix<c_float, n, 1>& gradient)
/*suggest*/ template<class T, int n> bool Data::setGradient(Eigen::Matrix<T, n, 1>& gradient)

Below are all the functions I found to have the same problems.
For Data.hpp & Data.tpp
template<int n> bool Data::setGradient(Eigen::Matrix<c_float, n, 1>& gradientVector);
template<int m> bool setLowerBound(Eigen::Matrix<c_float, m, 1>& lowerBoundVector);
template<int m> bool setUpperBound(Eigen::Matrix<c_float, m, 1>& upperBoundVector);
For Solver.hpp & Solver.tpp
template<int n> bool updateGradient(Eigen::Matrix<c_float, n, 1>& gradient);
template<int m> bool updateLowerBound(Eigen::Matrix<c_float, m, 1>& lowerBound);
template<int m> bool updateUpperBound(Eigen::Matrix<c_float, m, 1>& upperBound);
template<int m> bool updateBounds(Eigen::Matrix<c_float, m, 1>& lowerBound, Eigen::Matrix<c_float, m, 1>& upperBound);

It would be nice if someone could help fix all the definitions.
Thx~

@GiulioRomualdi
Copy link
Member

GiulioRomualdi commented Apr 5, 2019

Hi @MonkeyDied, first of all, thanks for using osqp-eigen.
Regarding your question, I think that the problem is related to the template argument deduction. Can you copy-paste the lines of the code that cause the issue?

@MonkeyDied
Copy link
Author

@GiulioRomualdi The following are the definitions of the functions that cause the issue.

template<int n>
bool setGradient(Eigen::Matrix<c_float, n, 1> &gradientVector);

/**
* Set the array for lower bound (size m).
* @param lowerBoundVector is the lower bound constraint.
* @return true/false in case of success/failure.
*/
template<int m>
bool setLowerBound(Eigen::Matrix<c_float, m, 1>& lowerBoundVector);
/**
* Set the array for upper bound (size m).
* @param upperBoundVector is the upper bound constraint.
* @return true/false in case of success/failure.
*/
template<int m>
bool setUpperBound(Eigen::Matrix<c_float, m, 1>& upperBoundVector);

/**
* Update the linear part of the cost function (Gradient).
* @param gradient is the Gradient vector.
* @return true/false in case of success/failure.
*/
template<int n>
bool updateGradient(Eigen::Matrix<c_float, n, 1>& gradient);
/**
* Update the lower bounds limit (size m).
* @param lowerBound is the lower bound constraint vector.
* @return true/false in case of success/failure.
*/
template<int m>
bool updateLowerBound(Eigen::Matrix<c_float, m, 1>& lowerBound);
/**
* Update the upper bounds limit (size m).
* @param upperBound is the upper bound constraint vector.
* @return true/false in case of success/failure.
*/
template<int m>
bool updateUpperBound(Eigen::Matrix<c_float, m, 1>& upperBound);
/**
* Update both upper and lower bounds (size m).
* @param lowerBound is the lower bound constraint vector;
* @param upperBound is the upper bound constraint vector.
* @return true/false in case of success/failure.
*/
template<int m>
bool updateBounds(Eigen::Matrix<c_float, m, 1>& lowerBound,
Eigen::Matrix<c_float, m, 1>& upperBound);

@GiulioRomualdi
Copy link
Member

Hi @MonkeyDied, I was referring to your code 😃

@MonkeyDied
Copy link
Author

Hi @GiulioRomualdi , I encounter the problem when compiling the MPCExample using Visual Studio 2013 in Win10. The Eigen version is 3.3.5. osqp version is 0.5.0.

The following codes produce a compile time fatal error C1001 as described in the first post.
(The setLinearConstraintsMatrix function works fine)

if(!solver.data()->setGradient(gradient)) return 1;
if(!solver.data()->setLinearConstraintsMatrix(linearMatrix)) return 1;
if(!solver.data()->setLowerBound(lowerBound)) return 1;
if(!solver.data()->setUpperBound(upperBound)) return 1;

if(!solver.updateBounds(lowerBound, upperBound)) return 1;

@GiulioRomualdi
Copy link
Member

Can you try to edit the lines in the following way?

 if(!solver.data()->setGradient<Eigen::Dynamic>(gradient)) return 1; 
 if(!solver.data()->setLinearConstraintsMatrix(linearMatrix)) return 1; 
 if(!solver.data()->setLowerBound<Eigen::Dynamic>(lowerBound)) return 1; 
 if(!solver.data()->setUpperBound<Eigen::Dynamic>(upperBound)) return 1; 

and

 if(!solver.updateBounds<Eigen::Dynamic>(lowerBound, upperBound)) return 1; 

@MonkeyDied
Copy link
Author

Hi @GiulioRomualdi , that seems to solve the problem.

@GiulioRomualdi
Copy link
Member

Nice! I'll fix it!

@GiulioRomualdi
Copy link
Member

Hi @MonkeyDied this PR (#24 ) should solve your problem. Let me know if you have still problems.

@GiulioRomualdi
Copy link
Member

Fixed in #24

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants