Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MSVC compatibility #54

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 20 additions & 11 deletions include/misc/optim_options.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,6 @@

//

#ifdef _MSC_VER
#error OptimLib: MSVC is not supported
#endif

//

#if defined(_OPENMP) && !defined(OPTIM_DONT_USE_OPENMP)
#undef OPTIM_USE_OPENMP
#define OPTIM_USE_OPENMP
Expand Down Expand Up @@ -76,15 +70,20 @@
#endif

// floating point number type

#ifndef FLOAT_TYPE_KEY
#define FLOAT_TYPE_KEY 0
#endif
#ifndef DOUBLE_TYPE_KEY
#define DOUBLE_TYPE_KEY 1
#endif
#ifndef OPTIM_FPN_TYPE
#define OPTIM_FPN_TYPE double
#define OPTIM_FPN_TYPE DOUBLE_TYPE_KEY
#endif

#if OPTIM_FPN_TYPE == float
#if OPTIM_FPN_TYPE == FLOAT_TYPE_KEY
#undef OPTIM_FPN_SMALL_NUMBER
#define OPTIM_FPN_SMALL_NUMBER fp_t(1e-05)
#elif OPTIM_FPN_TYPE == double
#elif OPTIM_FPN_TYPE == DOUBLE_TYPE_KEY
#undef OPTIM_FPN_SMALL_NUMBER
#define OPTIM_FPN_SMALL_NUMBER fp_t(1e-08)
#else
Expand All @@ -96,12 +95,22 @@
namespace optim
{
using uint_t = unsigned int;
using fp_t = OPTIM_FPN_TYPE;
#if OPTIM_FPN_TYPE == FLOAT_TYPE_KEY
using fp_t = float;
#else
using fp_t = double;
#endif

using rand_engine_t = std::mt19937_64;

static const double eps_dbl = std::numeric_limits<fp_t>::epsilon();
static const double inf = std::numeric_limits<fp_t>::infinity();

#ifdef _MSC_VER
using ompint_t = int64_t;
#else
using ompint_t = size_t;
#endif
}

