Commit cb886426 authored by Konstantinos Chatzilygeroudis's avatar Konstantinos Chatzilygeroudis
Browse files

Code to remove warnings in clang and g++. Fix in random sampling

parent d56b128d
......@@ -2287,7 +2287,7 @@ long random_init(random_t* t, long unsigned inseed)
if (inseed < 1) {
while ((long)(cloc - clock()) == 0)
; /* TODO: remove this for time critical applications? */
inseed = (long unsigned)abs((long)(100 * time(NULL) + clock()));
inseed = (long unsigned)labs((long)(100 * time(NULL) + clock()));
}
return random_Start(t, inseed);
}
......@@ -2670,7 +2670,7 @@ void readpara_SupplementDefaults(readpara_t* t)
if (t->seed < 1) {
while ((int)(cloc - clock()) == 0)
; /* TODO: remove this for time critical applications!? */
t->seed = (unsigned int)abs((long)(100 * time(NULL) + clock()));
t->seed = (unsigned int)labs((long)(100 * time(NULL) + clock()));
}
if (t->stStopFitness.flg == -1)
......
......@@ -88,7 +88,7 @@ double ehvi3d_2term(deque<individual*> P, double r[], double mu[],
double Sminus; // Correction term for the integral.
deque<individual*> Py, Pz; // P sorted by y/z coordinate
sort(P.begin(), P.end(), ycomparator);
for (int i = 0; i < P.size(); i++) {
for (size_t i = 0; i < P.size(); i++) {
Py.push_back(P[i]);
}
sort(P.begin(), P.end(), zcomparator);
......@@ -145,7 +145,7 @@ double ehvi3d_5term(deque<individual*> P, double r[], double mu[],
double Sminus; // Correction term for the integral.
deque<individual*> Py, Pz; // P sorted by y/z coordinate
sort(P.begin(), P.end(), ycomparator);
for (int i = 0; i < P.size(); i++) {
for (size_t i = 0; i < P.size(); i++) {
Py.push_back(P[i]);
}
sort(P.begin(), P.end(), zcomparator);
......@@ -231,7 +231,7 @@ double ehvi3d_8term(deque<individual*> P, double r[], double mu[],
tempimp; // Correction term, rectangular volume, temp. improvement
deque<individual*> Py, Pz; // P sorted by y/z coordinate
sort(P.begin(), P.end(), ycomparator);
for (int i = 0; i < P.size(); i++) {
for (size_t i = 0; i < P.size(); i++) {
Py.push_back(P[i]);
}
sort(P.begin(), P.end(), zcomparator);
......
......@@ -20,15 +20,15 @@ vector<double> ehvi3d_5term(deque<individual*> P, double r[],
double Sminus; // Correction term for the integral.
deque<individual*> Py, Pz; // P sorted by y/z coordinate
sort(P.begin(), P.end(), ycomparator);
for (int i = 0; i < P.size(); i++) {
for (size_t i = 0; i < P.size(); i++) {
Py.push_back(P[i]);
}
sort(P.begin(), P.end(), zcomparator);
for (unsigned int i = 0; i < P.size(); i++) {
for (size_t i = 0; i < P.size(); i++) {
Pz.push_back(P[i]);
}
sort(P.begin(), P.end(), xcomparator);
for (int i = 0; i < pdf.size(); i++) {
for (size_t i = 0; i < pdf.size(); i++) {
answer.push_back(0);
}
for (int z = 0; z <= n; z++) {
......@@ -72,7 +72,7 @@ vector<double> ehvi3d_5term(deque<individual*> P, double r[],
double yslice = calculateslice(Py, v, cl, 1);
double zslice = calculateslice(Pz, v, cl, 2);
// And then we integrate.
for (int i = 0; i < pdf.size(); i++) {
for (size_t i = 0; i < pdf.size(); i++) {
double psi1 = exipsi(v[0], cl[0], pdf[i]->mu[0], pdf[i]->s[0]) - exipsi(v[0], cu[0], pdf[i]->mu[0], pdf[i]->s[0]);
double psi2 = exipsi(v[1], cl[1], pdf[i]->mu[1], pdf[i]->s[1]) - exipsi(v[1], cu[1], pdf[i]->mu[1], pdf[i]->s[1]);
double psi3 = exipsi(v[2], cl[2], pdf[i]->mu[2], pdf[i]->s[2]) - exipsi(v[2], cu[2], pdf[i]->mu[2], pdf[i]->s[2]);
......@@ -116,7 +116,7 @@ vector<double> ehvi3d_sliceupdate(deque<individual*> P, double r[DIMENSIONS],
// location in
// the other sorting orders to be ascertained in O(1).
sort(P.begin(), P.end(), xcomparator);
for (unsigned int i = 0; i < n; i++) {
for (int i = 0; i < n; i++) {
newind = new specialind;
newind->point = P[i];
newind->xorder = i;
......@@ -125,11 +125,11 @@ vector<double> ehvi3d_sliceupdate(deque<individual*> P, double r[DIMENSIONS],
Pz.push_back(newind);
}
sort(Py.begin(), Py.end(), specialycomparator);
for (unsigned int i = 0; i < n; i++) {
for (int i = 0; i < n; i++) {
Py[i]->yorder = i;
}
sort(Pz.begin(), Pz.end(), specialzcomparator);
for (unsigned int i = 0; i < n; i++) {
for (int i = 0; i < n; i++) {
Pz[i]->zorder = i;
}
// Then also reserve memory for the structure array.
......@@ -244,7 +244,7 @@ vector<double> ehvi3d_sliceupdate(deque<individual*> P, double r[DIMENSIONS],
v[2] = (Pstruct[x + y * n].highestdominator == -1
? 0
: (Pz[Pstruct[x + y * n].highestdominator]->point->f[2] - r[2]));
for (int i = 0; i < pdf.size(); i++) {
for (size_t i = 0; i < pdf.size(); i++) {
double psi1 = exipsi(r[0], cl[0], pdf[i]->mu[0], pdf[i]->s[0]) - exipsi(r[0], cu[0], pdf[i]->mu[0], pdf[i]->s[0]);
double psi2 = exipsi(r[1], cl[1], pdf[i]->mu[1], pdf[i]->s[1]) - exipsi(r[1], cu[1], pdf[i]->mu[1], pdf[i]->s[1]);
double psi3 = exipsi(r[2], cl[2], pdf[i]->mu[2], pdf[i]->s[2]) - exipsi(r[2], cu[2], pdf[i]->mu[2], pdf[i]->s[2]);
......
......@@ -27,7 +27,7 @@ double ehvi3d_sliceupdate(deque<individual*> P, double r[], double mu[],
// location in
// the other sorting orders to be ascertained in O(1).
sort(P.begin(), P.end(), xcomparator);
for (unsigned int i = 0; i < n; i++) {
for (int i = 0; i < n; i++) {
newind = new specialind;
newind->point = P[i];
newind->xorder = i;
......@@ -36,11 +36,11 @@ double ehvi3d_sliceupdate(deque<individual*> P, double r[], double mu[],
Pz.push_back(newind);
}
sort(Py.begin(), Py.end(), specialycomparator);
for (unsigned int i = 0; i < n; i++) {
for (int i = 0; i < n; i++) {
Py[i]->yorder = i;
}
sort(Pz.begin(), Pz.end(), specialzcomparator);
for (unsigned int i = 0; i < n; i++) {
for (int i = 0; i < n; i++) {
Pz[i]->zorder = i;
}
// Then also reserve memory for the structure array.
......
......@@ -20,8 +20,8 @@ namespace limbo {
{
for (int i = 0; i < Params::init_randomsampling::samples(); i++) {
Eigen::VectorXd new_sample(StateFunction::dim_in);
for (int i = 0; i < StateFunction::dim_in; i++)
new_sample[i] = tools::rand<double>(0, 1);
for (size_t j = 0; j < StateFunction::dim_in; j++)
new_sample[j] = tools::rand<double>(0, 1);
opt.add_new_sample(new_sample, seval(new_sample));
}
}
......
......@@ -180,8 +180,8 @@ namespace limbo {
{
// O(n^2) [should be negligible]
_kernel.resize(_samples.size(), _samples.size());
for (int i = 0; i < _samples.size(); i++)
for (int j = 0; j < _samples.size(); ++j)
for (size_t i = 0; i < _samples.size(); i++)
for (size_t j = 0; j < _samples.size(); ++j)
_kernel(i, j) = _kernel_function(_samples[i], _samples[j]) + ((i == j) ? _noise : 0); // noise only on the diagonal
// O(n^3)
......
......@@ -43,7 +43,7 @@ namespace limbo {
int irun, lambda = 0, countevals = 0;
char const* stop;
boundary_transformation_t boundaries;
double lowerBounds[] = {0.0};
double lowerBounds[] = {0.0};
double upperBounds[] = {1.006309}; // Allows solution to be pretty close to 1
int nb_bounds = 1; /* numbers used from lower and upperBounds */
......@@ -51,7 +51,7 @@ namespace limbo {
double* x_in_bounds = cmaes_NewDouble(dim);
double init_point[dim];
for (int i = 0; i < dim; ++i)
for (size_t i = 0; i < dim; ++i)
init_point[i] = f.init()(i);
for (irun = 0; irun < nrestarts + 1; ++irun) {
......@@ -74,7 +74,7 @@ namespace limbo {
tools::par::loop(0, pop_size, [&](int i) {
// clang-format off
boundary_transformation(&boundaries, pop[i], all_x_in_bounds[i], dim);
for (int j = 0; j < dim; ++j)
for (size_t j = 0; j < dim; ++j)
pop_eigen[i](j) = all_x_in_bounds[i][j];
fitvals[i] = -f.utility(pop_eigen[i]);
// clang-format on
......
......@@ -8,11 +8,11 @@
#include <limbo/tools/macros.hpp>
namespace limbo {
namespace defaults {
namespace defaults {
struct opt_gridsearch {
BO_PARAM(int, bins, 5);
};
}
}
namespace opt {
template <typename Params>
struct GridSearch {
......@@ -27,7 +27,7 @@ namespace limbo {
protected:
template <typename F>
Eigen::VectorXd _inner_search(const F& f, int depth, const Eigen::VectorXd& current) const
Eigen::VectorXd _inner_search(const F& f, size_t depth, const Eigen::VectorXd& current) const
{
double step_size = 1.0 / (double)Params::opt_gridsearch::bins();
double upper_lim = 1.0 + step_size;
......
......@@ -53,15 +53,15 @@ BOOST_AUTO_TEST_CASE(test_gp)
Eigen::VectorXd mu;
double sigma;
std::tie(mu, sigma) = gp.query(make_v1(1));
BOOST_CHECK(abs((mu(0) - 5)) < 1);
BOOST_CHECK(std::abs((mu(0) - 5)) < 1);
BOOST_CHECK(sigma < 1e-5);
std::tie(mu, sigma) = gp.query(make_v1(2));
BOOST_CHECK(abs((mu(0) - 10)) < 1);
BOOST_CHECK(std::abs((mu(0) - 10)) < 1);
BOOST_CHECK(sigma < 1e-5);
std::tie(mu, sigma) = gp.query(make_v1(3));
BOOST_CHECK(abs((mu(0) - 5)) < 1);
BOOST_CHECK(std::abs((mu(0) - 5)) < 1);
BOOST_CHECK(sigma < 1e-5);
for (double x = 0; x < 4; x += 0.05) {
......@@ -123,14 +123,14 @@ BOOST_AUTO_TEST_CASE(test_gp_auto)
Eigen::VectorXd mu;
double sigma;
std::tie(mu, sigma) = gp.query(make_v1(1));
BOOST_CHECK(abs((mu(0) - 5)) < 1);
BOOST_CHECK(std::abs((mu(0) - 5)) < 1);
BOOST_CHECK(sigma < 1e-5);
std::tie(mu, sigma) = gp.query(make_v1(2));
BOOST_CHECK(abs((mu(0) - 10)) < 1);
BOOST_CHECK(std::abs((mu(0) - 10)) < 1);
BOOST_CHECK(sigma < 1e-5);
std::tie(mu, sigma) = gp.query(make_v1(3));
BOOST_CHECK(abs((mu(0) - 5)) < 1);
BOOST_CHECK(std::abs((mu(0) - 5)) < 1);
BOOST_CHECK(sigma < 1e-5);
}
\ No newline at end of file
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment