Skip to content

Commit 6b9a1ac

Browse files
committed
Update math wrapper functions
(until we conclude that current compilers are no longer exhibiting the issues previously encountered on some VMD platforms)
1 parent f80f7b1 commit 6b9a1ac

File tree

4 files changed

+27
-27
lines changed

4 files changed

+27
-27
lines changed

src/colvar_neuralnetworkcompute.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,18 @@
1717
namespace neuralnetworkCV {
1818
std::map<std::string, std::pair<std::function<double(double)>, std::function<double(double)>>> activation_function_map
1919
{
20-
{"tanh", {[](double x){return std::tanh(x);},
21-
[](double x){return 1.0 - std::tanh(x) * std::tanh(x);}}},
22-
{"sigmoid", {[](double x){return 1.0 / (1.0 + std::exp(-x));},
23-
[](double x){return std::exp(-x) / ((1.0 + std::exp(-x)) * (1.0 + std::exp(-x)));}}},
20+
{"tanh", {[](double x){return cvm::tanh(x);},
21+
[](double x){return 1.0 - cvm::tanh(x) * cvm::tanh(x);}}},
22+
{"sigmoid", {[](double x){return 1.0 / (1.0 + cvm::exp(-x));},
23+
[](double x){return cvm::exp(-x) / ((1.0 + cvm::exp(-x)) * (1.0 + cvm::exp(-x)));}}},
2424
{"linear", {[](double x){return x;},
2525
[](double /*x*/){return 1.0;}}},
2626
{"relu", {[](double x){return x < 0. ? 0. : x;},
2727
[](double x){return x < 0. ? 0. : 1.;}}},
2828
{"lrelu100", {[](double x){return x < 0. ? 0.01 * x : x;},
2929
[](double x){return x < 0. ? 0.01 : 1.;}}},
30-
{"elu", {[](double x){return x < 0. ? std::exp(x)-1. : x;},
31-
[](double x){return x < 0. ? std::exp(x) : 1.;}}}
30+
{"elu", {[](double x){return x < 0. ? cvm::exp(x)-1. : x;},
31+
[](double x){return x < 0. ? cvm::exp(x) : 1.;}}}
3232
};
3333

3434
#ifdef LEPTON

src/colvarbias_opes.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ int colvarbias_opes::init(const std::string& conf) {
143143
}
144144
if (m_explore) {
145145
for (size_t i = 0; i < num_variables(); ++i) {
146-
m_sigma0[i] *= std::sqrt(m_biasfactor);
146+
m_sigma0[i] *= cvm::sqrt(m_biasfactor);
147147
}
148148
}
149149
}
@@ -158,22 +158,22 @@ int colvarbias_opes::init(const std::string& conf) {
158158
}
159159
}
160160
}
161-
get_keyval(conf, "epsilon", m_epsilon, std::exp(-m_barrier/m_bias_prefactor/m_kbt));
161+
get_keyval(conf, "epsilon", m_epsilon, cvm::exp(-m_barrier/m_bias_prefactor/m_kbt));
162162
if (m_epsilon <= 0) {
163163
return cvm::error("you must choose a value of epsilon greater than zero");
164164
}
165-
m_sum_weights = std::pow(m_epsilon, m_bias_prefactor);
165+
m_sum_weights = cvm::pow(m_epsilon, m_bias_prefactor);
166166
m_sum_weights2 = m_sum_weights * m_sum_weights;
167167
if (m_explore) {
168-
get_keyval(conf, "kernelCutoff", m_cutoff, std::sqrt(2.0*m_barrier/m_kbt));
168+
get_keyval(conf, "kernelCutoff", m_cutoff, cvm::sqrt(2.0*m_barrier/m_kbt));
169169
} else {
170-
get_keyval(conf, "kernelCutoff", m_cutoff, std::sqrt(2.0*m_barrier/m_bias_prefactor/m_kbt));
170+
get_keyval(conf, "kernelCutoff", m_cutoff, cvm::sqrt(2.0*m_barrier/m_bias_prefactor/m_kbt));
171171
}
172172
if (m_cutoff <= 0) {
173173
return cvm::error("you must choose a value of kernelCutoff greater than zero");
174174
}
175175
m_cutoff2 = m_cutoff * m_cutoff;
176-
m_val_at_cutoff = std::exp(-0.5 * m_cutoff2);
176+
m_val_at_cutoff = cvm::exp(-0.5 * m_cutoff2);
177177
get_keyval(conf, "compressionThreshold", m_compression_threshold, 1);
178178
if (m_compression_threshold != 0) {
179179
if (m_compression_threshold < 0 || m_compression_threshold > m_cutoff) {
@@ -196,7 +196,7 @@ int colvarbias_opes::init(const std::string& conf) {
196196
if (nlist_param[0] <= 1.0) {
197197
return cvm::error("the first of neighborListParam must be greater than 1.0. The smaller the first, the smaller should be the second as well", COLVARS_INPUT_ERROR);
198198
}
199-
const cvm::real min_PARAM_1 = (1.-1./std::sqrt(nlist_param[0]))+0.16;
199+
const cvm::real min_PARAM_1 = (1.-1./cvm::sqrt(nlist_param[0]))+0.16;
200200
if (nlist_param[1] <= 0) {
201201
return cvm::error("the second of neighborListParam must be greater than 0", COLVARS_INPUT_ERROR);
202202
}
@@ -333,7 +333,7 @@ void colvarbias_opes::showInfo() const {
333333
}
334334
if (m_adaptive_sigma) {
335335
printInfo("adaptive sigma will be used, with adaptiveSigmaStride = ", cvm::to_str(m_adaptive_sigma_stride));
336-
size_t x = std::ceil(m_adaptive_sigma_stride / m_pace);
336+
size_t x = cvm::ceil(m_adaptive_sigma_stride / m_pace);
337337
printInfo(" thus the first x kernel depositions will be skipped, x = adaptiveSigmaStride/newHillFrequency = ", cvm::to_str(x));
338338
} else {
339339
std::string sigmas;
@@ -393,7 +393,7 @@ cvm::real colvarbias_opes::evaluateKernel(
393393
return 0;
394394
}
395395
}
396-
return G.m_height * (std::exp(-0.5 * norm2) - m_val_at_cutoff);
396+
return G.m_height * (cvm::exp(-0.5 * norm2) - m_val_at_cutoff);
397397
}
398398

399399
cvm::real colvarbias_opes::evaluateKernel(
@@ -409,7 +409,7 @@ cvm::real colvarbias_opes::evaluateKernel(
409409
return 0;
410410
}
411411
}
412-
const cvm::real val = G.m_height * (std::exp(-0.5 * norm2) - m_val_at_cutoff);
412+
const cvm::real val = G.m_height * (cvm::exp(-0.5 * norm2) - m_val_at_cutoff);
413413
// The derivative of norm2 with respect to x
414414
for (size_t i = 0; i < num_variables(); ++i) {
415415
accumulated_derivative[i] -= val * dist[i] / G.m_sigma[i];
@@ -674,7 +674,7 @@ int colvarbias_opes::update_opes() {
674674
m_av_M2[i] *= m_biasfactor;
675675
}
676676
for (size_t i = 0; i < num_variables(); ++i) {
677-
m_sigma0[i] = std::sqrt(m_av_M2[i] / m_adaptive_counter / factor);
677+
m_sigma0[i] = cvm::sqrt(m_av_M2[i] / m_adaptive_counter / factor);
678678
}
679679
if (m_sigma_min.size() == 0) {
680680
for (size_t i = 0; i < num_variables(); ++i) {
@@ -690,7 +690,7 @@ int colvarbias_opes::update_opes() {
690690
}
691691
}
692692
for (size_t i = 0; i < num_variables(); ++i) {
693-
sigma[i] = std::sqrt(m_av_M2[i] / m_adaptive_counter / factor);
693+
sigma[i] = cvm::sqrt(m_av_M2[i] / m_adaptive_counter / factor);
694694
}
695695
if (m_sigma_min.size() == 0) {
696696
bool sigma_less_than_threshold = false;
@@ -713,7 +713,7 @@ int colvarbias_opes::update_opes() {
713713
if (!m_fixed_sigma) {
714714
const cvm::real size = m_explore ? m_counter : m_neff;
715715
const size_t ncv = num_variables();
716-
const cvm::real s_rescaling = std::pow(size * (ncv + 2.0) / 4, -1.0 / (4.0 + ncv));
716+
const cvm::real s_rescaling = cvm::pow(size * (ncv + 2.0) / 4, -1.0 / (4.0 + ncv));
717717
for (size_t i = 0; i < num_variables(); ++i) {
718718
sigma[i] *= s_rescaling;
719719
}
@@ -1356,29 +1356,29 @@ template <typename IST> IST& colvarbias_opes::read_state_data_template_(IST &is)
13561356
old_biasfactor = std::stod(old_biasfactor_str);
13571357
m_inf_biasfactor = false;
13581358
}
1359-
if (std::abs(old_biasfactor - m_biasfactor) > 1e-6 * m_biasfactor) {
1359+
if (cvm::fabs(old_biasfactor - m_biasfactor) > 1e-6 * m_biasfactor) {
13601360
cvm::log("WARNING: previous bias factor was " + cvm::to_str(old_biasfactor) +
13611361
" while now it is " + cvm::to_str(m_biasfactor) +
13621362
" (the new one is used).\n");
13631363
}
13641364
cvm::real old_epsilon;
13651365
readFieldReal("epsilon", old_epsilon);
1366-
if (std::abs(old_epsilon - m_epsilon) > 1e-6 * m_epsilon) {
1366+
if (cvm::fabs(old_epsilon - m_epsilon) > 1e-6 * m_epsilon) {
13671367
cvm::log("WARNING: previous epsilon was " + cvm::to_str(old_epsilon) +
13681368
" while now it is " + cvm::to_str(m_epsilon) +
13691369
" (the new one is used).\n");
13701370
}
13711371
cvm::real old_cutoff;
13721372
readFieldReal("kernel_cutoff", old_cutoff);
1373-
if (std::abs(old_cutoff - m_cutoff) > 1e-6 * m_cutoff) {
1373+
if (cvm::fabs(old_cutoff - m_cutoff) > 1e-6 * m_cutoff) {
13741374
cvm::log("WARNING: previous cutoff was " + cvm::to_str(old_cutoff) +
13751375
" while now it is " + cvm::to_str(m_cutoff) +
13761376
" (the new one is used).\n");
13771377
}
13781378
m_cutoff2 = m_cutoff * m_cutoff;
13791379
cvm::real old_compression_threshold;
13801380
readFieldReal("compression_threshold", old_compression_threshold);
1381-
if (std::abs(old_compression_threshold - m_compression_threshold) > 1e-6 * m_compression_threshold) {
1381+
if (cvm::fabs(old_compression_threshold - m_compression_threshold) > 1e-6 * m_compression_threshold) {
13821382
cvm::log("WARNING: previous cutoff was " + cvm::to_str(old_compression_threshold) +
13831383
" while now it is " + cvm::to_str(m_compression_threshold) +
13841384
" (the new one is used).\n");

src/colvarcomp_apath.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ int colvar::aspath::init(std::string const &conf)
149149
cvm::real p_lambda;
150150
get_keyval(conf, "lambda", p_lambda, -1.0);
151151
const size_t num_atoms = atoms->size();
152-
std::vector<cvm::real> p_weights(num_atoms, std::sqrt(1.0 / num_atoms));
152+
std::vector<cvm::real> p_weights(num_atoms, cvm::sqrt(1.0 / num_atoms));
153153
// ArithmeticPathCV::ArithmeticPathBase<cvm::atom_pos, cvm::real, ArithmeticPathCV::path_sz::S>::initialize(num_atoms, total_reference_frames, p_lambda, reference_frames[0], p_weights);
154154
if (impl_) impl_.reset();
155155
impl_ = std::unique_ptr<ArithmeticPathImpl>(new ArithmeticPathImpl(num_atoms, total_reference_frames, p_lambda, p_weights));
@@ -207,7 +207,7 @@ int colvar::azpath::init(std::string const &conf)
207207
cvm::real p_lambda;
208208
get_keyval(conf, "lambda", p_lambda, -1.0);
209209
const size_t num_atoms = atoms->size();
210-
std::vector<cvm::real> p_weights(num_atoms, std::sqrt(1.0 / num_atoms));
210+
std::vector<cvm::real> p_weights(num_atoms, cvm::sqrt(1.0 / num_atoms));
211211
if (impl_) impl_.reset();
212212
impl_ = std::unique_ptr<ArithmeticPathImpl>(new ArithmeticPathImpl(num_atoms, total_reference_frames, p_lambda, p_weights));
213213
cvm::log(std::string("Lambda is ") + cvm::to_str(impl_->get_lambda()) + std::string("\n"));

src/colvarcomp_coordnums.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ cvm::real colvar::coordnum::switching_function(cvm::real const &r0,
6363
cvm::real const ed2_r = (cvm::real) ed2;
6464

6565
// Function value: 1st-order Taylor expansion around l2 = 1
66-
cvm::real const func_no_pairlist = (std::abs(h) < eps_l2) ?
66+
cvm::real const func_no_pairlist = (cvm::fabs(h) < eps_l2) ?
6767
(en2_r / ed2_r) + h * (en2_r * (en2_r - ed2_r) / (2.0 * ed2_r)) :
6868
(1.0 - xn) / (1.0 - xd);
6969

@@ -86,7 +86,7 @@ cvm::real colvar::coordnum::switching_function(cvm::real const &r0,
8686

8787
if (flags & ef_gradients) {
8888
// Logarithmic derivative: 1st-order Taylor expansion around l2 = 1
89-
cvm::real const log_deriv = (std::abs(h) < eps_l2) ?
89+
cvm::real const log_deriv = (cvm::fabs(h) < eps_l2) ?
9090
0.5 * (en2_r - ed2_r) + h * ((en2_r - ed2_r) * (en2_r + ed2_r - 6.0) / 12.0) :
9191
((ed2_r * xd / ((1.0 - xd) * l2)) - (en2_r * xn / ((1.0 - xn) * l2)));
9292

0 commit comments

Comments
 (0)