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
{

0 commit comments

Comments
 (0)