From 1ffc68e6787e11765b7c35d21c8e1f1e48bf8039 Mon Sep 17 00:00:00 2001 From: Anatoly Volkov Date: Tue, 10 Dec 2024 15:57:10 -0800 Subject: [PATCH 1/3] Add fixes for coverity hits --- .../algorithms/covariance/covariance_batch.h | 16 ++++++++++++++- .../algorithms/covariance/covariance_online.h | 7 +++++++ .../algorithms/covariance/covariance_types.h | 20 ++++++++++++++----- .../distance/correlation_distance.h | 4 ++++ .../algorithms/distance/cosine_distance.h | 4 ++++ .../covariance_online_parameter.cpp | 8 +++++++- 6 files changed, 52 insertions(+), 7 deletions(-) diff --git a/cpp/daal/include/algorithms/covariance/covariance_batch.h b/cpp/daal/include/algorithms/covariance/covariance_batch.h index fa39ce99890..c0ea506f761 100644 --- a/cpp/daal/include/algorithms/covariance/covariance_batch.h +++ b/cpp/daal/include/algorithms/covariance/covariance_batch.h @@ -271,11 +271,25 @@ class DAAL_EXPORT BatchImpl : public daal::algorithms::Analysis _hpar = other.daal::algorithms::Analysis::_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::_hpar; + return *this; + } + /** * Returns the structure that contains correlation or variance-covariance matrix * \return Structure that contains the computed matrix */ - ResultPtr getResult() { return _result; } + ResultPtr getResulst() { return _result; } /** * Registers user-allocated memory to store results of computation of the correlation or variance-covariance matrix diff --git a/cpp/daal/include/algorithms/covariance/covariance_online.h b/cpp/daal/include/algorithms/covariance/covariance_online.h index da951247ed9..0936c8b8f26 100644 --- a/cpp/daal/include/algorithms/covariance/covariance_online.h +++ b/cpp/daal/include/algorithms/covariance/covariance_online.h @@ -304,6 +304,13 @@ class DAAL_EXPORT OnlineImpl : public daal::algorithms::Analysis * 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() {} diff --git a/cpp/daal/include/algorithms/covariance/covariance_types.h b/cpp/daal/include/algorithms/covariance/covariance_types.h index 77fda3dda5e..a8b7414adc9 100644 --- a/cpp/daal/include/algorithms/covariance/covariance_types.h +++ b/cpp/daal/include/algorithms/covariance/covariance_types.h @@ -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; + InputIface & operator=(const InputIface & other) = default; + virtual size_t getNumberOfFeatures() const = 0; virtual ~InputIface() {} }; @@ -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() {} @@ -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 */ @@ -380,7 +388,8 @@ class DAAL_EXPORT DistributedInput : public Input { public: DistributedInput() : Input() {} - DistributedInput(const DistributedInput & other) : Input(other) {} + DistributedInput(const DistributedInput & other) = default; + DistributedInput & operator=(const DistributedInput & other) = default; virtual ~DistributedInput() {} }; @@ -395,7 +404,8 @@ class DAAL_EXPORT DistributedInput : public InputIface { public: DistributedInput(); - DistributedInput(const DistributedInput & other) : InputIface(other) {} + DistributedInput(const DistributedInput & other) = default; + DistributedInput & operator=(const DistributedInput & other) = default; virtual ~DistributedInput() {} diff --git a/cpp/daal/include/algorithms/distance/correlation_distance.h b/cpp/daal/include/algorithms/distance/correlation_distance.h index 8bea431b045..9ea7a3c8ba4 100644 --- a/cpp/daal/include/algorithms/distance/correlation_distance.h +++ b/cpp/daal/include/algorithms/distance/correlation_distance.h @@ -63,6 +63,10 @@ class BatchContainer : public daal::algorithms::AnalysisContainerIface 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 */ diff --git a/cpp/daal/include/algorithms/distance/cosine_distance.h b/cpp/daal/include/algorithms/distance/cosine_distance.h index cdbccfdfd67..165e9f3ed50 100644 --- a/cpp/daal/include/algorithms/distance/cosine_distance.h +++ b/cpp/daal/include/algorithms/distance/cosine_distance.h @@ -63,6 +63,10 @@ class BatchContainer : public daal::algorithms::AnalysisContainerIface 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 */ diff --git a/cpp/daal/src/algorithms/covariance/covariance_online_parameter.cpp b/cpp/daal/src/algorithms/covariance/covariance_online_parameter.cpp index c4235e99ce0..0d702d54270 100644 --- a/cpp/daal/src/algorithms/covariance/covariance_online_parameter.cpp +++ b/cpp/daal/src/algorithms/covariance/covariance_online_parameter.cpp @@ -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 From 21e127833c220b6b0cef4261848a233e2bf4baa4 Mon Sep 17 00:00:00 2001 From: Anatoly Volkov Date: Tue, 10 Dec 2024 17:49:09 -0800 Subject: [PATCH 2/3] Fix --- cpp/daal/include/algorithms/covariance/covariance_batch.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp/daal/include/algorithms/covariance/covariance_batch.h b/cpp/daal/include/algorithms/covariance/covariance_batch.h index c0ea506f761..abec1e12ae4 100644 --- a/cpp/daal/include/algorithms/covariance/covariance_batch.h +++ b/cpp/daal/include/algorithms/covariance/covariance_batch.h @@ -289,7 +289,7 @@ class DAAL_EXPORT BatchImpl : public daal::algorithms::Analysis * Returns the structure that contains correlation or variance-covariance matrix * \return Structure that contains the computed matrix */ - ResultPtr getResulst() { return _result; } + ResultPtr getResult() { return _result; } /** * Registers user-allocated memory to store results of computation of the correlation or variance-covariance matrix From dc124693a5cc58a6eee3d19f53f8788f9b4258ac Mon Sep 17 00:00:00 2001 From: Anatoly Volkov Date: Wed, 11 Dec 2024 06:03:24 -0800 Subject: [PATCH 3/3] Move implementations to cpp files --- .../algorithms/covariance/covariance_types.h | 22 +++++++++---------- .../covariance/covariance_input.cpp | 9 ++++++++ .../covariance_step2_distr_input.cpp | 4 ++++ 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/cpp/daal/include/algorithms/covariance/covariance_types.h b/cpp/daal/include/algorithms/covariance/covariance_types.h index a8b7414adc9..64dedfd0d04 100644 --- a/cpp/daal/include/algorithms/covariance/covariance_types.h +++ b/cpp/daal/include/algorithms/covariance/covariance_types.h @@ -125,11 +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) = default; - InputIface & operator=(const InputIface & other) = default; - virtual size_t getNumberOfFeatures() const = 0; - virtual ~InputIface() {} + InputIface(size_t nElements); + InputIface(const InputIface & other); + InputIface & operator=(const InputIface & other); + virtual size_t getNumberOfFeatures() const = 0; + virtual ~InputIface(); }; /** @@ -140,10 +140,10 @@ class DAAL_EXPORT Input : public InputIface { public: Input(); - Input(const Input & other) = default; - Input & operator=(const Input & other) = default; + Input(const Input & other); + Input & operator=(const Input & other); - virtual ~Input() {} + virtual ~Input(); /** * Returns number of columns in the input data set @@ -404,10 +404,10 @@ class DAAL_EXPORT DistributedInput : public InputIface { public: DistributedInput(); - DistributedInput(const DistributedInput & other) = default; - DistributedInput & operator=(const DistributedInput & other) = default; + DistributedInput(const DistributedInput & other); + DistributedInput & operator=(const DistributedInput & other); - virtual ~DistributedInput() {} + virtual ~DistributedInput(); /** * Returns number of columns in the input data set diff --git a/cpp/daal/src/algorithms/covariance/covariance_input.cpp b/cpp/daal/src/algorithms/covariance/covariance_input.cpp index adf31de9dd4..3d9a1547d30 100644 --- a/cpp/daal/src/algorithms/covariance/covariance_input.cpp +++ b/cpp/daal/src/algorithms/covariance/covariance_input.cpp @@ -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 diff --git a/cpp/daal/src/algorithms/covariance/covariance_step2_distr_input.cpp b/cpp/daal/src/algorithms/covariance/covariance_step2_distr_input.cpp index ce82c999778..9b3601a93a7 100644 --- a/cpp/daal/src/algorithms/covariance/covariance_step2_distr_input.cpp +++ b/cpp/daal/src/algorithms/covariance/covariance_step2_distr_input.cpp @@ -40,6 +40,10 @@ DistributedInput::DistributedInput() : InputIface(lastMasterInputId Argument::set(partialResults, DataCollectionPtr(new DataCollection())); } +DistributedInput::DistributedInput(const DistributedInput & other) = default; +DistributedInput & DistributedInput::operator=(const DistributedInput & other) = default; +DistributedInput::~DistributedInput() = default; + size_t DistributedInput::getNumberOfFeatures() const { DataCollectionPtr collectionOfPartialResults = staticPointerCast(Argument::get(partialResults));