Skip to content

[ML] Replace std::auto_ptr with std::unique_ptr #717

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 1 commit into from
Oct 4, 2019
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
6 changes: 3 additions & 3 deletions include/core/CContainerPrinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,10 @@ class CORE_EXPORT CContainerPrinter : private CNonInstantiatable {
return result.str();
}

//! Print a std::auto_ptr.
//! Print a std::unique_ptr.
template<typename T>
static std::string printElement(const std::auto_ptr<T>& value) {
if (value.get() == nullptr) {
static std::string printElement(const std::unique_ptr<T>& value) {
if (value == nullptr) {
return "\"null\"";
}
std::ostringstream result;
Expand Down
4 changes: 2 additions & 2 deletions include/model/CAnomalyDetectorModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class MODEL_EXPORT CAnomalyDetectorModel {
using TFeatureCorrelationsPtrPr = std::pair<model_t::EFeature, TCorrelationsPtr>;
using TFeatureCorrelationsPtrPrVec = std::vector<TFeatureCorrelationsPtrPr>;
using TDataGathererPtr = std::shared_ptr<CDataGatherer>;
using CModelDetailsViewPtr = std::auto_ptr<CModelDetailsView>;
using TModelDetailsViewUPtr = std::unique_ptr<CModelDetailsView>;
using TModelPtr = std::unique_ptr<CAnomalyDetectorModel>;

public:
Expand Down Expand Up @@ -471,7 +471,7 @@ class MODEL_EXPORT CAnomalyDetectorModel {
core_t::TTime bucketLength() const;

//! Get a view of the internals of the model for visualization.
virtual CModelDetailsViewPtr details() const = 0;
virtual TModelDetailsViewUPtr details() const = 0;

//! Get the frequency of the person identified by \p pid.
double personFrequency(std::size_t pid) const;
Expand Down
2 changes: 1 addition & 1 deletion include/model/CCountingModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ class MODEL_EXPORT CCountingModel : public CAnomalyDetectorModel {
std::size_t staticSize() const override;

//! Returns null.
CModelDetailsViewPtr details() const override;
TModelDetailsViewUPtr details() const override;

//! Get the descriptions of any occurring scheduled event descriptions for the bucket time
const TStr1Vec& scheduledEventDescriptions(core_t::TTime time) const override;
Expand Down
2 changes: 1 addition & 1 deletion include/model/CEventRateModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ class MODEL_EXPORT CEventRateModel : public CIndividualModel {
std::size_t computeMemoryUsage() const override;

//! Get a view of the internals of the model for visualization.
CModelDetailsViewPtr details() const override;
TModelDetailsViewUPtr details() const override;

//! Get the value of the \p feature of the person identified
//! by \p pid for the bucketing interval containing \p time.
Expand Down
2 changes: 1 addition & 1 deletion include/model/CEventRatePopulationModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ class MODEL_EXPORT CEventRatePopulationModel : public CPopulationModel {
std::size_t computeMemoryUsage() const override;

//! Get a view of the internals of the model for visualization.
CModelDetailsViewPtr details() const override;
TModelDetailsViewUPtr details() const override;

//! Get the feature data corresponding to \p feature at \p time.
const TSizeSizePrFeatureDataPrVec& featureData(model_t::EFeature feature,
Expand Down
2 changes: 1 addition & 1 deletion include/model/CMetricModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ class MODEL_EXPORT CMetricModel : public CIndividualModel {
std::size_t computeMemoryUsage() const override;

//! Get a view of the internals of the model for visualization.
CModelDetailsViewPtr details() const override;
TModelDetailsViewUPtr details() const override;

//! Get the value of the \p feature of the person identified
//! by \p pid for the bucketing interval containing \p time.
Expand Down
2 changes: 1 addition & 1 deletion include/model/CMetricPopulationModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ class MODEL_EXPORT CMetricPopulationModel : public CPopulationModel {
uint64_t checksum(bool includeCurrentBucketStats = true) const override;

//! Get a view of the internals of the model for visualization.
CModelDetailsViewPtr details() const override;
TModelDetailsViewUPtr details() const override;

//! Get the feature data corresponding to \p feature at \p time.
const TSizeSizePrFeatureDataPrVec& featureData(model_t::EFeature feature,
Expand Down
6 changes: 3 additions & 3 deletions lib/core/unittest/CContainerPrinterTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ void CContainerPrinterTest::testAll() {
CPPUNIT_ASSERT_EQUAL(std::string("[(1, \"null\"), (1.1, 3), (3.3, 5.1)]"),
CContainerPrinter::print(map));

std::auto_ptr<int> pints[] = {std::auto_ptr<int>(new int(2)),
std::auto_ptr<int>(new int(3)),
std::auto_ptr<int>(new int(2))};
std::unique_ptr<int> pints[] = {std::unique_ptr<int>(new int(2)),
std::unique_ptr<int>(new int(3)),
std::unique_ptr<int>(new int(2))};
LOG_DEBUG(<< "pints = "
<< CContainerPrinter::print(std::begin(pints), std::end(pints)));
CPPUNIT_ASSERT_EQUAL(std::string("[2, 3, 2]"),
Expand Down
8 changes: 4 additions & 4 deletions lib/model/CAnomalyDetector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace model {
// We use short field names to reduce the state size
namespace {

using TModelDetailsViewPtr = CAnomalyDetectorModel::CModelDetailsViewPtr;
using TModelDetailsViewUPtr = CAnomalyDetectorModel::TModelDetailsViewUPtr;

// tag 'a' was previously used for persisting first time;
// DO NOT USE; unless it is decided to break model state BWC
Expand Down Expand Up @@ -439,7 +439,7 @@ void CAnomalyDetector::generateModelPlot(core_t::TTime bucketStartTime,
if (terms.empty() || m_DataGatherer->partitionFieldValue().empty() ||
terms.find(m_DataGatherer->partitionFieldValue()) != terms.end()) {
const CSearchKey& key = m_DataGatherer->searchKey();
TModelDetailsViewPtr view = m_Model.get()->details();
TModelDetailsViewUPtr view = m_Model.get()->details();
if (view.get()) {
core_t::TTime bucketLength = m_ModelConfig.bucketLength();
for (core_t::TTime time = bucketStartTime; time < bucketEndTime;
Expand All @@ -458,7 +458,7 @@ CForecastDataSink::SForecastModelPrerequisites
CAnomalyDetector::getForecastPrerequisites() const {
CForecastDataSink::SForecastModelPrerequisites prerequisites{0, 0, 0, true, false};

TModelDetailsViewPtr view = m_Model->details();
TModelDetailsViewUPtr view = m_Model->details();

// The view can be empty, e.g. for the counting model.
if (view.get() == nullptr) {
Expand Down Expand Up @@ -508,7 +508,7 @@ CAnomalyDetector::getForecastModels(bool persistOnDisk,
return series;
}

TModelDetailsViewPtr view = m_Model.get()->details();
TModelDetailsViewUPtr view = m_Model.get()->details();

// The view can be empty, e.g. for the counting model.
if (view.get() == nullptr) {
Expand Down
4 changes: 2 additions & 2 deletions lib/model/CCountingModel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,8 @@ std::size_t CCountingModel::staticSize() const {
return sizeof(*this);
}

CCountingModel::CModelDetailsViewPtr CCountingModel::details() const {
return CModelDetailsViewPtr();
CCountingModel::TModelDetailsViewUPtr CCountingModel::details() const {
return TModelDetailsViewUPtr();
}

core_t::TTime CCountingModel::currentBucketStartTime() const {
Expand Down
4 changes: 2 additions & 2 deletions lib/model/CEventRateModel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -502,8 +502,8 @@ std::size_t CEventRateModel::computeMemoryUsage() const {
return mem;
}

CEventRateModel::CModelDetailsViewPtr CEventRateModel::details() const {
return CModelDetailsViewPtr(new CEventRateModelDetailsView(*this));
CEventRateModel::TModelDetailsViewUPtr CEventRateModel::details() const {
return TModelDetailsViewUPtr(new CEventRateModelDetailsView(*this));
}

const CEventRateModel::TFeatureData*
Expand Down
4 changes: 2 additions & 2 deletions lib/model/CEventRatePopulationModel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -852,8 +852,8 @@ std::size_t CEventRatePopulationModel::staticSize() const {
return sizeof(*this);
}

CEventRatePopulationModel::CModelDetailsViewPtr CEventRatePopulationModel::details() const {
return CModelDetailsViewPtr(new CEventRatePopulationModelDetailsView(*this));
CEventRatePopulationModel::TModelDetailsViewUPtr CEventRatePopulationModel::details() const {
return TModelDetailsViewUPtr(new CEventRatePopulationModelDetailsView(*this));
}

const CEventRatePopulationModel::TSizeSizePrFeatureDataPrVec&
Expand Down
4 changes: 2 additions & 2 deletions lib/model/CMetricModel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -466,8 +466,8 @@ std::size_t CMetricModel::staticSize() const {
return sizeof(*this);
}

CMetricModel::CModelDetailsViewPtr CMetricModel::details() const {
return CModelDetailsViewPtr(new CMetricModelDetailsView(*this));
CMetricModel::TModelDetailsViewUPtr CMetricModel::details() const {
return TModelDetailsViewUPtr(new CMetricModelDetailsView(*this));
}

const CMetricModel::TFeatureData*
Expand Down
4 changes: 2 additions & 2 deletions lib/model/CMetricPopulationModel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -761,8 +761,8 @@ std::size_t CMetricPopulationModel::staticSize() const {
return sizeof(*this);
}

CMetricPopulationModel::CModelDetailsViewPtr CMetricPopulationModel::details() const {
return CModelDetailsViewPtr(new CMetricPopulationModelDetailsView(*this));
CMetricPopulationModel::TModelDetailsViewUPtr CMetricPopulationModel::details() const {
return TModelDetailsViewUPtr(new CMetricPopulationModelDetailsView(*this));
}

const TSizeSizePrFeatureDataPrVec&
Expand Down
4 changes: 2 additions & 2 deletions lib/model/unittest/CEventRateModelTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2895,9 +2895,9 @@ void CEventRateModelTest::testIgnoreSamplingGivenDetectionRules() {
CPPUNIT_ASSERT(modelWithSkip->checksum() != modelNoSkip->checksum());

// but the underlying models should be the same
CAnomalyDetectorModel::CModelDetailsViewPtr modelWithSkipView =
CAnomalyDetectorModel::TModelDetailsViewUPtr modelWithSkipView =
modelWithSkip->details();
CAnomalyDetectorModel::CModelDetailsViewPtr modelNoSkipView = modelNoSkip->details();
CAnomalyDetectorModel::TModelDetailsViewUPtr modelNoSkipView = modelNoSkip->details();

uint64_t withSkipChecksum =
static_cast<const maths::CUnivariateTimeSeriesModel*>(
Expand Down
4 changes: 2 additions & 2 deletions lib/model/unittest/CMetricModelTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2478,9 +2478,9 @@ void CMetricModelTest::testIgnoreSamplingGivenDetectionRules() {
CPPUNIT_ASSERT(modelWithSkip->checksum() != modelNoSkip->checksum());

// but the underlying models should be the same
CAnomalyDetectorModel::CModelDetailsViewPtr modelWithSkipView =
CAnomalyDetectorModel::TModelDetailsViewUPtr modelWithSkipView =
modelWithSkip->details();
CAnomalyDetectorModel::CModelDetailsViewPtr modelNoSkipView = modelNoSkip->details();
CAnomalyDetectorModel::TModelDetailsViewUPtr modelNoSkipView = modelNoSkip->details();

// TODO this test fails due a different checksums for the decay rate and prior
// uint64_t withSkipChecksum = modelWithSkipView->model(model_t::E_IndividualMeanByPerson, 0)->checksum();
Expand Down
4 changes: 2 additions & 2 deletions lib/model/unittest/CMetricPopulationModelTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1499,9 +1499,9 @@ void CMetricPopulationModelTest::testIgnoreSamplingGivenDetectionRules() {
// Checksums will be different because a 3rd model is created for attribute c3
CPPUNIT_ASSERT(modelWithSkip->checksum() != modelNoSkip->checksum());

CAnomalyDetectorModel::CModelDetailsViewPtr modelWithSkipView =
CAnomalyDetectorModel::TModelDetailsViewUPtr modelWithSkipView =
modelWithSkip->details();
CAnomalyDetectorModel::CModelDetailsViewPtr modelNoSkipView = modelNoSkip->details();
CAnomalyDetectorModel::TModelDetailsViewUPtr modelNoSkipView = modelNoSkip->details();

// but the underlying models for people p1 and p2 are the same
uint64_t withSkipChecksum = modelWithSkipView
Expand Down
4 changes: 2 additions & 2 deletions lib/model/unittest/Mocks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ std::size_t CMockModel::staticSize() const {
return 0;
}

CMockModel::CModelDetailsViewPtr CMockModel::details() const {
CModelDetailsViewPtr result{new CMockModelDetailsView(*this)};
CMockModel::TModelDetailsViewUPtr CMockModel::details() const {
TModelDetailsViewUPtr result{new CMockModelDetailsView(*this)};
return result;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/model/unittest/Mocks.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class CMockModel : public CAnomalyDetectorModel {

std::size_t staticSize() const override;

CModelDetailsViewPtr details() const override;
TModelDetailsViewUPtr details() const override;

double attributeFrequency(std::size_t cid) const override;

Expand Down