From d92e9157cae98cba8f40e9506f2c7ad6519c49bd Mon Sep 17 00:00:00 2001 From: Julien Schueller Date: Fri, 25 Oct 2024 18:40:32 +0200 Subject: [PATCH] Fix warnings --- src/algs/ags/solver.cc | 4 ++-- src/algs/bobyqa/bobyqa.c | 6 +++--- src/algs/crs/crs.c | 4 ++-- src/algs/neldermead/nldrmd.c | 2 +- src/algs/stogo/tools.cc | 4 ++-- src/algs/stogo/tools.h | 2 +- src/api/nlopt-in.hpp | 8 ++++---- src/api/optimize.c | 2 +- src/util/timer.c | 4 ++-- 9 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/algs/ags/solver.cc b/src/algs/ags/solver.cc index 7ef24953..7eb08137 100644 --- a/src/algs/ags/solver.cc +++ b/src/algs/ags/solver.cc @@ -32,8 +32,8 @@ namespace const std::vector& leftBound, const std::vector& rightBound) { mFunctions = functions; - mConstraintsNumber = mFunctions.size() - 1; - mDimension = leftBound.size(); + mConstraintsNumber = static_cast(mFunctions.size() - 1); + mDimension = static_cast(leftBound.size()); mLeftBound = leftBound; mRightBound = rightBound; } diff --git a/src/algs/bobyqa/bobyqa.c b/src/algs/bobyqa/bobyqa.c index b8250194..0290abef 100644 --- a/src/algs/bobyqa/bobyqa.c +++ b/src/algs/bobyqa/bobyqa.c @@ -1979,12 +1979,12 @@ static nlopt_result bobyqb_(int *n, int *npt, double *x, int ksav; double gqsq, dist, sumw, sumz, diffa, diffb, diffc = 0.0, hdiag; int kbase; - double alpha, delta, adelt, denom, fsave, bdtol, delsq; + double alpha = 0.0, delta, adelt = 0.0, denom, fsave, bdtol, delsq; int nresc, nfsav; - double ratio, dnorm, vquad, pqold, tenth; + double ratio = 0.0, dnorm, vquad, pqold, tenth; int itest; double sumpq, scaden; - double errbig, cauchy, fracsq, biglsq, densav; + double errbig, cauchy = 0.0, fracsq, biglsq, densav; double bdtest; double crvmin, frhosq; double distsq; diff --git a/src/algs/crs/crs.c b/src/algs/crs/crs.c index c698d7d2..c74b4a8a 100644 --- a/src/algs/crs/crs.c +++ b/src/algs/crs/crs.c @@ -52,7 +52,7 @@ static int crs_compare(double *k1, double *k2) { if (*k1 < *k2) return -1; if (*k1 > *k2) return +1; - return k1 - k2; /* tie-breaker */ + return (int)(k1 - k2); /* tie-breaker */ } /* set x to a random trial value, as defined by CRS: @@ -67,7 +67,7 @@ static void random_trial(crs_data *d, double *x, rb_node *best) /* initialize x to x_0 = best point */ memcpy(x, best->k + 1, sizeof(double) * n); - i0 = (best->k - ps) / n1; + i0 = (int)((best->k - ps) / n1); jn = nlopt_iurand(n); /* which of remaining n points is "x_n", i.e. which to reflect through ... diff --git a/src/algs/neldermead/nldrmd.c b/src/algs/neldermead/nldrmd.c index ca868cce..6c1ce557 100644 --- a/src/algs/neldermead/nldrmd.c +++ b/src/algs/neldermead/nldrmd.c @@ -39,7 +39,7 @@ static int simplex_compare(double *k1, double *k2) { if (*k1 < *k2) return -1; if (*k1 > *k2) return +1; - return k1 - k2; /* tie-breaker */ + return (int)(k1 - k2); /* tie-breaker */ } /* return 1 if a and b are approximately equal relative to floating-point diff --git a/src/algs/stogo/tools.cc b/src/algs/stogo/tools.cc index ccc2139a..aa53adae 100644 --- a/src/algs/stogo/tools.cc +++ b/src/algs/stogo/tools.cc @@ -161,9 +161,9 @@ bool TBox::CloseToMin(RVector &vec, double *objval, double eps_cl) { return FALSE; } -unsigned int TBox::NStationary() { +int TBox::NStationary() { // Returns the number of trials in a box - return TList.size() ; + return static_cast(TList.size()); } void TBox::split(RTBox B1, RTBox B2) { diff --git a/src/algs/stogo/tools.h b/src/algs/stogo/tools.h index 608ae9f6..dd8dbafc 100644 --- a/src/algs/stogo/tools.h +++ b/src/algs/stogo/tools.h @@ -102,7 +102,7 @@ class TBox: public VBox { void ClearBox(); bool CloseToMin(RVector&, double*, double); - unsigned int NStationary(); // Returns the number of stationary points + int NStationary(); // Returns the number of stationary points void split(RTBox, RTBox); // Split a box void dispTrials(); diff --git a/src/api/nlopt-in.hpp b/src/api/nlopt-in.hpp index 2ee15df3..8fbddeaf 100644 --- a/src/api/nlopt-in.hpp +++ b/src/api/nlopt-in.hpp @@ -424,7 +424,7 @@ namespace nlopt { d->mf = mf; d->f_data = f_data; - mythrow(nlopt_add_inequality_mconstraint(o, tol.size(), mymfunc, d, + mythrow(nlopt_add_inequality_mconstraint(o, static_cast(tol.size()), mymfunc, d, tol.empty() ? NULL : &tol[0])); } @@ -453,7 +453,7 @@ namespace nlopt { d->mf = mf; d->f_data = f_data; - mythrow(nlopt_add_equality_mconstraint(o, tol.size(), mymfunc, d, + mythrow(nlopt_add_equality_mconstraint(o, static_cast(tol.size()), mymfunc, d, tol.empty() ? NULL : &tol[0])); } @@ -489,7 +489,7 @@ namespace nlopt { d->munge_destroy = md; d->munge_copy = mc; - mythrow(nlopt_add_inequality_mconstraint(o, tol.size(), mymfunc, d, + mythrow(nlopt_add_inequality_mconstraint(o, static_cast(tol.size()), mymfunc, d, tol.empty() ? NULL : &tol[0])); } void add_equality_mconstraint(mfunc mf, void *f_data, @@ -501,7 +501,7 @@ namespace nlopt { d->munge_destroy = md; d->munge_copy = mc; - mythrow(nlopt_add_equality_mconstraint(o, tol.size(), mymfunc, d, + mythrow(nlopt_add_equality_mconstraint(o, static_cast(tol.size()), mymfunc, d, tol.empty() ? NULL : &tol[0])); } diff --git a/src/api/optimize.c b/src/api/optimize.c index fe037bc8..8159309d 100644 --- a/src/api/optimize.c +++ b/src/api/optimize.c @@ -675,7 +675,7 @@ static nlopt_result nlopt_optimize_(nlopt_opt opt, double *x, double *minf) nlopt_set_ftol_abs(dual_opt, nlopt_get_param(opt, "dual_ftol_abs", LO(ftol_abs, 0.0))); nlopt_set_xtol_rel(dual_opt, nlopt_get_param(opt, "dual_xtol_rel", 0.0)); nlopt_set_xtol_abs1(dual_opt, nlopt_get_param(opt, "dual_xtol_abs", 0.0)); - nlopt_set_maxeval(dual_opt, nlopt_get_param(opt, "dual_maxeval", LO(maxeval, 100000))); + nlopt_set_maxeval(dual_opt, (int)nlopt_get_param(opt, "dual_maxeval", LO(maxeval, 100000))); #undef LO if (algorithm == NLOPT_LD_MMA) ret = mma_minimize(n, f, f_data, opt->m, opt->fc, lb, ub, x, minf, &stop, dual_opt, inner_maxeval, (unsigned)verbosity, rho_init, opt->dx); diff --git a/src/util/timer.c b/src/util/timer.c index 2319a08d..603c8739 100644 --- a/src/util/timer.c +++ b/src/util/timer.c @@ -51,7 +51,7 @@ double nlopt_seconds(void) gettimeofday(&tv, NULL); return (tv.tv_sec - start.tv_sec) + 1.e-6 * (tv.tv_usec - start.tv_usec); #elif defined(HAVE_TIME) - return time(NULL); + return (double)time(NULL); #elif defined(_WIN32) || defined(__WIN32__) static THREADLOCAL ULONGLONG start; FILETIME ft; @@ -82,7 +82,7 @@ unsigned long nlopt_time_seed(void) gettimeofday(&tv, NULL); return (tv.tv_sec ^ tv.tv_usec); #elif defined(HAVE_TIME) - return time(NULL); + return (unsigned long)time(NULL); #elif defined(_WIN32) || defined(__WIN32__) FILETIME ft; GetSystemTimeAsFileTime(&ft);