//
Expand Down
6 changes: 3 additions & 3 deletions src/unconstrained/de.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ optim::internal::de_impl(
#ifdef OPTIM_USE_OPENMP
#pragma omp parallel for num_threads(omp_n_threads) firstprivate(rand_vec)
#endif
for (size_t i = 0; i < n_pop; ++i) {
for (ompint_t i = 0; i < n_pop; ++i) {
size_t thread_num = 0;

#ifdef OPTIM_USE_OPENMP
Expand Down Expand Up @@ -164,7 +164,7 @@ optim::internal::de_impl(
#ifdef OPTIM_USE_OPENMP
#pragma omp parallel for num_threads(omp_n_threads) firstprivate(rand_vec)
#endif
for (size_t i = 0; i < n_pop; ++i) {
for (ompint_t i = 0; i < n_pop; ++i) {
size_t thread_num = 0;

#ifdef OPTIM_USE_OPENMP
Expand Down Expand Up @@ -258,7 +258,7 @@ optim::internal::de_impl(
#ifdef OPTIM_USE_OPENMP
#pragma omp parallel for num_threads(omp_n_threads)
#endif
for (size_t i = 0; i < n_pop; ++i) {
for (ompint_t i = 0; i < n_pop; ++i) {
X_next.row(i) = inv_transform<RowVec_t>(X_next.row(i), bounds_type, lower_bounds, upper_bounds);
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/unconstrained/de_prmm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ optim::internal::de_prmm_impl(
#ifdef OPTIM_USE_OPENMP
#pragma omp parallel for num_threads(omp_n_threads) firstprivate(rand_vec)
#endif
for (size_t i = 0; i < n_pop; ++i) {
for (ompint_t i = 0; i < n_pop; ++i) {
size_t thread_num = 0;

#ifdef OPTIM_USE_OPENMP
Expand Down Expand Up @@ -195,7 +195,7 @@ optim::internal::de_prmm_impl(
#ifdef OPTIM_USE_OPENMP
#pragma omp parallel for num_threads(omp_n_threads)
#endif
for (size_t j = 0; j < n_pop_temp; ++j) {
for (ompint_t j = 0; j < n_pop_temp; ++j) {
if (objfn_vals(j) < objfn_vals(j + n_pop_temp)) {
X_reset.row(j) = X_next.row(j);
objfn_vals_reset(j) = objfn_vals(j);
Expand Down Expand Up @@ -223,7 +223,7 @@ optim::internal::de_prmm_impl(
#ifdef OPTIM_USE_OPENMP
#pragma omp parallel for num_threads(omp_n_threads) firstprivate(rand_vec,rand_pars)
#endif
for (size_t i = 0; i < n_pop - n_pop_best; ++i) {
for (ompint_t i = 0; i < n_pop - n_pop_best; ++i) {
size_t thread_num = 0;

#ifdef OPTIM_USE_OPENMP
Expand Down Expand Up @@ -306,7 +306,7 @@ optim::internal::de_prmm_impl(
#ifdef OPTIM_USE_OPENMP
#pragma omp parallel for num_threads(omp_n_threads) firstprivate(rand_vec,rand_pars)
#endif
for (size_t i = n_pop - n_pop_best; i < n_pop; ++i) {
for (ompint_t i = n_pop - n_pop_best; i < n_pop; ++i) {
size_t thread_num = 0;

#ifdef OPTIM_USE_OPENMP
Expand Down Expand Up @@ -417,7 +417,7 @@ optim::internal::de_prmm_impl(
#ifdef OPTIM_USE_OPENMP
#pragma omp parallel for num_threads(omp_n_threads)
#endif
for (size_t i = 0; i < n_pop; ++i) {
for (ompint_t i = 0; i < n_pop; ++i) {
X_next.row(i) = inv_transform<RowVec_t>(X_next.row(i), bounds_type, lower_bounds, upper_bounds);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/unconstrained/nm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ optim::internal::nm_impl(
#ifdef OPTIM_USE_OPENMP
#pragma omp parallel for num_threads(omp_n_threads)
#endif
for (size_t i = 1; i < n_vals + 1; i++) {
for (ompint_t i = 1; i < n_vals + 1; i++) {
simplex_fn_vals(i) = box_objfn( BMO_MATOPS_TRANSPOSE(simplex_points.row(i)), nullptr, opt_data);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/unconstrained/pso.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ optim::internal::pso_impl(
#ifdef OPTIM_USE_OPENMP
#pragma omp parallel for num_threads(omp_n_threads) firstprivate(rand_vec)
#endif
for (size_t i = 0; i < n_pop; ++i) {
for (ompint_t i = 0; i < n_pop; ++i) {
size_t thread_num = 0;

#ifdef OPTIM_USE_OPENMP
Expand Down Expand Up @@ -202,7 +202,7 @@ optim::internal::pso_impl(
#ifdef OPTIM_USE_OPENMP
#pragma omp parallel for num_threads(omp_n_threads) firstprivate(rand_vec_1,rand_vec_2)
#endif
for (size_t i=0; i < n_pop; ++i) {
for (ompint_t i=0; i < n_pop; ++i) {
size_t thread_num = 0;

#ifdef OPTIM_USE_OPENMP
Expand Down Expand Up @@ -270,7 +270,7 @@ optim::internal::pso_impl(
#ifdef OPTIM_USE_OPENMP
#pragma omp parallel for num_threads(omp_n_threads)
#endif
for (size_t i = 0; i < n_pop; ++i) {
for (ompint_t i = 0; i < n_pop; ++i) {
P.row(i) = inv_transform<RowVec_t>(P.row(i), bounds_type, lower_bounds, upper_bounds);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/unconstrained/pso_dv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ optim::internal::pso_dv_impl(
#ifdef OPTIM_USE_OPENMP
#pragma omp parallel for num_threads(omp_n_threads) firstprivate(rand_vec)
#endif
for (size_t i = 0; i < n_pop; ++i) {
for (ompint_t i = 0; i < n_pop; ++i) {
size_t thread_num = 0;

#ifdef OPTIM_USE_OPENMP
Expand Down Expand Up @@ -178,7 +178,7 @@ optim::internal::pso_dv_impl(
#ifdef OPTIM_USE_OPENMP
#pragma omp parallel for num_threads(omp_n_threads) firstprivate(rand_vec,rand_CR)
#endif
for (size_t i = 0; i < n_pop; ++i) {
for (ompint_t i = 0; i < n_pop; ++i) {
size_t thread_num = 0;

#ifdef OPTIM_USE_OPENMP
Expand Down