You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've noticed that void nlopt::get_initial_step(std::vector<double> &v) and std::vector<double> nlopt::get_initial_step() are unusable in their current state. Right now, they always throw std::invalid_argument.
Description
I dug into the issue a little bit and it seems the issue is related to the overloads of get_initial_step that do not take an initial guess (these are also the overloads defined by the NLOPT_GETSET_VEC macro). These functions call this overload:
The issue is that the overload above provides an invalid argument to nlopt_get_initial_step, that argument being NULL. This argument is considered invalid because nlopt_get_initial_step frowards the NULL value to nlopt_set_default_initial_step:
Which will evaluate to true and propagate the error back up to the caller as a std::invalid_argument exception.
Proposed fix
My suggestion would be to remove the two problematic functions. Given that they do not work as is, I can't imagine removing the functions would negatively affect any users.
To remove the functions, I suggest removing the usage of the NLOPT_GETSET_VEC macro for initial_step and then manually defining the setters or, to be consistent with prior code, create a NLOPT_SET_VEC macro to define them for you.
Right, we should probably get rid of that get function, and replace it with a call to get_initial_step_ which allocates the result.
Note, however, that there is a usable getter function get_initial_step(const std::vector<double> &x, std::vector<double> &dx) where you pass an array dx to hold the result. This one is documented in the manual.
I fixed the documentation in 596799b to only document the functional method for now.
I've noticed that
void nlopt::get_initial_step(std::vector<double> &v)
andstd::vector<double> nlopt::get_initial_step()
are unusable in their current state. Right now, they always throwstd::invalid_argument
.Description
I dug into the issue a little bit and it seems the issue is related to the overloads of
get_initial_step
that do not take an initial guess (these are also the overloads defined by theNLOPT_GETSET_VEC
macro). These functions call this overload:nlopt/src/api/nlopt-in.hpp
Lines 41 to 43 in b2caea2
The issue is that the overload above provides an invalid argument to
nlopt_get_initial_step
, that argument beingNULL
. This argument is considered invalid becausenlopt_get_initial_step
frowards theNULL
value tonlopt_set_default_initial_step
:nlopt/src/api/options.c
Line 892 in b2caea2
within the same function, a few lines down,
nlopt/src/api/options.c
Line 901 in b2caea2
And within
nlopt_set_default_initial_step
, there is this check:nlopt/src/api/options.c
Lines 918 to 919 in b2caea2
Which will evaluate to true and propagate the error back up to the caller as a
std::invalid_argument
exception.Proposed fix
My suggestion would be to remove the two problematic functions. Given that they do not work as is, I can't imagine removing the functions would negatively affect any users.
To remove the functions, I suggest removing the usage of the
NLOPT_GETSET_VEC
macro forinitial_step
and then manually defining the setters or, to be consistent with prior code, create aNLOPT_SET_VEC
macro to define them for you.In other words, replace,
nlopt/src/api/nlopt-in.hpp
Line 580 in b2caea2
with,
Option 1 (manual definition):
or,
Option 2 (macro):
If you go with Option 2, you might as well update the
NLOPT_GETSET_VEC
macro to the following,Additionally, relevant documentation should be updated.
The text was updated successfully, but these errors were encountered: