Skip to content

Commit cd2a6d4

Browse files
committed
[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 d445421 commit cd2a6d4

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
@@ -65,7 +65,7 @@
6565

6666
int main(int argc, char **argv)
6767
{
68-
typedef ml::autodetect::CCmdLineParser::TStrVec TStrVec;
68+
using TStrVec = ml::autodetect::CCmdLineParser::TStrVec;
6969

7070
// Read command line options
7171
std::string limitConfigFile;
@@ -216,7 +216,7 @@ int main(int argc, char **argv)
216216
return EXIT_FAILURE;
217217
}
218218

219-
typedef boost::scoped_ptr<ml::core::CDataSearcher> TScopedDataSearcherP;
219+
using TScopedDataSearcherP = boost::scoped_ptr<ml::core::CDataSearcher>;
220220
TScopedDataSearcherP restoreSearcher;
221221
if (ioMgr.restoreStream() != 0)
222222
{
@@ -236,14 +236,14 @@ int main(int argc, char **argv)
236236
}
237237
}
238238

239-
typedef boost::scoped_ptr<ml::core::CDataAdder> TScopedDataAdderP;
239+
using TScopedDataAdderP = boost::scoped_ptr<ml::core::CDataAdder>;
240240
TScopedDataAdderP persister;
241241
if (ioMgr.persistStream() != 0)
242242
{
243243
persister.reset(new ml::api::CSingleStreamDataAdder(ioMgr.persistStream()));
244244
}
245245

246-
typedef boost::scoped_ptr<ml::api::CBackgroundPersister> TScopedBackgroundPersisterP;
246+
using TScopedBackgroundPersisterP = boost::scoped_ptr<ml::api::CBackgroundPersister>;
247247
TScopedBackgroundPersisterP periodicPersister;
248248
if (persistInterval >= 0)
249249
{
@@ -258,7 +258,7 @@ int main(int argc, char **argv)
258258
*persister));
259259
}
260260

261-
typedef boost::scoped_ptr<ml::api::CInputParser> TScopedInputParserP;
261+
using TScopedInputParserP = boost::scoped_ptr<ml::api::CInputParser>;
262262
TScopedInputParserP inputParser;
263263
if (lengthEncodedInput)
264264
{

bin/categorize/Main.cc

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

153-
typedef boost::scoped_ptr<ml::core::CDataSearcher> TScopedDataSearcherP;
153+
using TScopedDataSearcherP = boost::scoped_ptr<ml::core::CDataSearcher>;
154154
TScopedDataSearcherP restoreSearcher;
155155
if (ioMgr.restoreStream() != 0)
156156
{
@@ -170,14 +170,14 @@ int main(int argc, char **argv)
170170
}
171171
}
172172

173-
typedef boost::scoped_ptr<ml::core::CDataAdder> TScopedDataAdderP;
173+
using TScopedDataAdderP = boost::scoped_ptr<ml::core::CDataAdder>;
174174
TScopedDataAdderP persister;
175175
if (ioMgr.persistStream() != 0)
176176
{
177177
persister.reset(new ml::api::CSingleStreamDataAdder(ioMgr.persistStream()));
178178
}
179179

180-
typedef boost::scoped_ptr<ml::api::CBackgroundPersister> TScopedBackgroundPersisterP;
180+
using TScopedBackgroundPersisterP = boost::scoped_ptr<ml::api::CBackgroundPersister>;
181181
TScopedBackgroundPersisterP periodicPersister;
182182
if (persistInterval >= 0)
183183
{
@@ -192,7 +192,7 @@ int main(int argc, char **argv)
192192
*persister));
193193
}
194194

195-
typedef boost::scoped_ptr<ml::api::CInputParser> TScopedInputParserP;
195+
using TScopedInputParserP = boost::scoped_ptr<ml::api::CInputParser>;
196196
TScopedInputParserP inputParser;
197197
if (lengthEncodedInput)
198198
{

bin/normalize/Main.cc

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

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

135-
typedef boost::scoped_ptr<ml::api::COutputHandler> TScopedOutputHandlerP;
135+
using TScopedOutputHandlerP = boost::scoped_ptr<ml::api::COutputHandler>;
136136
TScopedOutputHandlerP outputWriter;
137137
if (writeCsv)
138138
{

include/core/CFloatStorage.h

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

2222
#include <maths/ImportExport.h>
2323

24+
#include <cmath>
2425
#include <limits>
2526

26-
#include <math.h>
27-
28-
2927
namespace ml
3028
{
3129
namespace core
@@ -35,7 +33,7 @@ namespace
3533
{
3634
const int MAX_PRECISE_INTEGER_FLOAT(
3735
static_cast<int>(
38-
::pow(10.0,
36+
std::pow(10.0,
3937
static_cast<double>(std::numeric_limits<float>::digits10))
4038
) - 1
4139
);

include/core/Constants.h

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

1919
#include <core/CoreTypes.h>
2020

21+
#include <cmath>
2122
#include <limits>
22-
#include <math.h>
2323

2424
namespace ml
2525
{
@@ -47,13 +47,13 @@ const core_t::TTime WEEK = 604800;
4747
const core_t::TTime YEAR = 31449600;
4848

4949
//! Log of min double.
50-
const double LOG_MIN_DOUBLE = ::log(std::numeric_limits<double>::min());
50+
const double LOG_MIN_DOUBLE = std::log(std::numeric_limits<double>::min());
5151

5252
//! Log of max double.
53-
const double LOG_MAX_DOUBLE = ::log(std::numeric_limits<double>::max());
53+
const double LOG_MAX_DOUBLE = std::log(std::numeric_limits<double>::max());
5454

5555
//! Log of double epsilon.
56-
const double LOG_DOUBLE_EPSILON = ::log(std::numeric_limits<double>::epsilon());
56+
const double LOG_DOUBLE_EPSILON = std::log(std::numeric_limits<double>::epsilon());
5757

5858
//! Log of two.
5959
const double LOG_TWO = 0.693147180559945;

include/maths/CCompositeFunctions.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@
2121
#include <boost/type_traits/integral_constant.hpp>
2222
#include <boost/type_traits/remove_reference.hpp>
2323

24+
#include <cmath>
2425
#include <limits>
2526

26-
#include <math.h>
27-
2827
namespace ml
2928
{
3029
namespace maths
@@ -225,19 +224,19 @@ class MATHS_EXPORT CCompositeFunctions
225224
inline T operator()(double x) 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
double fx = m_F(x);
230-
return fx < LOG_MIN_DOUBLE ? 0.0 : ::exp(fx);
229+
return fx < LOG_MIN_DOUBLE ? 0.0 : std::exp(fx);
231230
}
232231

233232
//! For function return success/fail and taking result as argument.
234233
inline bool operator()(double x, T &result) const
235234
{
236235
static const double LOG_MIN_DOUBLE =
237-
::log(std::numeric_limits<double>::min());
236+
std::log(std::numeric_limits<double>::min());
238237
if (m_F(x, result))
239238
{
240-
result = result < LOG_MIN_DOUBLE ? 0.0 : ::exp(result);
239+
result = result < LOG_MIN_DOUBLE ? 0.0 : std::exp(result);
241240
return true;
242241
}
243242
return false;

include/maths/CEqualWithTolerance.h

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

2323
#include <functional>
2424

25-
#include <math.h>
26-
2725
namespace ml
2826
{
2927
namespace maths

include/maths/CGradientDescent.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <maths/CLinearAlgebra.h>
2323
#include <maths/ImportExport.h>
2424

25+
#include <cmath>
2526
#include <cstddef>
2627
#include <vector>
2728

include/maths/CGramSchmidt.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ class MATHS_EXPORT CGramSchmidt : private core::CNonInstantiatable
154154
<< ", norm = " << n
155155
<< ", eps = " << eps);
156156

157-
if (::fabs(n) > eps)
157+
if (std::fabs(n) > eps)
158158
{
159159
divide(x[current], n);
160160
++current;

include/maths/CInformationCriteria.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <maths/CSphericalCluster.h>
2424
#include <maths/ImportExport.h>
2525

26+
#include <cmath>
2627
#include <cstddef>
2728
#include <limits>
2829
#include <vector>
@@ -196,7 +197,7 @@ class CSphericalGaussianInfoCriterion
196197
m_Likelihood += ni * log(ni)
197198
- 0.5 * m_D * ni * ( 1.0
198199
+ core::constants::LOG_TWO_PI
199-
+ ::log(upper * vi / m_D));
200+
+ std::log(upper * vi / m_D));
200201
}
201202
else
202203
{
@@ -215,7 +216,7 @@ class CSphericalGaussianInfoCriterion
215216
return 0.0;
216217
}
217218

218-
double logN = ::log(m_N);
219+
double logN = std::log(m_N);
219220
double p = (m_D * m_K + 2.0 * m_K - 1.0);
220221
switch (TYPE)
221222
{
@@ -327,7 +328,7 @@ class CGaussianInfoCriterion
327328
return 0.0;
328329
}
329330

330-
double logN = ::log(m_N);
331+
double logN = std::log(m_N);
331332
double p = (m_D * (1.0 + 0.5 * (m_D + 1.0)) * m_K + m_K - 1.0);
332333
switch (TYPE)
333334
{

include/maths/CIntegration.h

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,10 @@
2929
#include <maths/ImportExport.h>
3030

3131
#include <algorithm>
32+
#include <cmath>
3233
#include <functional>
3334
#include <numeric>
3435

35-
#include <math.h>
36-
3736
namespace ml
3837
{
3938
namespace maths
@@ -223,7 +222,7 @@ class MATHS_EXPORT CIntegration
223222
//! of the integral is returned. This is intended to support integration
224223
//! where the integrand is very small and may underflow double. This is
225224
//! handled by renormalizing the integral so only underflows if values
226-
//! are less than ::exp(-std::numeric_limits<double>::max()), so really
225+
//! are less than std::exp(-std::numeric_limits<double>::max()), so really
227226
//! very small!
228227
//!
229228
//! \param[in] function The log of the function to integrate.
@@ -270,7 +269,7 @@ class MATHS_EXPORT CIntegration
270269
double fmax = *std::max_element(fx, fx + ORDER);
271270
for (unsigned int i = 0; i < ORDER; ++i)
272271
{
273-
fx[i] = ::exp(fx[i] - fmax);
272+
fx[i] = std::exp(fx[i] - fmax);
274273
}
275274

276275
// Quadrature.
@@ -279,7 +278,7 @@ class MATHS_EXPORT CIntegration
279278
result += weights[i] * fx[i];
280279
}
281280
result *= range;
282-
result = result <= 0.0 ? core::constants::LOG_MIN_DOUBLE : fmax + ::log(result);
281+
result = result <= 0.0 ? core::constants::LOG_MIN_DOUBLE : fmax + std::log(result);
283282

284283
return true;
285284
}
@@ -333,15 +332,15 @@ class MATHS_EXPORT CIntegration
333332
corrections.reserve(fIntervals.size());
334333
for (std::size_t i = 0u; i < fIntervals.size(); ++i)
335334
{
336-
corrections.push_back(::fabs(fIntervals[i]));
335+
corrections.push_back(std::fabs(fIntervals[i]));
337336
}
338337

339338
for (std::size_t i = 0u;
340339
!intervals.empty() && i < refinements;
341340
++i)
342341
{
343342
std::size_t n = intervals.size();
344-
double cutoff = tolerance * ::fabs(result) / static_cast<double>(n);
343+
double cutoff = tolerance * std::fabs(result) / static_cast<double>(n);
345344

346345
std::size_t end = 0u;
347346
for (std::size_t j = 0u; j < corrections.size(); ++j)
@@ -415,13 +414,13 @@ class MATHS_EXPORT CIntegration
415414
double correction = fjNew - fjOld;
416415
if (i + 1 < refinements)
417416
{
418-
corrections[j] = ::fabs(correction);
417+
corrections[j] = std::fabs(correction);
419418
corrections.resize(corrections.size() + splitsPerRefinement - 1,
420-
::fabs(correction));
419+
std::fabs(correction));
421420
}
422421

423422
result += correction;
424-
cutoff = tolerance * ::fabs(result) / static_cast<double>(n);
423+
cutoff = tolerance * std::fabs(result) / static_cast<double>(n);
425424
}
426425
}
427426

include/maths/CKMeansOnline.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include <maths/CPRNG.h>
3535
#include <maths/CTypeConversions.h>
3636

37+
#include <cmath>
3738
#include <cstddef>
3839
#include <numeric>
3940
#include <utility>
@@ -385,7 +386,7 @@ class CKMeansOnline
385386
return;
386387
}
387388

388-
double alpha = ::exp(-m_DecayRate * time);
389+
double alpha = std::exp(-m_DecayRate * time);
389390
LOG_TRACE("alpha = " << alpha);
390391

391392
this->age(alpha);
@@ -471,7 +472,7 @@ class CKMeansOnline
471472
}
472473
else
473474
{
474-
std::size_t ni_ = static_cast<std::size_t>(::ceil(ni));
475+
std::size_t ni_ = static_cast<std::size_t>(std::ceil(ni));
475476
TDoublePoint v(m_Clusters[i].second);
476477
sampleGaussian(ni_, m, v.diagonal(), categorySamples);
477478
}
@@ -485,7 +486,7 @@ class CKMeansOnline
485486
LOG_TRACE("weights = " << core::CContainerPrinter::print(weights));
486487

487488
TDoublePointVec final;
488-
final.reserve(static_cast<std::size_t>(::ceil(std::accumulate(weights.begin(), weights.end(), 0.0))));
489+
final.reserve(static_cast<std::size_t>(std::ceil(std::accumulate(weights.begin(), weights.end(), 0.0))));
489490
TDoubleMeanAccumulator sample;
490491
for (;;)
491492
{

include/maths/CKdTree.h

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

2626
#include <algorithm>
27+
#include <cmath>
2728
#include <cstddef>
2829
#include <vector>
2930

@@ -349,7 +350,7 @@ class CKdTree
349350
nextCoordinate,
350351
nearest,
351352
distanceToNearest);
352-
if (secondary && ::fabs(distanceToHyperplane) < distanceToNearest)
353+
if (secondary && std::fabs(distanceToHyperplane) < distanceToNearest)
353354
{
354355
nearest = this->nearestNeighbour(point,
355356
*secondary,
@@ -386,7 +387,7 @@ class CKdTree
386387

387388
std::size_t nextCoordinate = (coordinate + 1) % m_Dimension;
388389
this->nearestNeighbours(point, *primary, nextCoordinate, nearest);
389-
if (secondary && ::fabs(distanceToHyperplane) < nearest.biggest().first)
390+
if (secondary && std::fabs(distanceToHyperplane) < nearest.biggest().first)
390391
{
391392
this->nearestNeighbours(point, *secondary, nextCoordinate, nearest);
392393
}

include/maths/CLinearAlgebra.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1017,7 +1017,7 @@ struct SVector
10171017
double result = 0.0;
10181018
for (std::size_t i = 0u; i < m_X.size(); ++i)
10191019
{
1020-
result += ::fabs(static_cast<double>(m_X[i]));
1020+
result += std::fabs(static_cast<double>(m_X[i]));
10211021
}
10221022
return result;
10231023
}

0 commit comments

Comments
 (0)