Skip to content
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

Fix Coverity hits for covariance, correlation and cosine distances #3017

Closed
Show file tree
Hide file tree
Changes from 2 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
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
20 changes: 15 additions & 5 deletions cpp/daal/include/algorithms/covariance/covariance_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,9 @@ 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) {}
virtual size_t getNumberOfFeatures() const = 0;
InputIface(const InputIface & other) = default;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sort of thing (adding definitions in headers that get compiled for different instruction sets) was causing 'illegal intruction' errors in the CI:
#3012

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, I only did this in places where constructor was already defined in header

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this method (L130) wasn't there before:

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, but copy-constructor was already defined in header, so I think defining copy-assignment operator here wouldn't change anything

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps @Vika-F could provide some perspective here.

InputIface & operator=(const InputIface & other) = default;
virtual size_t getNumberOfFeatures() const = 0;
virtual ~InputIface() {}
};

Expand All @@ -139,7 +140,8 @@ class DAAL_EXPORT Input : public InputIface
{
public:
Input();
Input(const Input & other) : InputIface(other) {}
Input(const Input & other) = default;
Input & operator=(const Input & other) = default;

virtual ~Input() {}

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;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As for this class I can't find a respective cpp with implementation, so I'm not sure if we can move the implementation of this functions from here. I don't understand the purpose of DistributedInput maybe it should removed in the future


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

virtual ~DistributedInput() {}

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
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
Loading