Skip to content

Commit

Permalink
Fix coverity hits in classifier and Decision Forest
Browse files Browse the repository at this point in the history
  • Loading branch information
Vika-F committed Dec 3, 2024
1 parent 32d72e3 commit 6efef0e
Show file tree
Hide file tree
Showing 19 changed files with 93 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ namespace interface1
struct DAAL_EXPORT Parameter : public daal::algorithms::Parameter
{
Parameter(double beta = 1.0);
Parameter(const Parameter & other) = default;
Parameter & operator=(const Parameter & other) = default;
virtual ~Parameter() {}

double beta; /*!< Parameter of the F-score */
Expand All @@ -132,6 +134,7 @@ class DAAL_EXPORT Input : public daal::algorithms::Input
public:
Input();
Input(const Input & other) : daal::algorithms::Input(other) {}
Input & operator=(const Input & other) = default;

virtual ~Input() {}

Expand Down
4 changes: 4 additions & 0 deletions cpp/daal/include/algorithms/classifier/classifier_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ class DAAL_EXPORT Model : public daal::algorithms::Model
public:
DAAL_CAST_OPERATOR(Model)

Model() = default;
Model(const Model & other) = default;
Model & operator=(const Model & other) = default;

virtual ~Model() DAAL_C11_OVERRIDE {}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,7 @@ class DAAL_EXPORT InputIface : public daal::algorithms::Input
public:
InputIface(size_t nElements);
InputIface(const InputIface & other) : daal::algorithms::Input(other) {}
InputIface & operator=(const InputIface & other)
{
daal::algorithms::Input::operator=(other);
return *this;
}
InputIface & operator=(const InputIface & other) = default;
virtual ~InputIface() {}
/**
* Returns the number of rows in the input data set
Expand All @@ -117,8 +113,7 @@ class DAAL_EXPORT Input : public InputIface
public:
Input();
Input(const Input & other) : InputIface(other) {}
Input & operator=(const Input & other);

Input & operator=(const Input & other) = default;
virtual ~Input() {}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,7 @@ class DAAL_EXPORT InputIface : public daal::algorithms::Input
public:
InputIface(size_t nElements);
InputIface(const InputIface & other) : daal::algorithms::Input(other) {}
InputIface & operator=(const InputIface & other)
{
daal::algorithms::Input::operator=(other);
return *this;
}
InputIface & operator=(const InputIface & other) = default;
virtual ~InputIface() {}
virtual size_t getNumberOfFeatures() const = 0;
};
Expand All @@ -117,7 +113,7 @@ class DAAL_EXPORT Input : public InputIface
public:
Input(size_t nElements = lastInputId + 1);
Input(const Input & other) : InputIface(other) {}
Input & operator=(const Input & other);
Input & operator=(const Input & other) = default;

virtual ~Input() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ namespace interface1
struct DAAL_EXPORT Parameter : public daal::algorithms::Parameter
{
Parameter(size_t nClasses = 0, double beta = 1.0);
Parameter(const Parameter & other) = default;
Parameter & operator=(const Parameter & other) = default;
virtual ~Parameter() {}

size_t nClasses; /*!< Number of classes */
Expand All @@ -129,6 +131,7 @@ class DAAL_EXPORT Input : public daal::algorithms::Input
public:
Input();
Input(const Input & other) : daal::algorithms::Input(other) {}
Input & operator=(const Input & other) = default;

virtual ~Input() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class DAAL_EXPORT Input : public classifier::prediction::Input
public:
Input();
Input(const Input & other) : super(other) {}
Input & operator=(const Input & other) = default;
virtual ~Input() {}

using super::get;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ class DAAL_EXPORT Input : public algorithms::regression::prediction::Input
public:
Input();
Input(const Input & other);
Input & operator=(const Input & other) = default;

/**
* Returns an input object for making decision forest model-based prediction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ class DAAL_EXPORT Input : public algorithms::regression::training::Input
/** Copy constructor */
Input(const Input & other) : algorithms::regression::training::Input(other) {}

Input & operator=(const Input & other) = default;

virtual ~Input() {};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ struct DAAL_EXPORT Parameter : public daal::algorithms::classifier::Parameter

Parameter(size_t nClasses = 2) : super(nClasses), nIterations(0), resultsToCompute(predictionResult) {}
Parameter(const Parameter & o) : super(o), nIterations(o.nIterations), resultsToCompute(o.resultsToCompute) {}
Parameter & operator=(const Parameter & o) = default;
size_t nIterations; /*!< Number of iterations of the trained model to be used for prediction */
DAAL_UINT64 resultsToCompute; /*!< 64 bit integer flag that indicates the results to compute */
};
Expand Down Expand Up @@ -185,7 +186,7 @@ class DAAL_EXPORT Input : public classifier::prediction::Input
public:
Input() : super() {}
Input(const Input & other) : super(other) {}
Input & operator=(const Input & other);
Input & operator=(const Input & other) = default;
virtual ~Input() {}

