Skip to content

Commit ec719ab

Browse files
authored
[ML] Standardise on cmath header (#33)
This switches to use the cmath rather than math.h header. This only guaranties to declare special functions in the std namespace, so this also adds std:: qualification on existing calls.
1 parent 33c9d1e commit ec719ab

File tree

167 files changed

+1532
-1545
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

167 files changed

+1532
-1545
lines changed

bin/autodetect/Main.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656

5757
int main(int argc, char **argv)
5858
{
59-
typedef ml::autodetect::CCmdLineParser::TStrVec TStrVec;
59+
using TStrVec = ml::autodetect::CCmdLineParser::TStrVec;
6060

6161
// Read command line options
6262
std::string limitConfigFile;
@@ -207,7 +207,7 @@ int main(int argc, char **argv)
207207
return EXIT_FAILURE;
208208
}
209209

210-
typedef boost::scoped_ptr<ml::core::CDataSearcher> TScopedDataSearcherP;
210+
using TScopedDataSearcherP = boost::scoped_ptr<ml::core::CDataSearcher>;
211211
TScopedDataSearcherP restoreSearcher;
212212
if (ioMgr.restoreStream() != 0)
213213
{
@@ -227,14 +227,14 @@ int main(int argc, char **argv)
227227
}
228228
}
229229

230-
typedef boost::scoped_ptr<ml::core::CDataAdder> TScopedDataAdderP;
230+
using TScopedDataAdderP = boost::scoped_ptr<ml::core::CDataAdder>;
231231
TScopedDataAdderP persister;
232232
if (ioMgr.persistStream() != 0)
233233
{
234234
persister.reset(new ml::api::CSingleStreamDataAdder(ioMgr.persistStream()));
235235
}
236236

237-
typedef boost::scoped_ptr<ml::api::CBackgroundPersister> TScopedBackgroundPersisterP;
237+
using TScopedBackgroundPersisterP = boost::scoped_ptr<ml::api::CBackgroundPersister>;
238238
TScopedBackgroundPersisterP periodicPersister;
239239
if (persistInterval >= 0)
240240
{
@@ -249,7 +249,7 @@ int main(int argc, char **argv)
249249
*persister));
250250
}
251251

252-
typedef boost::scoped_ptr<ml::api::CInputParser> TScopedInputParserP;
252+
using TScopedInputParserP = boost::scoped_ptr<ml::api::CInputParser>;
253253
TScopedInputParserP inputParser;
254254
if (lengthEncodedInput)
255255
{

bin/categorize/Main.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ int main(int argc, char **argv)
141141
}
142142
ml::api::CFieldConfig fieldConfig(categorizationFieldName);
143143

144-
typedef boost::scoped_ptr<ml::core::CDataSearcher> TScopedDataSearcherP;
144+
using TScopedDataSearcherP = boost::scoped_ptr<ml::core::CDataSearcher>;
145145
TScopedDataSearcherP restoreSearcher;
146146
if (ioMgr.restoreStream() != 0)
147147
{
@@ -161,14 +161,14 @@ int main(int argc, char **argv)
161161
}
162162
}
163163

164-
typedef boost::scoped_ptr<ml::core::CDataAdder> TScopedDataAdderP;
164+
using TScopedDataAdderP = boost::scoped_ptr<ml::core::CDataAdder>;
165165
TScopedDataAdderP persister;
166166
if (ioMgr.persistStream() != 0)
167167
{
168168
persister.reset(new ml::api::CSingleStreamDataAdder(ioMgr.persistStream()));
169169
}
170170

171-
typedef boost::scoped_ptr<ml::api::CBackgroundPersister> TScopedBackgroundPersisterP;
171+
using TScopedBackgroundPersisterP = boost::scoped_ptr<ml::api::CBackgroundPersister>;
172172
TScopedBackgroundPersisterP periodicPersister;
173173
if (persistInterval >= 0)
174174
{
@@ -183,7 +183,7 @@ int main(int argc, char **argv)
183183
*persister));
184184
}
185185

