Skip to content

Commit 73d7523

Browse files
authored
Merge pull request #1304 from boostorg/failing_jso_test
Try repair or remove two JSO tests
2 parents 309d95e + 8b1a03d commit 73d7523

4 files changed

Lines changed: 14 additions & 9 deletions

File tree

include/boost/math/optimization/jso.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ jso(const Func cost_function, jso_parameters<ArgumentContainer> &jso_params,
389389
throw std::logic_error(oss.str());
390390
}
391391
for (size_t i = 0; i < weights.size(); ++i) {
392-
weights[i] = delta_f[i] / delta_sum;
392+
weights[i] = static_cast<DimensionlessReal>(delta_f[i] / delta_sum);
393393
}
394394

395395
M_CR[k] = detail::weighted_lehmer_mean(S_CR, weights);

test/Jamfile.v2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1112,7 +1112,7 @@ test-suite interpolators :
11121112
[ run compile_test/interpolators_catmull_rom_concept_test.cpp compile_test_main : : : [ requires cxx11_hdr_array cxx11_hdr_initializer_list ] ]
11131113
[ run test_standalone_asserts.cpp ]
11141114
[ run differential_evolution_test.cpp : : : [ requires cxx17_if_constexpr cxx17_std_apply ] ]
1115-
[ run jso_test.cpp : : : [ requires cxx17_if_constexpr cxx17_std_apply ] ]
1115+
[ run jso_test.cpp : : : <toolset>clang:<cxxflags>-fno-fast-math <toolset>gcc:<cxxflags>-fno-fast-math <toolset>msvc:<cxxflags>/fp:precise [ requires cxx17_if_constexpr cxx17_std_apply ] ]
11161116
[ run random_search_test.cpp : : : [ requires cxx17_if_constexpr cxx17_std_apply ] ]
11171117
[ run cma_es_test.cpp : : : [ requires cxx17_if_constexpr cxx17_std_apply ] [ check-target-builds ../../multiprecision/config//has_eigen : : <build>no ] ]
11181118
[ compile compile_test/random_search_incl_test.cpp : [ requires cxx17_if_constexpr cxx17_std_apply ] ]

test/jso_test.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,21 @@ template <class Real> void test_ackley() {
5656
std::array<Real, 2> initial_guess{0, 0};
5757
jso_params.initial_guess = &initial_guess;
5858
local_minima = jso(ack, jso_params, gen);
59+
60+
#if (defined(BOOST_GCC) && ((BOOST_GCC >= 80000) && (BOOST_GCC < 90000)))
61+
using std::fabs;
62+
CHECK_LE(fabs(local_minima[0]), 128 * boost::math::tools::epsilon<Real>());
63+
CHECK_LE(fabs(local_minima[1]), 128 * boost::math::tools::epsilon<Real>());
64+
#else
5965
CHECK_EQUAL(local_minima[0], Real(0));
6066
CHECK_EQUAL(local_minima[1], Real(0));
67+
#endif
6168
}
6269

6370
template <class Real> void test_rosenbrock_saddle() {
6471
std::cout << "Testing jSO on Rosenbrock saddle . . .\n";
6572
using ArgType = std::array<Real, 2>;
66-
auto jso_params = jso_parameters<ArgType>();
73+
jso_parameters<ArgType> jso_params { };
6774
jso_params.lower_bounds = {0.5, 0.5};
6875
jso_params.upper_bounds = {2.048, 2.048};
6976
std::mt19937_64 gen(234568);
@@ -157,14 +164,12 @@ void test_dimensioned_sphere() {
157164
#endif
158165

159166
int main() {
160-
#if defined(__clang__) || defined(_MSC_VER)
161167
test_ackley<float>();
162168
test_ackley<double>();
163169
test_rosenbrock_saddle<double>();
164170
test_rastrigin<double>();
165171
test_three_hump_camel<float>();
166172
test_beale<double>();
167-
#endif
168173
#if BOOST_MATH_TEST_UNITS_COMPATIBILITY
169174
test_dimensioned_sphere();
170175
#endif

test/test_functions_for_optimization.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ template <typename Real> Real ackley(std::array<Real, 2> const &v) {
5252
return -20 * exp(arg1) - exp(arg2 / 2) + 20 + e<Real>();
5353
}
5454

55-
template <typename Real> auto rosenbrock_saddle(std::array<Real, 2> const &v) {
56-
auto x = v[0];
57-
auto y = v[1];
58-
return 100 * (x * x - y) * (x * x - y) + (1 - x) * (1 - x);
55+
template <typename Real> auto rosenbrock_saddle(std::array<Real, 2> const &v) -> Real {
56+
Real x { v[0] };
57+
Real y { v[1] };
58+
return static_cast<Real>(100 * (x * x - y) * (x * x - y) + (1 - x) * (1 - x));
5959
}
6060

6161

0 commit comments

Comments
 (0)