Skip to content

Commit 6c80c11

Browse files
authored
[7.8][ML] Silence gcc warnings (#1153)
Backport #1145.
1 parent 80a8e99 commit 6c80c11

17 files changed

+57
-40
lines changed

include/maths/COutliers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ class MATHS_EXPORT COutliers : private core::CNonInstantiatable {
719719
std::size_t dimension);
720720

721721
//! Return string representation of the \p method.
722-
static std::string print(EMethod method);
722+
static const std::string& print(EMethod method);
723723

724724
//! \name Test Interface
725725
//@{

include/test/CDataFrameAnalyzerTrainingFactory.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ class TEST_EXPORT CDataFrameAnalyzerTrainingFactory {
8181
// TODO
8282
return TDataFrameUPtr{};
8383
}
84+
return TDataFrameUPtr{};
8485
}();
8586

8687
TLossUPtr loss;

lib/api/CDataFrameTrainBoostedTreeRegressionRunner.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ CDataFrameTrainBoostedTreeRegressionRunner::lossFunction(const CDataFrameAnalysi
5656
case E_Mse:
5757
return std::make_unique<maths::boosted_tree::CMse>();
5858
}
59+
return nullptr;
5960
}
6061

6162
CDataFrameTrainBoostedTreeRegressionRunner::CDataFrameTrainBoostedTreeRegressionRunner(

lib/config/unittest/CReportWriterTest.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ BOOST_AUTO_TEST_CASE(testPretty) {
7474
TDoubleVec weight;
7575
TSizeVec index;
7676
for (core_t::TTime time = startTime; time < endTime;
77-
time += static_cast<double>(dt[0])) {
77+
time += static_cast<core_t::TTime>(dt[0])) {
7878
double progress = static_cast<double>(time - startTime) /
7979
static_cast<double>((endTime - startTime));
8080
if (progress > lastProgress + 0.05) {

lib/maths/COutliers.cc

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@
2121

2222
#include <boost/math/distributions/lognormal.hpp>
2323

24+
#include <cmath>
2425
#include <numeric>
2526
#include <sstream>
27+
#include <string>
2628
#include <tuple>
2729

2830
namespace ml {
@@ -32,6 +34,7 @@ using namespace outliers_detail;
3234
namespace {
3335

3436
const std::string COMPUTE_OUTLIER_SCORES{"compute_outlier_scores"};
37+
const std::string EMPTY_STRING;
3538

3639
using TRowItr = core::CDataFrame::TRowItr;
3740
using TStepCallback = std::function<void(const std::string&)>;
@@ -1124,19 +1127,20 @@ void COutliers::noopRecordProgress(double) {
11241127
void COutliers::noopRecordMemoryUsage(std::int64_t) {
11251128
}
11261129

1127-
std::string COutliers::print(EMethod method) {
1130+
const std::string& COutliers::print(EMethod method) {
11281131
switch (method) {
11291132
case E_Lof:
11301133
return LOF;
1131-
case maths::COutliers::E_Ldof:
1134+
case E_Ldof:
11321135
return LDOF;
1133-
case maths::COutliers::E_DistancekNN:
1136+
case E_DistancekNN:
11341137
return DISTANCE_KNN;
1135-
case maths::COutliers::E_TotalDistancekNN:
1138+
case E_TotalDistancekNN:
11361139
return TOTAL_DISTANCE_KNN;
1137-
case maths::COutliers::E_Ensemble:
1140+
case E_Ensemble:
11381141
return ENSEMBLE;
11391142
}
1143+
return EMPTY_STRING;
11401144
}
11411145

11421146
const std::string COutliers::LOF{"lof"};

lib/maths/unittest/CMicTest.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ BOOST_AUTO_TEST_CASE(testOptimizeXAxis) {
8787
mic.setup();
8888

8989
std::size_t k{5};
90-
std::size_t ck{static_cast<std::size_t>(k * mic.maximumXAxisPartitionSizeToSearch())};
90+
std::size_t ck{static_cast<std::size_t>(
91+
static_cast<double>(k) * mic.maximumXAxisPartitionSizeToSearch())};
9192

9293
TDoubleVec pi(mic.equipartitionAxis(0, ck));
9394
TDoubleVec q(mic.equipartitionAxis(1, k));

lib/maths/unittest/CMultivariateMultimodalPriorTest.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -318,14 +318,14 @@ BOOST_AUTO_TEST_CASE(testMultipleModes) {
318318
LOG_DEBUG(<< "Mixture Normals");
319319
{
320320
const TSizeVec n{400, 600};
321-
const double means[][2] = {{10.0, 10.0}, {20.0, 20.0}};
322-
const double covariances[][3] = {{4.0, 1.0, 4.0}, {10.0, -4.0, 6.0}};
321+
const double means[][2]{{10.0, 10.0}, {20.0, 20.0}};
322+
const double covariances[][3]{{4.0, 1.0, 4.0}, {10.0, -4.0, 6.0}};
323323

324324
TDouble10Vec1Vec samples;
325325
gaussianSamples(rng, n, means, covariances, samples);
326326

327-
double w[] = {n[0] / static_cast<double>(n[0] + n[1]),
328-
n[1] / static_cast<double>(n[0] + n[1])};
327+
double w[]{static_cast<double>(n[0]) / static_cast<double>(n[0] + n[1]),
328+
static_cast<double>(n[1]) / static_cast<double>(n[0] + n[1])};
329329

330330
double loss = 0.0;
331331
TMeanAccumulator differentialEntropy_;

lib/maths/unittest/CPeriodicityHypothesisTestsTest.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,8 @@ BOOST_AUTO_TEST_CASE(testWithOutliers) {
582582

583583
for (const auto& bucketLength : bucketLengths) {
584584
core_t::TTime buckets{window / bucketLength};
585-
std::size_t numberOutliers{static_cast<std::size_t>(0.12 * buckets)};
585+
std::size_t numberOutliers{
586+
static_cast<std::size_t>(0.12 * static_cast<double>(buckets))};
586587
rng.generateUniformSamples(0, buckets, numberOutliers, outliers);
587588
rng.generateUniformSamples(0, 1.0, numberOutliers, spikeOrTroughSelector);
588589
rng.generateNormalSamples(0.0, 9.0, buckets, noise);
@@ -632,7 +633,8 @@ BOOST_AUTO_TEST_CASE(testWithOutliers) {
632633

633634
for (const auto& bucketLength : bucketLengths) {
634635
core_t::TTime buckets{window / bucketLength};
635-
std::size_t numberOutliers{static_cast<std::size_t>(0.12 * buckets)};
636+
std::size_t numberOutliers{
637+
static_cast<std::size_t>(0.12 * static_cast<double>(buckets))};
636638
rng.generateUniformSamples(0, buckets, numberOutliers, outliers);
637639
rng.generateUniformSamples(0, 1.0, numberOutliers, spikeOrTroughSelector);
638640
rng.generateNormalSamples(0.0, 9.0, buckets, noise);

lib/maths/unittest/CRandomizedPeriodicityTestTest.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ BOOST_AUTO_TEST_CASE(testAccuracy) {
8787
: falseNegatives[j - 3]) += 1.0;
8888
if (rtests[j].test()) {
8989
timeToDetectionMoments[j - 3].add(
90-
time - lastTruePositive[j - 3]);
90+
static_cast<double>(time - lastTruePositive[j - 3]));
9191
timeToDetectionMax[j - 3].add(
9292
static_cast<double>(time - lastTruePositive[j - 3]));
9393
lastTruePositive[j - 3] = time;

lib/maths/unittest/CTimeSeriesDecompositionTest.cc

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1776,7 +1776,7 @@ BOOST_FIXTURE_TEST_CASE(testWithOutliers, CTestFixture) {
17761776
TDoubleVec spikeOrTroughSelector;
17771777

17781778
core_t::TTime buckets{WEEK / TEN_MINS};
1779-
std::size_t numberOutliers{static_cast<std::size_t>(0.1 * buckets)};
1779+
std::size_t numberOutliers{static_cast<std::size_t>(0.1 * static_cast<double>(buckets))};
17801780
rng.generateUniformSamples(0, buckets, numberOutliers, outliers);
17811781
rng.generateUniformSamples(0, 1.0, numberOutliers, spikeOrTroughSelector);
17821782
rng.generateNormalSamples(0.0, 9.0, buckets, noise);
@@ -1920,19 +1920,25 @@ BOOST_FIXTURE_TEST_CASE(testComponentLifecycle, CTestFixture) {
19201920
test::CRandomNumbers rng;
19211921

19221922
auto trend = [](core_t::TTime time) {
1923-
return 20.0 + 10.0 * std::sin(boost::math::double_constants::two_pi * time / DAY) +
1923+
return 20.0 +
1924+
10.0 * std::sin(boost::math::double_constants::two_pi *
1925+
static_cast<double>(time) / static_cast<double>(DAY)) +
19241926
3.0 * (time > 4 * WEEK
1925-
? std::sin(boost::math::double_constants::two_pi * time / HOUR)
1927+
? std::sin(boost::math::double_constants::two_pi *
1928+
static_cast<double>(time) / static_cast<double>(HOUR))
19261929
: 0.0) -
19271930
3.0 * (time > 9 * WEEK
1928-
? std::sin(boost::math::double_constants::two_pi * time / HOUR)
1931+
? std::sin(boost::math::double_constants::two_pi *
1932+
static_cast<double>(time) / static_cast<double>(HOUR))
19291933
: 0.0) +
1930-
8.0 * (time > 16 * WEEK
1931-
? std::sin(boost::math::double_constants::two_pi * time / 4 / DAY)
1932-
: 0.0) -
1933-
8.0 * (time > 21 * WEEK
1934-
? std::sin(boost::math::double_constants::two_pi * time / 4 / DAY)
1935-
: 0.0);
1934+
8.0 * (time > 16 * WEEK ? std::sin(boost::math::double_constants::two_pi *
1935+
static_cast<double>(time) /
1936+
4.0 / static_cast<double>(DAY))
1937+
: 0.0) -
1938+
8.0 * (time > 21 * WEEK ? std::sin(boost::math::double_constants::two_pi *
1939+
static_cast<double>(time) /
1940+
4.0 / static_cast<double>(DAY))
1941+
: 0.0);
19361942
};
19371943

19381944
maths::CTimeSeriesDecomposition decomposition(0.012, FIVE_MINS);

lib/maths/unittest/CTreeShapFeatureImportanceTest.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -386,8 +386,8 @@ class CBruteForceTreeShap {
386386
if (m_Tree[nodeIndex].isLeaf()) {
387387
return weight * m_Tree[nodeIndex].value();
388388
} else {
389-
auto leftChildIndex{m_Tree[nodeIndex].leftChildIndex()};
390-
auto rightChildIndex{m_Tree[nodeIndex].rightChildIndex()};
389+
auto leftChildIndex = m_Tree[nodeIndex].leftChildIndex();
390+
auto rightChildIndex = m_Tree[nodeIndex].rightChildIndex();
391391
if (S.find(m_Tree[nodeIndex].splitFeature()) != S.end()) {
392392
if (m_Tree[nodeIndex].assignToLeft(x)) {
393393
return this->conditionalExpectation(x, S, leftChildIndex, weight);
@@ -397,12 +397,12 @@ class CBruteForceTreeShap {
397397
} else {
398398
return this->conditionalExpectation(
399399
x, S, leftChildIndex,
400-
weight * m_Tree[leftChildIndex].numberSamples() /
401-
m_Tree[nodeIndex].numberSamples()) +
400+
weight * static_cast<double>(m_Tree[leftChildIndex].numberSamples()) /
401+
static_cast<double>(m_Tree[nodeIndex].numberSamples())) +
402402
this->conditionalExpectation(
403403
x, S, rightChildIndex,
404-
weight * m_Tree[rightChildIndex].numberSamples() /
405-
m_Tree[nodeIndex].numberSamples());
404+
weight * static_cast<double>(m_Tree[rightChildIndex].numberSamples()) /
405+
static_cast<double>(m_Tree[nodeIndex].numberSamples()));
406406
}
407407
}
408408
}

lib/maths/unittest/CTrendComponentTest.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,9 +280,9 @@ BOOST_AUTO_TEST_CASE(testDecayRate) {
280280
for (core_t::TTime time = start; time < end; time += BUCKET_LENGTH) {
281281
double value{values[(time - start) / BUCKET_LENGTH]};
282282
component.add(time, value);
283-
regression.add(time / 604800.0, value);
283+
regression.add(static_cast<double>(time) / 604800.0, value);
284284

285-
double expectedPrediction{regression.predict(time / 604800.0)};
285+
double expectedPrediction{regression.predict(static_cast<double>(time) / 604800.0)};
286286
double prediction{maths::CBasicStatistics::mean(component.value(time, 0.0))};
287287
error.add(std::fabs(prediction - expectedPrediction));
288288
level.add(value);

lib/model/CResourceMonitor.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,8 @@ std::size_t CResourceMonitor::adjustedUsage(std::size_t usage) const {
281281
// This gives the user a fairer indication of how close the job is to hitting
282282
// the model memory limit in a concise manner (as the limit is scaled down by
283283
// the margin during the beginning period of the job's existence).
284-
size_t adjustedUsage{static_cast<std::size_t>(usage / m_ByteLimitMargin)};
284+
std::size_t adjustedUsage{
285+
static_cast<std::size_t>(static_cast<double>(usage) / m_ByteLimitMargin)};
285286

286287
adjustedUsage *= this->persistenceMemoryIncreaseFactor();
287288

lib/model/CRuleCondition.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ bool CRuleCondition::test(const CAnomalyDetectorModel& model,
7676
break;
7777
}
7878
case E_Time: {
79-
value.push_back(time);
79+
value.push_back(static_cast<double>(time));
8080
break;
8181
}
8282
}

lib/model/unittest/CEventRatePopulationDataGathererTest.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ BOOST_FIXTURE_TEST_CASE(testCompressedLength, CTestFixture) {
528528
uniqueValues.begin(), uniqueValues.end(),
529529
std::bind(&core::CCompressUtil::addString,
530530
&compressor, std::placeholders::_1))));
531-
size_t length(0);
531+
std::size_t length(0);
532532
BOOST_TEST_REQUIRE(compressor.length(true, length));
533533
expectedBucketCompressedLengthPerPerson[key] = length;
534534
}
@@ -539,8 +539,9 @@ BOOST_FIXTURE_TEST_CASE(testCompressedLength, CTestFixture) {
539539
for (TSizeSizePrFeatureDataPrVec::const_iterator j =
540540
bucketCompressedLengthPerPerson.begin();
541541
j != bucketCompressedLengthPerPerson.end(); ++j) {
542-
double expectedLength = expectedBucketCompressedLengthPerPerson[j->first];
543-
double actual = j->second.s_Count;
542+
double expectedLength = static_cast<double>(
543+
expectedBucketCompressedLengthPerPerson[j->first]);
544+
double actual = static_cast<double>(j->second.s_Count);
544545
BOOST_REQUIRE_CLOSE_ABSOLUTE(expectedLength, actual, expectedLength * 0.1);
545546
}
546547

lib/model/unittest/CEventRatePopulationModelTest.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ BOOST_FIXTURE_TEST_CASE(testBasicAccessors, CTestFixture) {
308308
BOOST_TEST_REQUIRE(gatherer->personId(message.s_Person, pid));
309309
BOOST_TEST_REQUIRE(gatherer->attributeId(message.s_Attribute, cid));
310310
++expectedBucketPersonCounts[pid];
311-
expectedBucketPersonAttributeCounts[{pid, cid}] += 1.0;
311+
++expectedBucketPersonAttributeCounts[{pid, cid}];
312312
}
313313
}
314314

lib/model/unittest/CSampleQueueTest.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1019,7 +1019,7 @@ BOOST_AUTO_TEST_CASE(testQualityOfSamplesGivenConstantRate) {
10191019
core_t::TTime measurementTime = static_cast<core_t::TTime>(testData[0]);
10201020
queue.add(measurementTime, {1.0}, 1u, sampleCount);
10211021
}
1022-
meanQueueSize.add(queue.size());
1022+
meanQueueSize.add(static_cast<double>(queue.size()));
10231023
queue.sample(latestTime, sampleCount, model_t::E_IndividualMeanByPerson, samples);
10241024

10251025
maths::CBasicStatistics::SSampleMeanVar<double>::TAccumulator varianceStat;

0 commit comments

Comments
 (0)