Skip to content

Commit c2284b4

Browse files
authored
Merge pull request #1306 from boostorg/more_warnings
Handle more conversion warnings
2 parents 73d7523 + 4d5ec95 commit c2284b4

7 files changed

Lines changed: 135 additions & 199 deletions

File tree

include/boost/math/special_functions/detail/lambert_w_lookup_table.ipp

Lines changed: 99 additions & 71 deletions
Large diffs are not rendered by default.

test/cma_es_test.cpp

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -146,18 +146,6 @@ void test_beale() {
146146
CHECK_ABSOLUTE_ERROR(Real(1)/Real(2), local_minima[1], Real(0.1));
147147
}
148148

149-
#if BOOST_MATH_TEST_UNITS_COMPATIBILITY
150-
void test_dimensioned_sphere() {
151-
std::cout << "Testing CMA-ES on dimensioned sphere . . .\n";
152-
using ArgType = std::vector<quantity<length>>;
153-
auto params = cma_es_parameters<ArgType>();
154-
params.lower_bounds.resize(4, -1.0*meter);
155-
params.upper_bounds.resize(4, 1*meter);
156-
std::mt19937_64 gen(56789);
157-
auto local_minima = cma_es(dimensioned_sphere, params, gen);
158-
}
159-
#endif
160-
161149
int main() {
162150
#if (defined(__clang__) || defined(_MSC_VER))
163151
test_ackley<float>();
@@ -166,9 +154,6 @@ int main() {
166154
test_rastrigin<double>();
167155
test_three_hump_camel<float>();
168156
test_beale<double>();
169-
#endif
170-
#if BOOST_MATH_TEST_UNITS_COMPATIBILITY
171-
test_dimensioned_sphere();
172157
#endif
173158
test_sphere();
174159
return boost::math::test::report_errors();

test/differential_evolution_test.cpp

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -188,19 +188,6 @@ void test_beale() {
188188
CHECK_ABSOLUTE_ERROR(Real(1)/Real(2), local_minima[1], Real(2e-4));
189189
}
190190

191-
#if BOOST_MATH_TEST_UNITS_COMPATIBILITY
192-
void test_dimensioned_sphere() {
193-
std::cout << "Testing differential evolution on dimensioned sphere . . .\n";
194-
using ArgType = std::vector<quantity<length>>;
195-
auto params = differential_evolution_parameters<ArgType>();
196-
params.lower_bounds.resize(4, -1.0*meter);
197-
params.upper_bounds.resize(4, 1*meter);
198-
params.threads = 2;
199-
std::mt19937_64 gen(56789);
200-
auto local_minima = differential_evolution(dimensioned_sphere, params, gen);
201-
}
202-
#endif
203-
204191
int main() {
205192

206193
#if defined(__clang__) || defined(_MSC_VER)
@@ -210,9 +197,6 @@ int main() {
210197
test_rastrigin<float>();
211198
test_three_hump_camel<float>();
212199
test_beale<double>();
213-
#endif
214-
#if BOOST_MATH_TEST_UNITS_COMPATIBILITY
215-
test_dimensioned_sphere();
216200
#endif
217201
test_sphere();
218202
test_parameter_checks();

test/jso_test.cpp

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,9 @@ template <class Real> void test_ackley() {
5757
jso_params.initial_guess = &initial_guess;
5858
local_minima = jso(ack, jso_params, gen);
5959

60-
#if (defined(BOOST_GCC) && ((BOOST_GCC >= 80000) && (BOOST_GCC < 90000)))
6160
using std::fabs;
6261
CHECK_LE(fabs(local_minima[0]), 128 * boost::math::tools::epsilon<Real>());
6362
CHECK_LE(fabs(local_minima[1]), 128 * boost::math::tools::epsilon<Real>());
64-
#else
65-
CHECK_EQUAL(local_minima[0], Real(0));
66-
CHECK_EQUAL(local_minima[1], Real(0));
67-
#endif
6863
}
6964

7065
template <class Real> void test_rosenbrock_saddle() {
@@ -150,29 +145,13 @@ void test_beale() {
150145
CHECK_ABSOLUTE_ERROR(Real(1)/Real(2), local_minima[1], Real(2e-4));
151146
}
152147

153-
#if BOOST_MATH_TEST_UNITS_COMPATIBILITY
154-
void test_dimensioned_sphere() {
155-
std::cout << "Testing jso on dimensioned sphere . . .\n";
156-
using ArgType = std::vector<quantity<length>>;
157-
auto params = jso_parameters<ArgType>();
158-
params.lower_bounds.resize(4, -1.0*meter);
159-
params.upper_bounds.resize(4, 1*meter);
160-
params.threads = 2;
161-
std::mt19937_64 gen(56789);
162-
auto local_minima = jso(dimensioned_sphere, params, gen);
163-
}
164-
#endif
165-
166148
int main() {
167149
test_ackley<float>();
168150
test_ackley<double>();
169151
test_rosenbrock_saddle<double>();
170152
test_rastrigin<double>();
171153
test_three_hump_camel<float>();
172154
test_beale<double>();
173-
#if BOOST_MATH_TEST_UNITS_COMPATIBILITY
174-
test_dimensioned_sphere();
175-
#endif
176155
test_sphere();
177156
test_weighted_lehmer_mean();
178157
return boost::math::test::report_errors();

test/random_search_test.cpp

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -151,21 +151,6 @@ void test_beale() {
151151
CHECK_ABSOLUTE_ERROR(Real(1)/Real(2), local_minima[1], Real(0.1));
152152
}
153153

154-
#if BOOST_MATH_TEST_UNITS_COMPATIBILITY
155-
void test_dimensioned_sphere() {
156-
std::cout << "Testing random search on dimensioned sphere . . .\n";
157-
using ArgType = std::vector<quantity<length>>;
158-
auto rs_params = random_search_parameters<ArgType>();
159-
rs_params.lower_bounds.resize(4, -1.0*meter);
160-
rs_params.upper_bounds.resize(4, 1*meter);
161-
rs_params.max_function_calls = 100000;
162-
rs_params.threads = 2;
163-
std::mt19937_64 gen(56789);
164-
auto local_minima = random_search(dimensioned_sphere, rs_params, gen);
165-
}
166-
167-
#endif
168-
169154
int main() {
170155
#if defined(__clang__) || defined(_MSC_VER)
171156
test_ackley<float>();
@@ -174,9 +159,6 @@ int main() {
174159
test_rastrigin<double>();
175160
test_three_hump_camel<float>();
176161
test_beale<double>();
177-
#endif
178-
#if BOOST_MATH_TEST_UNITS_COMPATIBILITY
179-
test_dimensioned_sphere();
180162
#endif
181163
test_sphere();
182164
return boost::math::test::report_errors();

test/test_bessel_j.hpp

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -285,15 +285,17 @@ void test_bessel(T, const char* name)
285285
SC_(0.3810550980268886849843356923521907577982), SC_(0.3648312306136669944635769493587219791343), SC_(0.3466185870197064968846647990300282094299)
286286
}};
287287

288-
const T tolerance { 128 * boost::math::tools::epsilon<T>() };
288+
using value_type = table_entry_type;
289+
290+
const value_type tolerance { 128 * boost::math::tools::epsilon<value_type>() };
289291

290292
int n_val { 9 };
291293

292-
for(const T& ctrl: ctrl_data)
294+
for(const value_type& ctrl: ctrl_data)
293295
{
294-
const T x_val { static_cast<T>(static_cast<T>(n_val) / 10) };
296+
const value_type x_val { static_cast<value_type>(static_cast<value_type>(n_val) / 10) };
295297

296-
const T jn_val { boost::math::cyl_bessel_j(3, x_val) };
298+
const value_type jn_val { boost::math::cyl_bessel_j(3, x_val) };
297299

298300
++n_val;
299301

@@ -303,39 +305,41 @@ void test_bessel(T, const char* name)
303305

304306
// More specific tests for Git-issue1292.
305307
{
306-
using local_ctrl_array_type = std::array<table_entry_type, std::size_t { UINT8_C(43) }>;
308+
using local_ctrl_array_type = std::array<table_entry_type, std::size_t { UINT8_C(43) }>;
309+
310+
// Table[N[BesselJ[31 / 10, n/10], 40], {n, 9, 51, 1}]
311+
static const local_ctrl_array_type ctrl_data =
312+
{{
313+
SC_(0.01175139795214295170487105485346781171863), SC_(0.01610092560641321584451701371378836908343), SC_(0.02135659148701787280713314897691402425560), SC_(0.02757316602094671775387912184375438913864),
314+
SC_(0.03479372470942323424236519547108889796879), SC_(0.04304884612770317349181083608393216357649), SC_(0.05235595486839477302545989170267853515412), SC_(0.06271881444009116864560457340917173135492),
315+
SC_(0.07412717428914531462554459978389560408816), SC_(0.08655657401374878955779092959288219537482), SC_(0.09996830657138141192006478769855556316995), SC_(0.1143095409011066041623799431143340837007),
316+
SC_(0.1295136029333754366226206053365805922136), SC_(0.1455004124749064242445094865982308151833), SC_(0.1621770719619318324763655518038365467780), SC_(0.1794386015949089605595848208470049166853),
317+
SC_(0.1971688139222575484595939469080319406355), SC_(0.2152413195483352761119610246805962611319), SC_(0.2335206543185642795903443565627832597552), SC_(0.2518635170977563283446184976264924077045),
318+
SC_(0.2701201061202457234361463802484836927464), SC_(0.2881355408650536940851830262098172944660), SC_(0.3057513555072237123913927136839853900197), SC_(0.3228070492275195774383850177821175151772),
319+
SC_(0.3391416780352496831991017115498371039332), SC_(0.3545954722799571667706920253581728149226), SC_(0.3690114637024459111815176585531943143085), SC_(0.3822371057078773326211699424651752096338),
320+
SC_(0.3941258705356621024731438508712990073773), SC_(0.4045388071531719615179931506197074798366), SC_(0.4133460440118967760814988295083688541739), SC_(0.4204282212729730452147271372029342292548),
321+
SC_(0.4256778377298582292448895379334671298297), SC_(0.4290004984236535775073755577697874033289), SC_(0.4303160498540635572666996674883665298558), SC_(0.4295595907277138677145484170304736319185),
322+
SC_(0.4266823473457215250850626209433240464185), SC_(0.4216524040030023831246842156638018726147), SC_(0.4144552801406973126588418824207056743782), SC_(0.4050943474472003316564108983454900189419),
323+
SC_(0.3935910816286283019261303507307813773886), SC_(0.3799851451515116989978414766085547417497), SC_(0.3643342988837623802358278078893847672838)
324+
}};
307325

308-
// Table[N[BesselJ[31 / 10, n/10], 40], {n, 9, 51, 1}]
309-
static const local_ctrl_array_type ctrl_data =
310-
{{
311-
SC_(0.01175139795214295170487105485346781171863), SC_(0.01610092560641321584451701371378836908343), SC_(0.02135659148701787280713314897691402425560), SC_(0.02757316602094671775387912184375438913864),
312-
SC_(0.03479372470942323424236519547108889796879), SC_(0.04304884612770317349181083608393216357649), SC_(0.05235595486839477302545989170267853515412), SC_(0.06271881444009116864560457340917173135492),
313-
SC_(0.07412717428914531462554459978389560408816), SC_(0.08655657401374878955779092959288219537482), SC_(0.09996830657138141192006478769855556316995), SC_(0.1143095409011066041623799431143340837007),
314-
SC_(0.1295136029333754366226206053365805922136), SC_(0.1455004124749064242445094865982308151833), SC_(0.1621770719619318324763655518038365467780), SC_(0.1794386015949089605595848208470049166853),
315-
SC_(0.1971688139222575484595939469080319406355), SC_(0.2152413195483352761119610246805962611319), SC_(0.2335206543185642795903443565627832597552), SC_(0.2518635170977563283446184976264924077045),
316-
SC_(0.2701201061202457234361463802484836927464), SC_(0.2881355408650536940851830262098172944660), SC_(0.3057513555072237123913927136839853900197), SC_(0.3228070492275195774383850177821175151772),
317-
SC_(0.3391416780352496831991017115498371039332), SC_(0.3545954722799571667706920253581728149226), SC_(0.3690114637024459111815176585531943143085), SC_(0.3822371057078773326211699424651752096338),
318-
SC_(0.3941258705356621024731438508712990073773), SC_(0.4045388071531719615179931506197074798366), SC_(0.4133460440118967760814988295083688541739), SC_(0.4204282212729730452147271372029342292548),
319-
SC_(0.4256778377298582292448895379334671298297), SC_(0.4290004984236535775073755577697874033289), SC_(0.4303160498540635572666996674883665298558), SC_(0.4295595907277138677145484170304736319185),
320-
SC_(0.4266823473457215250850626209433240464185), SC_(0.4216524040030023831246842156638018726147), SC_(0.4144552801406973126588418824207056743782), SC_(0.4050943474472003316564108983454900189419),
321-
SC_(0.3935910816286283019261303507307813773886), SC_(0.3799851451515116989978414766085547417497), SC_(0.3643342988837623802358278078893847672838)
322-
}};
326+
using value_type = table_entry_type;
323327

324-
const T tolerance { 128 * boost::math::tools::epsilon<T>() };
328+
const value_type tolerance { 128 * boost::math::tools::epsilon<value_type>() };
325329

326-
const T vu_val { static_cast<T>(static_cast<T>(31) / 10) };
330+
const value_type vu_val { static_cast<value_type>(static_cast<value_type>(31) / 10) };
327331

328-
int n_val { 9 };
332+
int n_val { 9 };
329333

330-
for(const T& ctrl : ctrl_data)
331-
{
332-
const T x_val { static_cast<T>(static_cast<T>(n_val) / 10) };
334+
for(const value_type& ctrl : ctrl_data)
335+
{
336+
const value_type x_val { static_cast<value_type>(static_cast<value_type>(n_val) / 10) };
333337

334-
const T jn_val { boost::math::cyl_bessel_j(vu_val, x_val) };
338+
const value_type jn_val { boost::math::cyl_bessel_j(vu_val, x_val) };
335339

336-
++n_val;
340+
++n_val;
337341

338-
BOOST_CHECK_CLOSE_FRACTION(jn_val, ctrl, tolerance);
342+
BOOST_CHECK_CLOSE_FRACTION(jn_val, ctrl, tolerance);
339343
}
340344
}
341345

test/test_functions_for_optimization.hpp

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,11 @@
66
*/
77
#ifndef TEST_FUNCTIONS_FOR_OPTIMIZATION_HPP
88
#define TEST_FUNCTIONS_FOR_OPTIMIZATION_HPP
9-
#include <array>
10-
#include <vector>
9+
1110
#include <boost/math/constants/constants.hpp>
12-
#if __has_include(<boost/units/systems/si/length.hpp>)
13-
// This is the only system boost.units still works on.
14-
// I imagine this will start to fail at some point,
15-
// and we'll have to remove this test as well.
16-
#if defined(__APPLE__)
17-
#define BOOST_MATH_TEST_UNITS_COMPATIBILITY 1
18-
#include <boost/units/systems/si/length.hpp>
19-
#include <boost/units/systems/si/area.hpp>
20-
#include <boost/units/cmath.hpp>
21-
#include <boost/units/quantity.hpp>
22-
#include <boost/units/systems/si/io.hpp>
23-
using namespace boost::units;
24-
using namespace boost::units::si;
2511

26-
// This *should* return an area, but see: https://github.com/boostorg/units/issues/58
27-
// This sadly prevents std::atomic<quantity<area>>.
28-
// Nonetheless, we *do* get some information making the argument type dimensioned,
29-
// even if it would be better to get the full information:
30-
double dimensioned_sphere(std::vector<quantity<length>> const & v) {
31-
quantity<area> r(0.0*meters*meters);
32-
for (auto const & x : v) {
33-
r += (x * x);
34-
}
35-
quantity<area> scale(1.0*meters*meters);
36-
return static_cast<double>(r/scale);
37-
}
38-
#endif
39-
#endif
12+
#include <array>
13+
#include <vector>
4014

4115
// Taken from: https://en.wikipedia.org/wiki/Test_functions_for_optimization
4216
template <typename Real> Real ackley(std::array<Real, 2> const &v) {

0 commit comments

Comments
 (0)