Skip to content

Commit

Permalink
options: nlopt_set_xtol_abs check xtol_abs
Browse files Browse the repository at this point in the history
Closes #461
  • Loading branch information
jschueller committed Jul 4, 2022
1 parent 17826b8 commit 073e944
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/api/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,12 @@ GETSET(ftol_rel, double, ftol_rel) GETSET(ftol_abs, double, ftol_abs) GETSET(xto
{
if (opt) {
nlopt_unset_errmsg(opt);
if (!xtol_abs)
{
free(opt->xtol_abs);
opt->xtol_abs = NULL;
return NLOPT_SUCCESS;
}
if (!opt->xtol_abs && opt->n > 0) {
opt->xtol_abs = (double *) calloc(opt->n, sizeof(double));
if (!opt->xtol_abs) return NLOPT_OUT_OF_MEMORY;
Expand Down Expand Up @@ -738,6 +744,12 @@ nlopt_result NLOPT_STDCALL nlopt_set_x_weights(nlopt_opt opt, const double *x_we
if (opt) {
unsigned i;
nlopt_unset_errmsg(opt);
if (!x_weights)
{
free(opt->x_weights);
opt->x_weights = NULL;
return NLOPT_SUCCESS;
}
for (i = 0; i < opt->n; i++)
if (x_weights[i] < 0)
return ERR(NLOPT_INVALID_ARGS, opt, "invalid negative weight");
Expand Down

0 comments on commit 073e944

Please sign in to comment.