Skip to content

Commit

Permalink
fixing warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobdenobel committed Feb 13, 2024
1 parent 88b85fd commit a00881b
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 23 deletions.
6 changes: 3 additions & 3 deletions include/ioh/common/container_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace ioh
* \return true if all elements of x == y
*/
template <typename T>
inline bool is_equal(const std::vector<T> &x, const std::vector<T> &y)
bool is_equal(const std::vector<T> &x, const std::vector<T> &y)
{
if (!(x.size() == y.size()))
return false;
Expand Down Expand Up @@ -150,8 +150,8 @@ namespace ioh
template<typename T>
std::vector<std::vector<T>> to_matrix(const std::vector<T>& v)
{
const size_t n = std::sqrt(v.size());
return to_matrix(v, n, n);
const size_t n = static_cast<size_t>(std::sqrt(v.size()));
return to_matrix<T>(v, n, n);
}

/**
Expand Down
9 changes: 8 additions & 1 deletion include/ioh/common/file.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ namespace ioh::common::file
*
* @return fs::path the absolute path of IOHexperimenter/static
*/

#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable : 4996)
#endif
inline fs::path get_static_root_by_env()
{
// First, try to use the IOH_RESOURCES environment variable
Expand All @@ -108,7 +113,9 @@ namespace ioh::common::file
std::cerr << "[get_static_root] Error: Neither IOH_RESOURCES nor GITHUB_WORKSPACE environment variables "
"are set.\n";
}

#if defined(_MSC_VER)
#pragma warning(pop)
#endif
/**
* @brief Get the absolute path of IOHexperimenter/static
*
Expand Down
25 changes: 13 additions & 12 deletions include/ioh/common/sampler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,23 @@ namespace ioh::common::random::sampler
static inline seed_type default_seed = 1993;

Uniform(const size_t n, const seed_type seed = default_seed, const T lb = 0, const T ub = 1) :
Sampler<T>(n, seed, lb, ub), gen((std::mt19937::result_type)seed), delta_g(gen.max() - gen.min()), delta(ub - lb)
Sampler<T>(n, seed, lb, ub), gen_(static_cast<std::mt19937::result_type>(seed)), delta_g_(std::mt19937::max() -
std::mt19937::min()), delta_(ub - lb)
{
}

virtual std::vector<T> next()
virtual std::vector<T> next() override
{
std::vector<T> res(this->n);
for (size_t i = 0; i < this->n; i++)
res[i] = (delta * (static_cast<double>(gen()) / delta_g)) + this->lb;
res[i] = (delta_ * (static_cast<T>(gen_()) / static_cast<T>(delta_g_))) + this->lb;
return res;
}

private:
std::mt19937 gen;
size_t delta_g;
T delta;
std::mt19937 gen_;
size_t delta_g_;
T delta_;
};


Expand All @@ -57,9 +58,9 @@ namespace ioh::common::random::sampler
{
}

virtual std::vector<double> next() {
virtual std::vector<double> next() override {
std::vector<double> data(n);
i8_sobol((int)n, &seed, data.data(), lb, ub);
i8_sobol(static_cast<int>(n), &seed, data.data(), lb, ub);
return data;
}
};
Expand All @@ -75,7 +76,7 @@ namespace ioh::common::random::sampler
primes.resize(n);
}

virtual std::vector<double> next()
virtual std::vector<double> next() override
{
std::vector<double> data(n);

Expand Down Expand Up @@ -114,12 +115,12 @@ namespace ioh::common::random::sampler
return primes;
}

inline double next_seq(int index, int base) const
{
static double next_seq(int index, const int base)
{
double y = 1., x = 0.;
while (index > 0)
{
auto dm = divmod(index, base);
const auto dm = divmod(index, base);
index = dm.first;
y *= static_cast<double>(base);
x += static_cast<double>(dm.second) / y;
Expand Down
2 changes: 1 addition & 1 deletion include/ioh/problem/cec/2022/hybrid_function_2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace ioh::problem::cec2022
{
y[i] = z[this->input_permutation_[i] - 1];
}

const int n = static_cast<int>(x.size());
int n_shaffer = n;
for (const auto gp : {0.1, 0.2, 0.2, 0.2, 0.1})
Expand Down
6 changes: 3 additions & 3 deletions tests/cpp/problem/test_cec2014.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "../utils.hpp"
#include "ioh/problem/cec.hpp"

TEST_F(BaseTest, CECProblem)
TEST_F(BaseTest, test_cec2014)
{
std::ifstream infile;
const auto file_path = ioh::common::file::utils::find_static_file("cec_problem2022.in");
Expand All @@ -19,15 +19,15 @@ TEST_F(BaseTest, CECProblem)
auto x = string_to_vector_double(tmp[2]);
auto f = stod(tmp[3]);

auto instance = problem_factory.create(func_id, ins_id, x.size());
auto instance = problem_factory.create(func_id, ins_id, static_cast<int>(x.size()));
auto y = (*instance)(x);
EXPECT_LE(abs(y - f) / f, 1.0 / pow(10, 6 - log(10)))
<< "The fitness of function " << func_id << "( ins "
<< ins_id << " ) is " << f << " ( not " << y << ").";
}
}

TEST_F(BaseTest, xopt_equals_yopt_cec)
TEST_F(BaseTest, xopt_equals_yopt_cec2014)
{
const auto& problem_factory = ioh::problem::ProblemRegistry<ioh::problem::CEC2022>::instance();
for (const auto& name : problem_factory.names())
Expand Down
6 changes: 3 additions & 3 deletions tests/cpp/problem/test_cec2022.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "../utils.hpp"
#include "ioh/problem/cec/2022.hpp"

TEST_F(BaseTest, CECProblem)
TEST_F(BaseTest, test_cec2022)
{
std::ifstream infile;
const auto file_path = ioh::common::file::utils::find_static_file("cec_problem2022.in");
Expand All @@ -19,15 +19,15 @@ TEST_F(BaseTest, CECProblem)
auto x = string_to_vector_double(tmp[2]);
auto f = stod(tmp[3]);

auto instance = problem_factory.create(func_id, ins_id, x.size());
auto instance = problem_factory.create(func_id, ins_id, static_cast<int>(x.size()));
auto y = (*instance)(x);
EXPECT_LE(abs(y - f) / f, 1.0 / pow(10, 6 - log(10)))
<< "The fitness of function " << func_id << "( ins "
<< ins_id << " ) is " << f << " ( not " << y << ").";
}
}

TEST_F(BaseTest, xopt_equals_yopt_cec)
TEST_F(BaseTest, xopt_equals_yopt_cec2022)
{
const auto& problem_factory = ioh::problem::ProblemRegistry<ioh::problem::CEC2022>::instance();
for (const auto& name : problem_factory.names())
Expand Down

0 comments on commit a00881b

Please sign in to comment.