186-
typedef boost::scoped_ptr<ml::api::CInputParser> TScopedInputParserP;
186+
using TScopedInputParserP = boost::scoped_ptr<ml::api::CInputParser>;
187187
TScopedInputParserP inputParser;
188188
if (lengthEncodedInput)
189189
{

bin/normalize/Main.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ int main(int argc, char **argv)
111111
modelConfig.perPartitionNormalization(perPartitionNormalization);
112112

113113
// There's a choice of input and output formats for the numbers to be normalised
114-
typedef boost::scoped_ptr<ml::api::CInputParser> TScopedInputParserP;
114+
using TScopedInputParserP = boost::scoped_ptr<ml::api::CInputParser>;
115115
TScopedInputParserP inputParser;
116116
if (lengthEncodedInput)
117117
{
@@ -123,7 +123,7 @@ int main(int argc, char **argv)
123123
ml::api::CCsvInputParser::COMMA));
124124
}
125125

126-
typedef boost::scoped_ptr<ml::api::COutputHandler> TScopedOutputHandlerP;
126+
using TScopedOutputHandlerP = boost::scoped_ptr<ml::api::COutputHandler>;
127127
TScopedOutputHandlerP outputWriter;
128128
if (writeCsv)
129129
{

include/core/CFloatStorage.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,9 @@
1212

1313
#include <maths/ImportExport.h>
1414

15+
#include <cmath>
1516
#include <limits>
1617

17-
#include <math.h>
18-
19-
2018
namespace ml
2119
{
2220
namespace core
@@ -26,7 +24,7 @@ namespace
2624
{
2725
const int MAX_PRECISE_INTEGER_FLOAT(
2826
static_cast<int>(
29-
::pow(10.0,
27+
std::pow(10.0,
3028
static_cast<double>(std::numeric_limits<float>::digits10))
3129
) - 1
3230
);

include/core/Constants.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99

1010
#include <core/CoreTypes.h>
1111

12+
#include <cmath>
1213
#include <limits>
13-
#include <math.h>
1414

1515
namespace ml
1616
{
@@ -38,13 +38,13 @@ const core_t::TTime WEEK = 604800;
3838
const core_t::TTime YEAR = 31449600;
3939

4040
//! Log of min double.
41-
const double LOG_MIN_DOUBLE = ::log(std::numeric_limits<double>::min());
41+
const double LOG_MIN_DOUBLE = std::log(std::numeric_limits<double>::min());
4242

4343
//! Log of max double.
44-
const double LOG_MAX_DOUBLE = ::log(std::numeric_limits<double>::max());
44+
const double LOG_MAX_DOUBLE = std::log(std::numeric_limits<double>::max());
4545

4646
//! Log of double epsilon.
47-
const double LOG_DOUBLE_EPSILON = ::log(std::numeric_limits<double>::epsilon());
47+
const double LOG_DOUBLE_EPSILON = std::log(std::numeric_limits<double>::epsilon());
4848

4949
//! Log of two.
5050
const double LOG_TWO = 0.693147180559945;

include/maths/CCompositeFunctions.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@
1212
#include <boost/type_traits/integral_constant.hpp>
1313
#include <boost/type_traits/remove_reference.hpp>
1414

15+
#include <cmath>
1516
#include <limits>
1617

17-
#include <math.h>
18-
1918
namespace ml
2019
{
2120
namespace maths
@@ -216,19 +215,19 @@ class MATHS_EXPORT CCompositeFunctions
216215
inline T operator()(double x) const
217216
{
218217
static const double LOG_MIN_DOUBLE =
219-
::log(std::numeric_limits<double>::min());
218+
std::log(std::numeric_limits<double>::min());
220219
double fx = m_F(x);
221-
return fx < LOG_MIN_DOUBLE ? 0.0 : ::exp(fx);
220+
return fx < LOG_MIN_DOUBLE ? 0.0 : std::exp(fx);
222221
}
223222

224223
//! For function return success/fail and taking result as argument.
225224
inline bool operator()(double x, T &result) const
226225
{
227226
static const double LOG_MIN_DOUBLE =
228-
::log(std::numeric_limits<double>::min());
227+
std::log(std::numeric_limits<double>::min());
229228
if (m_F(x, result))
230229
{
231-
result = result < LOG_MIN_DOUBLE ? 0.0 : ::exp(result);
230+
result = result < LOG_MIN_DOUBLE ? 0.0 : std::exp(result);
232231
return true;
233232
}
234233
return false;

include/maths/CEqualWithTolerance.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313

1414
#include <functional>
1515

16-
#include <math.h>
17-
1816
namespace ml
1917
{
2018
namespace maths

include/maths/CGradientDescent.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <maths/CLinearAlgebra.h>
1414
#include <maths/ImportExport.h>
1515

16+
#include <cmath>
1617
#include <cstddef>
1718
#include <vector>
1819

include/maths/CGramSchmidt.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ class MATHS_EXPORT CGramSchmidt : private core::CNonInstantiatable
145145
<< ", norm = " << n
146146
<< ", eps = " << eps);
147147

148-
if (::fabs(n) > eps)
148+
if (std::fabs(n) > eps)
149149
{
150150
divide(x[current], n);
151151
++current;

include/maths/CInformationCriteria.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <maths/CSphericalCluster.h>
1515
#include <maths/ImportExport.h>
1616

17+
#include <cmath>
1718
#include <cstddef>
1819
#include <limits>
1920
#include <vector>
@@ -187,7 +188,7 @@ class CSphericalGaussianInfoCriterion
187188
m_Likelihood += ni * log(ni)
188189
- 0.5 * m_D * ni * ( 1.0
189190
+ core::constants::LOG_TWO_PI
190-
+ ::log(upper * vi / m_D));
191+
+ std::log(upper * vi / m_D));
191192
}
192193
else
193194
{
@@ -206,7 +207,7 @@ class CSphericalGaussianInfoCriterion
206207
return 0.0;
207208
}
208209

209-
double logN = ::log(m_N);
210+
double logN = std::log(m_N);
210211
double p = (m_D * m_K + 2.0 * m_K - 1.0);
211212
switch (TYPE)
212213
{
@@ -318,7 +319,7 @@ class CGaussianInfoCriterion
318319
return 0.0;
319320
}
320321

321-
double logN = ::log(m_N);
322+
double logN = std::log(m_N);
322323
double p = (m_D * (1.0 + 0.5 * (m_D + 1.0)) * m_K + m_K - 1.0);
323324
switch (TYPE)
324325
{

include/maths/CIntegration.h

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,10 @@
2020

2121
#include <atomic>
2222
#include <algorithm>
23+
#include <cmath>
2324
#include <functional>
2425
#include <numeric>
2526

26-
#include <math.h>
27-
2827
namespace ml
2928
{
3029
namespace maths
@@ -214,7 +213,7 @@ class MATHS_EXPORT CIntegration
214213
//! of the integral is returned. This is intended to support integration
215214
//! where the integrand is very small and may underflow double. This is
216215
//! handled by renormalizing the integral so only underflows if values
217-
//! are less than ::exp(-std::numeric_limits<double>::max()), so really
216+
//! are less than std::exp(-std::numeric_limits<double>::max()), so really
218217
//! very small!
219218
//!
220219
//! \param[in] function The log of the function to integrate.
@@ -261,7 +260,7 @@ class MATHS_EXPORT CIntegration
261260
double fmax = *std::max_element(fx, fx + ORDER);
262261
for (unsigned int i = 0; i < ORDER; ++i)
263262
{
264-
fx[i] = ::exp(fx[i] - fmax);
263+
fx[i] = std::exp(fx[i] - fmax);
265264
}
266265

267266
// Quadrature.
@@ -270,7 +269,7 @@ class MATHS_EXPORT CIntegration
270269
result += weights[i] * fx[i];
271270
}
272271
result *= range;
273-
result = result <= 0.0 ? core::constants::LOG_MIN_DOUBLE : fmax + ::log(result);
272+
result = result <= 0.0 ? core::constants::LOG_MIN_DOUBLE : fmax + std::log(result);
274273

275274
return true;
276275
}
@@ -324,15 +323,15 @@ class MATHS_EXPORT CIntegration
324323
corrections.reserve(fIntervals.size());
325324
for (std::size_t i = 0u; i < fIntervals.size(); ++i)
326325
{
327-
corrections.push_back(::fabs(fIntervals[i]));
326+
corrections.push_back(std::fabs(fIntervals[i]));
328327
}
329328

330329
for (std::size_t i = 0u;
331330
!intervals.empty() && i < refinements;
332331
++i)
333332
{
334333
std::size_t n = intervals.size();
335-
double cutoff = tolerance * ::fabs(result) / static_cast<double>(n);
334+
double cutoff = tolerance * std::fabs(result) / static_cast<double>(n);
336335

337336
std::size_t end = 0u;
338337
for (std::size_t j = 0u; j < corrections.size(); ++j)
@@ -406,13 +405,13 @@ class MATHS_EXPORT CIntegration
406405
double correction = fjNew - fjOld;
407406
if (i + 1 < refinements)
408407
{
409-
corrections[j] = ::fabs(correction);
408+
corrections[j] = std::fabs(correction);
410409
corrections.resize(corrections.size() + splitsPerRefinement - 1,
411-
::fabs(correction));
410+
std::fabs(correction));
412411
}
413412

414413
result += correction;
415-
cutoff = tolerance * ::fabs(result) / static_cast<double>(n);
414+
cutoff = tolerance * std::fabs(result) / static_cast<double>(n);
416415
}
417416
}
418417

include/maths/CKMeansOnline.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <maths/CPRNG.h>
2626
#include <maths/CTypeConversions.h>
2727

28+
#include <cmath>
2829
#include <cstddef>
2930
#include <numeric>
3031
#include <utility>
@@ -376,7 +377,7 @@ class CKMeansOnline
376377
return;
377378
}
378379

379-
double alpha = ::exp(-m_DecayRate * time);
380+
double alpha = std::exp(-m_DecayRate * time);
380381
LOG_TRACE("alpha = " << alpha);
381382

382383
this->age(alpha);
@@ -462,7 +463,7 @@ class CKMeansOnline
462463
}
463464
else
464465
{
465-
std::size_t ni_ = static_cast<std::size_t>(::ceil(ni));
466+
std::size_t ni_ = static_cast<std::size_t>(std::ceil(ni));
466467
TDoublePoint v(m_Clusters[i].second);
467468
sampleGaussian(ni_, m, v.diagonal(), categorySamples);
468469
}
@@ -476,7 +477,7 @@ class CKMeansOnline
476477
LOG_TRACE("weights = " << core::CContainerPrinter::print(weights));
477478

478479
TDoublePointVec final;
479-
final.reserve(static_cast<std::size_t>(::ceil(std::accumulate(weights.begin(), weights.end(), 0.0))));
480+
final.reserve(static_cast<std::size_t>(std::ceil(std::accumulate(weights.begin(), weights.end(), 0.0))));
480481
TDoubleMeanAccumulator sample;
481482
for (;;)
482483
{

include/maths/CKdTree.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <maths/CTypeConversions.h>
1616

1717
#include <algorithm>
18+
#include <cmath>
1819
#include <cstddef>
1920
#include <vector>
2021

@@ -340,7 +341,7 @@ class CKdTree
340341
nextCoordinate,
341342
nearest,
342343
distanceToNearest);
343-
if (secondary && ::fabs(distanceToHyperplane) < distanceToNearest)
344+
if (secondary && std::fabs(distanceToHyperplane) < distanceToNearest)
344345
{
345346
nearest = this->nearestNeighbour(point,
346347
*secondary,
@@ -377,7 +378,7 @@ class CKdTree
377378

378379
std::size_t nextCoordinate = (coordinate + 1) % m_Dimension;
379380
this->nearestNeighbours(point, *primary, nextCoordinate, nearest);
380-
if (secondary && ::fabs(distanceToHyperplane) < nearest.biggest().first)
381+
if (secondary && std::fabs(distanceToHyperplane) < nearest.biggest().first)
381382
{
382383
this->nearestNeighbours(point, *secondary, nextCoordinate, nearest);
383384
}

include/maths/CLinearAlgebra.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1008,7 +1008,7 @@ struct SVector
10081008
double result = 0.0;
10091009
for (std::size_t i = 0u; i < m_X.size(); ++i)
10101010
{
1011-
result += ::fabs(static_cast<double>(m_X[i]));
1011+
result += std::fabs(static_cast<double>(m_X[i]));
10121012
}
10131013
return result;
10141014
}

0 commit comments

Comments
 (0)