Skip to content

[ML] Silence gcc warnings #1145

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Apr 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/maths/COutliers.h
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ class MATHS_EXPORT COutliers : private core::CNonInstantiatable {
std::size_t dimension);

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

//! \name Test Interface
//@{
Expand Down
1 change: 1 addition & 0 deletions include/test/CDataFrameAnalyzerTrainingFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class TEST_EXPORT CDataFrameAnalyzerTrainingFactory {
// TODO
return TDataFrameUPtr{};
}
return TDataFrameUPtr{};
}();

TLossUPtr loss;
Expand Down
1 change: 1 addition & 0 deletions lib/api/CDataFrameTrainBoostedTreeRegressionRunner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ CDataFrameTrainBoostedTreeRegressionRunner::lossFunction(const CDataFrameAnalysi
case E_Mse:
return std::make_unique<maths::boosted_tree::CMse>();
}
return nullptr;
}

CDataFrameTrainBoostedTreeRegressionRunner::CDataFrameTrainBoostedTreeRegressionRunner(
Expand Down
2 changes: 1 addition & 1 deletion lib/config/unittest/CReportWriterTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ BOOST_AUTO_TEST_CASE(testPretty) {
TDoubleVec weight;
TSizeVec index;
for (core_t::TTime time = startTime; time < endTime;
time += static_cast<double>(dt[0])) {
time += static_cast<core_t::TTime>(dt[0])) {
double progress = static_cast<double>(time - startTime) /
static_cast<double>((endTime - startTime));
if (progress > lastProgress + 0.05) {
Expand Down
14 changes: 9 additions & 5 deletions lib/maths/COutliers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@

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

#include <cmath>
#include <numeric>
#include <sstream>
#include <string>
#include <tuple>

namespace ml {
Expand All @@ -31,6 +33,7 @@ using namespace outliers_detail;
namespace {

const std::string COMPUTE_OUTLIER_SCORES{"compute_outlier_scores"};
const std::string EMPTY_STRING;

using TRowItr = core::CDataFrame::TRowItr;
using TStepCallback = std::function<void(const std::string&)>;
Expand Down Expand Up @@ -1121,19 +1124,20 @@ void COutliers::noopRecordProgress(double) {
void COutliers::noopRecordMemoryUsage(std::int64_t) {
}

std::string COutliers::print(EMethod method) {
const std::string& COutliers::print(EMethod method) {
switch (method) {
case E_Lof:
return LOF;
case maths::COutliers::E_Ldof:
case E_Ldof:
return LDOF;
case maths::COutliers::E_DistancekNN:
case E_DistancekNN:
return DISTANCE_KNN;
case maths::COutliers::E_TotalDistancekNN:
case E_TotalDistancekNN:
return TOTAL_DISTANCE_KNN;
case maths::COutliers::E_Ensemble:
case E_Ensemble:
return ENSEMBLE;
}
return EMPTY_STRING;
}

const std::string COutliers::LOF{"lof"};
Expand Down
3 changes: 2 additions & 1 deletion lib/maths/unittest/CMicTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ BOOST_AUTO_TEST_CASE(testOptimizeXAxis) {
mic.setup();

std::size_t k{5};
std::size_t ck{static_cast<std::size_t>(k * mic.maximumXAxisPartitionSizeToSearch())};
std::size_t ck{static_cast<std::size_t>(
static_cast<double>(k) * mic.maximumXAxisPartitionSizeToSearch())};

TDoubleVec pi(mic.equipartitionAxis(0, ck));
TDoubleVec q(mic.equipartitionAxis(1, k));
Expand Down
8 changes: 4 additions & 4 deletions lib/maths/unittest/CMultivariateMultimodalPriorTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -318,14 +318,14 @@ BOOST_AUTO_TEST_CASE(testMultipleModes) {
LOG_DEBUG(<< "Mixture Normals");
{
const TSizeVec n{400, 600};
const double means[][2] = {{10.0, 10.0}, {20.0, 20.0}};
const double covariances[][3] = {{4.0, 1.0, 4.0}, {10.0, -4.0, 6.0}};
const double means[][2]{{10.0, 10.0}, {20.0, 20.0}};
const double covariances[][3]{{4.0, 1.0, 4.0}, {10.0, -4.0, 6.0}};

TDouble10Vec1Vec samples;
gaussianSamples(rng, n, means, covariances, samples);

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

double loss = 0.0;
TMeanAccumulator differentialEntropy_;
Expand Down
6 changes: 4 additions & 2 deletions lib/maths/unittest/CPeriodicityHypothesisTestsTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,8 @@ BOOST_AUTO_TEST_CASE(testWithOutliers) {

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

for (const auto& bucketLength : bucketLengths) {
core_t::TTime buckets{window / bucketLength};
std::size_t numberOutliers{static_cast<std::size_t>(0.12 * buckets)};
std::size_t numberOutliers{
static_cast<std::size_t>(0.12 * static_cast<double>(buckets))};
rng.generateUniformSamples(0, buckets, numberOutliers, outliers);
rng.generateUniformSamples(0, 1.0, numberOutliers, spikeOrTroughSelector);
rng.generateNormalSamples(0.0, 9.0, buckets, noise);
Expand Down
2 changes: 1 addition & 1 deletion lib/maths/unittest/CRandomizedPeriodicityTestTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ BOOST_AUTO_TEST_CASE(testAccuracy) {
: falseNegatives[j - 3]) += 1.0;
if (rtests[j].test()) {
timeToDetectionMoments[j - 3].add(
time - lastTruePositive[j - 3]);
static_cast<double>(time - lastTruePositive[j - 3]));
timeToDetectionMax[j - 3].add(
static_cast<double>(time - lastTruePositive[j - 3]));
lastTruePositive[j - 3] = time;
Expand Down
26 changes: 16 additions & 10 deletions lib/maths/unittest/CTimeSeriesDecompositionTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1776,7 +1776,7 @@ BOOST_FIXTURE_TEST_CASE(testWithOutliers, CTestFixture) {
TDoubleVec spikeOrTroughSelector;

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

auto trend = [](core_t::TTime time) {
return 20.0 + 10.0 * std::sin(boost::math::double_constants::two_pi * time / DAY) +
return 20.0 +
10.0 * std::sin(boost::math::double_constants::two_pi *
static_cast<double>(time) / static_cast<double>(DAY)) +
3.0 * (time > 4 * WEEK
? std::sin(boost::math::double_constants::two_pi * time / HOUR)
? std::sin(boost::math::double_constants::two_pi *
static_cast<double>(time) / static_cast<double>(HOUR))
: 0.0) -
3.0 * (time > 9 * WEEK
? std::sin(boost::math::double_constants::two_pi * time / HOUR)
? std::sin(boost::math::double_constants::two_pi *
static_cast<double>(time) / static_cast<double>(HOUR))
: 0.0) +
8.0 * (time > 16 * WEEK
? std::sin(boost::math::double_constants::two_pi * time / 4 / DAY)
: 0.0) -
8.0 * (time > 21 * WEEK
? std::sin(boost::math::double_constants::two_pi * time / 4 / DAY)
: 0.0);
8.0 * (time > 16 * WEEK ? std::sin(boost::math::double_constants::two_pi *
static_cast<double>(time) /
4.0 / static_cast<double>(DAY))
: 0.0) -
8.0 * (time > 21 * WEEK ? std::sin(boost::math::double_constants::two_pi *
static_cast<double>(time) /
4.0 / static_cast<double>(DAY))
: 0.0);
};

maths::CTimeSeriesDecomposition decomposition(0.012, FIVE_MINS);
Expand Down
12 changes: 6 additions & 6 deletions lib/maths/unittest/CTreeShapFeatureImportanceTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,8 @@ class CBruteForceTreeShap {
if (m_Tree[nodeIndex].isLeaf()) {
return weight * m_Tree[nodeIndex].value();
} else {
auto leftChildIndex{m_Tree[nodeIndex].leftChildIndex()};
auto rightChildIndex{m_Tree[nodeIndex].rightChildIndex()};
auto leftChildIndex = m_Tree[nodeIndex].leftChildIndex();
auto rightChildIndex = m_Tree[nodeIndex].rightChildIndex();
if (S.find(m_Tree[nodeIndex].splitFeature()) != S.end()) {
if (m_Tree[nodeIndex].assignToLeft(x)) {
return this->conditionalExpectation(x, S, leftChildIndex, weight);
Expand All @@ -397,12 +397,12 @@ class CBruteForceTreeShap {
} else {
return this->conditionalExpectation(
x, S, leftChildIndex,
weight * m_Tree[leftChildIndex].numberSamples() /
m_Tree[nodeIndex].numberSamples()) +
weight * static_cast<double>(m_Tree[leftChildIndex].numberSamples()) /
static_cast<double>(m_Tree[nodeIndex].numberSamples())) +
this->conditionalExpectation(
x, S, rightChildIndex,
weight * m_Tree[rightChildIndex].numberSamples() /
m_Tree[nodeIndex].numberSamples());
weight * static_cast<double>(m_Tree[rightChildIndex].numberSamples()) /
static_cast<double>(m_Tree[nodeIndex].numberSamples()));
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/maths/unittest/CTrendComponentTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,9 @@ BOOST_AUTO_TEST_CASE(testDecayRate) {
for (core_t::TTime time = start; time < end; time += BUCKET_LENGTH) {
double value{values[(time - start) / BUCKET_LENGTH]};
component.add(time, value);
regression.add(time / 604800.0, value);
regression.add(static_cast<double>(time) / 604800.0, value);

double expectedPrediction{regression.predict(time / 604800.0)};
double expectedPrediction{regression.predict(static_cast<double>(time) / 604800.0)};
double prediction{maths::CBasicStatistics::mean(component.value(time, 0.0))};
error.add(std::fabs(prediction - expectedPrediction));
level.add(value);
Expand Down
3 changes: 2 additions & 1 deletion lib/model/CResourceMonitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,8 @@ std::size_t CResourceMonitor::adjustedUsage(std::size_t usage) const {
// This gives the user a fairer indication of how close the job is to hitting
// the model memory limit in a concise manner (as the limit is scaled down by
// the margin during the beginning period of the job's existence).
size_t adjustedUsage{static_cast<std::size_t>(usage / m_ByteLimitMargin)};
std::size_t adjustedUsage{
static_cast<std::size_t>(static_cast<double>(usage) / m_ByteLimitMargin)};

adjustedUsage *= this->persistenceMemoryIncreaseFactor();

Expand Down
2 changes: 1 addition & 1 deletion lib/model/CRuleCondition.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ bool CRuleCondition::test(const CAnomalyDetectorModel& model,
break;
}
case E_Time: {
value.push_back(time);
value.push_back(static_cast<double>(time));
break;
}
}
Expand Down
7 changes: 4 additions & 3 deletions lib/model/unittest/CEventRatePopulationDataGathererTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ BOOST_FIXTURE_TEST_CASE(testCompressedLength, CTestFixture) {
uniqueValues.begin(), uniqueValues.end(),
std::bind(&core::CCompressUtil::addString,
&compressor, std::placeholders::_1))));
size_t length(0);
std::size_t length(0);
BOOST_TEST_REQUIRE(compressor.length(true, length));
expectedBucketCompressedLengthPerPerson[key] = length;
}
Expand All @@ -539,8 +539,9 @@ BOOST_FIXTURE_TEST_CASE(testCompressedLength, CTestFixture) {
for (TSizeSizePrFeatureDataPrVec::const_iterator j =
bucketCompressedLengthPerPerson.begin();
j != bucketCompressedLengthPerPerson.end(); ++j) {
double expectedLength = expectedBucketCompressedLengthPerPerson[j->first];
double actual = j->second.s_Count;
double expectedLength = static_cast<double>(
expectedBucketCompressedLengthPerPerson[j->first]);
double actual = static_cast<double>(j->second.s_Count);
BOOST_REQUIRE_CLOSE_ABSOLUTE(expectedLength, actual, expectedLength * 0.1);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/model/unittest/CEventRatePopulationModelTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ BOOST_FIXTURE_TEST_CASE(testBasicAccessors, CTestFixture) {
BOOST_TEST_REQUIRE(gatherer->personId(message.s_Person, pid));
BOOST_TEST_REQUIRE(gatherer->attributeId(message.s_Attribute, cid));
++expectedBucketPersonCounts[pid];
expectedBucketPersonAttributeCounts[{pid, cid}] += 1.0;
++expectedBucketPersonAttributeCounts[{pid, cid}];
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/model/unittest/CSampleQueueTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1019,7 +1019,7 @@ BOOST_AUTO_TEST_CASE(testQualityOfSamplesGivenConstantRate) {
core_t::TTime measurementTime = static_cast<core_t::TTime>(testData[0]);
queue.add(measurementTime, {1.0}, 1u, sampleCount);
}
meanQueueSize.add(queue.size());
meanQueueSize.add(static_cast<double>(queue.size()));
queue.sample(latestTime, sampleCount, model_t::E_IndividualMeanByPerson, samples);

maths::CBasicStatistics::SSampleMeanVar<double>::TAccumulator varianceStat;
Expand Down