Skip to content

Commit

Permalink
Fix Coverity hits for covariance, correlation and cosine distances (#…
Browse files Browse the repository at this point in the history
…3022)

* Add fixes for coverity hits

* Fix

* Move implementations to cpp files
  • Loading branch information
avolkov-intel authored Dec 20, 2024
1 parent 1df0847 commit 72e80b8
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 9 deletions.
14 changes: 14 additions & 0 deletions cpp/daal/include/algorithms/covariance/covariance_batch.h
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,20 @@ class DAAL_EXPORT BatchImpl : public daal::algorithms::Analysis<batch>
_hpar = other.daal::algorithms::Analysis<batch>::_hpar;
}

/**
* Copy-assignment operator for an algorithm for correlation or variance-covariance matrix computation
* \param[in] other An algorithm to be used as the source to initialize the input objects
* and parameters of the algorithm
*/
BatchImpl & operator=(const BatchImpl & other)
{
input = other.input;
parameter = other.parameter;
initialize();
_hpar = other.daal::algorithms::Analysis<batch>::_hpar;
return *this;
}

/**
* Returns the structure that contains correlation or variance-covariance matrix
* \return Structure that contains the computed matrix
Expand Down
7 changes: 7 additions & 0 deletions cpp/daal/include/algorithms/covariance/covariance_online.h
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,13 @@ class DAAL_EXPORT OnlineImpl : public daal::algorithms::Analysis<online>
* and parameters of the algorithm
*/
OnlineImpl(const OnlineImpl & other) : input(other.input), parameter(other.parameter) { initialize(); }
OnlineImpl & operator=(const OnlineImpl & other)
{
input = other.input;
parameter = other.parameter;
initialize();
return *this;
}

virtual ~OnlineImpl() {}

Expand Down
26 changes: 18 additions & 8 deletions cpp/daal/include/algorithms/covariance/covariance_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,11 @@ namespace interface1
class DAAL_EXPORT InputIface : public daal::algorithms::Input
{
public:
InputIface(size_t nElements) : daal::algorithms::Input(nElements) {}
InputIface(const InputIface & other) : daal::algorithms::Input(other) {}
InputIface(size_t nElements);
InputIface(const InputIface & other);
InputIface & operator=(const InputIface & other);
virtual size_t getNumberOfFeatures() const = 0;
virtual ~InputIface() {}
virtual ~InputIface();
};

/**
Expand All @@ -139,9 +140,10 @@ class DAAL_EXPORT Input : public InputIface
{
public:
Input();
Input(const Input & other) : InputIface(other) {}
Input(const Input & other);
Input & operator=(const Input & other);

virtual ~Input() {}
virtual ~Input();

/**
* Returns number of columns in the input data set
Expand Down Expand Up @@ -279,6 +281,12 @@ struct DAAL_EXPORT OnlineParameter : public Parameter
*/
OnlineParameter(const OnlineParameter & other);

/**
* Copy-assignment operator for parameters of the Covariance Online algorithm
* \param[in] other Parameters of the Covariance Online algorithm
*/
OnlineParameter & operator=(const OnlineParameter & other);

/**
* Check the correctness of the %OnlineParameter object
*/
Expand Down Expand Up @@ -380,7 +388,8 @@ class DAAL_EXPORT DistributedInput<step1Local> : public Input
{
public:
DistributedInput() : Input() {}
DistributedInput(const DistributedInput & other) : Input(other) {}
DistributedInput(const DistributedInput & other) = default;
DistributedInput & operator=(const DistributedInput & other) = default;

virtual ~DistributedInput() {}
};
Expand All @@ -395,9 +404,10 @@ class DAAL_EXPORT DistributedInput<step2Master> : public InputIface
{
public:
DistributedInput();
DistributedInput(const DistributedInput & other) : InputIface(other) {}
DistributedInput(const DistributedInput & other);
DistributedInput & operator=(const DistributedInput & other);

virtual ~DistributedInput() {}
virtual ~DistributedInput();

/**
* Returns number of columns in the input data set
Expand Down
4 changes: 4 additions & 0 deletions cpp/daal/include/algorithms/distance/correlation_distance.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ class BatchContainer : public daal::algorithms::AnalysisContainerIface<batch>
BatchContainer(daal::services::Environment::env * daalEnv);
/** Default destructor */
~BatchContainer();
/** Delete copy-constructor and copy-assignment constructor to follow the rule of three */
BatchContainer(const BatchContainer &) = delete;
BatchContainer & operator=(const BatchContainer &) = delete;

/**
* Computes the result of the correlation distance algorithm in the batch processing mode
*/
Expand Down
4 changes: 4 additions & 0 deletions cpp/daal/include/algorithms/distance/cosine_distance.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ class BatchContainer : public daal::algorithms::AnalysisContainerIface<batch>
BatchContainer(daal::services::Environment::env * daalEnv);
/** Default constructor */
~BatchContainer();
/** Delete copy-constructor and copy-assignment constructor to follow the rule of three */
BatchContainer(const BatchContainer &) = delete;
BatchContainer & operator=(const BatchContainer &) = delete;

/**
* Computes the result of the cosine distance algorithm in the batch processing mode
*/
Expand Down
9 changes: 9 additions & 0 deletions cpp/daal/src/algorithms/covariance/covariance_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,16 @@ namespace covariance
{
namespace interface1
{

InputIface::InputIface(size_t nElements) : daal::algorithms::Input(nElements) {}
InputIface::InputIface(const InputIface & other) = default;
InputIface & InputIface::operator=(const InputIface & other) = default;
InputIface::~InputIface() = default;

Input::Input() : InputIface(lastInputId + 1) {}
Input::Input(const Input & other) = default;
Input & Input::operator=(const Input & other) = default;
Input::~Input() {}

/**
* Returns number of columns in the input data set
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,13 @@ OnlineParameter::OnlineParameter() : Parameter() {}
* Constructs parameters of the Covariance Online algorithm by copying another parameters of the Covariance Online algorithm
* \param[in] other Parameters of the Covariance Online algorithm
*/
OnlineParameter::OnlineParameter(const OnlineParameter & other) : Parameter(other) {}
OnlineParameter::OnlineParameter(const OnlineParameter & other) = default;

/**
* Copy-assignment operator for parameters of the Covariance Online algorithm
* \param[in] other Parameters of the Covariance Online algorithm
*/
OnlineParameter & OnlineParameter::operator=(const OnlineParameter & other) = default;

/**
* Check the correctness of the %OnlineParameter object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ DistributedInput<step2Master>::DistributedInput() : InputIface(lastMasterInputId
Argument::set(partialResults, DataCollectionPtr(new DataCollection()));
}

DistributedInput<step2Master>::DistributedInput(const DistributedInput & other) = default;
DistributedInput<step2Master> & DistributedInput<step2Master>::operator=(const DistributedInput & other) = default;
DistributedInput<step2Master>::~DistributedInput() = default;

size_t DistributedInput<step2Master>::getNumberOfFeatures() const
{
DataCollectionPtr collectionOfPartialResults = staticPointerCast<DataCollection, SerializationIface>(Argument::get(partialResults));
Expand Down

0 comments on commit 72e80b8

Please sign in to comment.