using super::get;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ struct DAAL_EXPORT Parameter : public daal::algorithms::Parameter

Parameter() : super(), nIterations(0), resultsToCompute(predictionResult) {}
Parameter(const Parameter & o) : super(o), nIterations(o.nIterations), resultsToCompute(o.resultsToCompute) {}
Parameter & operator=(const Parameter & o) = default;
size_t nIterations; /*!< Number of iterations of the trained model to be uses for prediction*/
DAAL_UINT64 resultsToCompute; /*!< 64 bit integer flag that indicates the results to compute */
};
Expand All @@ -132,8 +133,8 @@ class DAAL_EXPORT Input : public algorithms::regression::prediction::Input
{
public:
Input();
Input(const Input & other);
Input & operator=(const Input & other);
Input(const Input & other) = default;
Input & operator=(const Input & other) = default;
virtual ~Input() {}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ class DAAL_EXPORT Model : public daal::algorithms::classifier::Model
*/
Model();

Model(const Model & other);
Model & operator=(const Model & other);

/**
* Constructs multi-class classifier model
* \param[in] nFeatures Number of features in the dataset
Expand Down
6 changes: 0 additions & 6 deletions cpp/daal/src/algorithms/classifier/classifier_predict.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@ InputIface::InputIface(size_t nElements) : daal::algorithms::Input(nElements) {}

Input::Input() : InputIface(lastModelInputId + 1) {}

Input & Input::operator=(const Input & other)
{
InputIface::operator=(other);
return *this;
}

/**
* Returns the number of rows in the input data set
* \return Number of rows in the input data set
Expand Down
6 changes: 0 additions & 6 deletions cpp/daal/src/algorithms/classifier/classifier_train.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,6 @@ __DAAL_REGISTER_SERIALIZATION_CLASS(Result, SERIALIZATION_CLASSIFIER_TRAINING_RE
InputIface::InputIface(size_t nElements) : daal::algorithms::Input(nElements) {}
Input::Input(size_t nElements) : InputIface(nElements) {}

Input & Input::operator=(const Input & other)
{
InputIface::operator=(other);
return *this;
}

size_t Input::getNumberOfFeatures() const
{
return get(classifier::training::data)->getNumberOfColumns();
Expand Down
33 changes: 33 additions & 0 deletions cpp/daal/src/algorithms/dtrees/dtrees_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,39 @@ Tree::~Tree() {}

ModelImpl::ModelImpl() : _nTree(0) {}

ModelImpl::ModelImpl(const ModelImpl & other)
{
const size_t nTree = other._nTree.get();
resize(nTree); // sets _nTree = 0
_nTree.set(nTree);
for (size_t i = 0; i < nTree; ++i)
{
(*_serializationData)[i] = (*other._serializationData)[i];
(*_impurityTables)[i] = (*other._impurityTables)[i];
(*_nNodeSampleTables)[i] = (*other._nNodeSampleTables)[i];
(*_probTbl)[i] = (*other._probTbl)[i];
}
}

ModelImpl & ModelImpl::operator=(const ModelImpl & other)
{
if (this != &other)
{
destroy();
const size_t nTree = other._nTree.get();
resize(nTree); // sets _nTree = 0
_nTree.set(nTree);
for (size_t i = 0; i < nTree; ++i)
{
(*_serializationData)[i] = (*other._serializationData)[i];
(*_impurityTables)[i] = (*other._impurityTables)[i];
(*_nNodeSampleTables)[i] = (*other._nNodeSampleTables)[i];
(*_probTbl)[i] = (*other._probTbl)[i];
}
}
return *this;
}

ModelImpl::~ModelImpl()
{
destroy();
Expand Down
5 changes: 3 additions & 2 deletions cpp/daal/src/algorithms/dtrees/dtrees_model_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -480,8 +480,9 @@ class DAAL_EXPORT ModelImpl
{
public:
ModelImpl();
ModelImpl(const ModelImpl &) = delete;
ModelImpl & operator=(const ModelImpl & other) = delete;

ModelImpl(const ModelImpl & other);
ModelImpl & operator=(const ModelImpl & other);

virtual ~ModelImpl();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,6 @@ namespace prediction
{
namespace interface1
{
Input & Input::operator=(const Input & other)
{
algorithms::classifier::prediction::Input::operator=(other);
return *this;
}

/**
* Returns an input object for making gradient boosted trees model-based prediction
* \param[in] id Identifier of the input object
Expand Down
4 changes: 4 additions & 0 deletions cpp/daal/src/algorithms/dtrees/gbt/gbt_model_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,10 @@ class ModelImpl : protected dtrees::internal::ModelImpl
using TreeType = gbt::internal::TreeImpRegression<>;
using super = dtrees::internal::ModelImpl;

ModelImpl() = default;
ModelImpl(const ModelImpl & other) = default;
ModelImpl & operator=(const ModelImpl & other) = default;

~ModelImpl() DAAL_C11_OVERRIDE;
size_t size() const;
bool reserve(const size_t nTrees);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,6 @@ __DAAL_REGISTER_SERIALIZATION_CLASS(Result, SERIALIZATION_DECISION_FOREST_REGRES
Input::Input() : algorithms::regression::prediction::Input(lastModelInputId + 1) {}
Input::Input(const Input & other) : algorithms::regression::prediction::Input(other) {}

Input & Input::operator=(const Input & other)
{
algorithms::regression::prediction::Input::operator=(other);
return *this;
}

/**
* Returns an input object for making gradient boosted trees model-based prediction
* \param[in] id Identifier of the input object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,33 @@ Model::Model(size_t nFeatures, const multi_class_classifier::interface2::Paramet
if (!_models) st.add(services::ErrorMemoryAllocationFailed);
}

Model::Model(const Model & other) :
_nFeatures(other._nFeatures),
_models(new data_management::DataCollection(other.getNumberOfTwoClassClassifierModels())),
_modelsArray(nullptr)
{
const size_t nModels = other.getNumberOfTwoClassClassifierModels();
for (size_t i = 0; i < nModels; ++i)
{
setTwoClassClassifierModel(i, other.getTwoClassClassifierModel(i));
}
}

Model & Model::operator=(const Model & other)
{
if (this != &other)
{
_nFeatures = other._nFeatures;
const size_t nModels = other.getNumberOfTwoClassClassifierModels();
_models = data_management::DataCollectionPtr(new data_management::DataCollection(nModels));
for (size_t i = 0; i < nModels; ++i)
{
setTwoClassClassifierModel(i, other.getTwoClassClassifierModel(i));
}
}
return *this;
}

Model::Model() : _nFeatures(0), _models(new data_management::DataCollection()), _modelsArray(nullptr) {}

ModelPtr Model::create(size_t nFeatures, const multi_class_classifier::interface2::ParameterBase * par, services::Status * stat)
Expand Down

0 comments on commit 6efef0e

Please sign in to comment.