Skip to content

Commit cd091bb

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 ec28abd commit cd091bb

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
{

0 commit comments

Comments
 (0)