From 9c52d407a66a29284f8276069987f1573281adff Mon Sep 17 00:00:00 2001 From: NAUD Maxence <maxence.naud@cea.fr> Date: Thu, 23 Nov 2023 13:53:19 +0000 Subject: [PATCH] [Rmv] inline destructor error, fix code quality in GraphView --- include/aidge/graphRegex/GraphParser.hpp | 4 +- .../aidge/graphRegex/matchFsm/MatchResult.hpp | 27 ++-- .../aidge/nodeTester/ConditionalParser.hpp | 1 - include/aidge/operator/Operator.hpp | 2 +- include/aidge/operator/OperatorTensor.hpp | 2 +- src/graph/GraphView.cpp | 22 +-- src/graphRegex/matchFsm/MatchResult.cpp | 149 ++++++++---------- src/operator/Operator.cpp | 2 +- src/operator/OperatorTensor.cpp | 2 + 9 files changed, 100 insertions(+), 111 deletions(-) diff --git a/include/aidge/graphRegex/GraphParser.hpp b/include/aidge/graphRegex/GraphParser.hpp index 29ee8c7b2..cfe25c227 100644 --- a/include/aidge/graphRegex/GraphParser.hpp +++ b/include/aidge/graphRegex/GraphParser.hpp @@ -21,8 +21,6 @@ class GraphParser{ */ GraphParser(const std::string gRegexExpressions); - virtual ~GraphParser() = default; - /** * @brief AST graph creation function * @return The AST tree @@ -31,7 +29,7 @@ class GraphParser{ /** - * @brief get the query that be use in the parsing + * @brief get the query that be use in the parsing * @return query */ const std::string getQuery(); diff --git a/include/aidge/graphRegex/matchFsm/MatchResult.hpp b/include/aidge/graphRegex/matchFsm/MatchResult.hpp index 29b9abb61..4f7f9bf1d 100644 --- a/include/aidge/graphRegex/matchFsm/MatchResult.hpp +++ b/include/aidge/graphRegex/matchFsm/MatchResult.hpp @@ -1,10 +1,12 @@ #ifndef AIDGE_CORE_MATCH_RESULT_H_ #define AIDGE_CORE_MATCH_RESULT_H_ +#include <cstddef> +#include <map> #include <memory> +#include <string> +#include <set> #include <vector> -#include <map> - #include "aidge/graphRegex/matchFsm/FsmRunTimeContext.hpp" #include "aidge/graph/Node.hpp" @@ -12,23 +14,25 @@ namespace Aidge{ /** - * @brief contained the result of one match and the associate key , the query and the start node + * @brief contained the result of one match and the associate key , the query and the start node */ class MatchSolution{ private: - std::map<std::string,std::set<NodePtr>> mSolution; + std::map<std::string, std::set<NodePtr>> mSolution; const std::string mQueryFrom; const std::vector<NodePtr> mStartNode; public: MatchSolution(std::vector<std::shared_ptr<FsmRunTimeContext>>& precedence,const std::string query,const std::vector<NodePtr> startNode); - const std::set<NodePtr> & at(const std::string key); - const std::set<NodePtr> getAll(); + inline const std::set<NodePtr>& at(const std::string key) { + return mSolution[key]; + } + const std::set<NodePtr> getAll(); bool areCompatible(std::shared_ptr<MatchSolution> solution); - const std::string& getQuery(){ return mQueryFrom ;} - const std::vector<NodePtr>& getStartNode(){ return mStartNode ;} + inline const std::string& getQuery() const noexcept { return mQueryFrom; } + inline const std::vector<NodePtr>& getStartNode() const noexcept { return mStartNode; } }; @@ -59,15 +63,15 @@ public: MatchResult(std::vector<std::shared_ptr<FsmRunTimeContext>> allValid, std::size_t nbSubStm, const std::string& query,const std::vector<NodePtr>& startNodes); - virtual ~MatchResult() = default; - /** * @brief get the set of the node match for une expression * @return the set of node of the graph that corresponding to an expression */ std::shared_ptr<MatchSolution> getBiggerSolution(void); - std::vector<std::shared_ptr<MatchSolution>> getSolutions(void); + inline std::vector<std::shared_ptr<MatchSolution>> getSolutions(void) const noexcept { + return mSolve; + } private: @@ -75,7 +79,6 @@ private: * @brief recurrent function use to init mSolve in the constructor * **/ - void _generateCombination( std::size_t idxSubStm, std::vector<std::shared_ptr<FsmRunTimeContext>>& precedence,const std::string& query,const std::vector<NodePtr>& startNodes); }; diff --git a/include/aidge/nodeTester/ConditionalParser.hpp b/include/aidge/nodeTester/ConditionalParser.hpp index a99f53741..c21eca040 100644 --- a/include/aidge/nodeTester/ConditionalParser.hpp +++ b/include/aidge/nodeTester/ConditionalParser.hpp @@ -38,7 +38,6 @@ class ConditionalParser{ */ ConditionalParser(const std::string ConditionalExpressions); - virtual ~ConditionalParser() = default; /** * @brief AST graph creation function * @return The AST tree diff --git a/include/aidge/operator/Operator.hpp b/include/aidge/operator/Operator.hpp index 5ff1152e4..b0f8435bd 100644 --- a/include/aidge/operator/Operator.hpp +++ b/include/aidge/operator/Operator.hpp @@ -68,7 +68,7 @@ public: // Hooks are not copied. } - virtual ~Operator(); + virtual ~Operator() noexcept; public: virtual std::shared_ptr<Operator> clone() const = 0; diff --git a/include/aidge/operator/OperatorTensor.hpp b/include/aidge/operator/OperatorTensor.hpp index 5f8317966..a55d7ac28 100644 --- a/include/aidge/operator/OperatorTensor.hpp +++ b/include/aidge/operator/OperatorTensor.hpp @@ -61,7 +61,7 @@ public: } } - virtual ~OperatorTensor() = default; + ~OperatorTensor(); public: /////////////////////////////////////////////////// diff --git a/src/graph/GraphView.cpp b/src/graph/GraphView.cpp index 2306ec8ab..96466cd1a 100644 --- a/src/graph/GraphView.cpp +++ b/src/graph/GraphView.cpp @@ -13,6 +13,7 @@ #include <cassert> #include <iterator> #include <utility> +#include <numeric> #include "aidge/utils/Types.h" #include "aidge/graph/GraphView.hpp" @@ -108,20 +109,19 @@ void Aidge::GraphView::save(std::string path, bool verbose) const { /////////////////////////////////////////////////////// Aidge::IOIndex_t Aidge::GraphView::getNbDataInputs() const { - IOIndex_t nbDataInput = 0; - // assert(outputNodes().size() == static_cast<std::size_t>(1)); - for (const std::shared_ptr<Node> &inNode : inputNodes()) { - nbDataInput += inNode->nbData(); - } - return nbDataInput; + return std::accumulate(mInputNodes.cbegin(), mInputNodes.cend(), 0, + [](IOIndex_t sumData, const std::shared_ptr<Node> inNode) { + return sumData + inNode->nbData(); + } + ); } Aidge::IOIndex_t Aidge::GraphView::getNbFreeDataInputs() const { - IOIndex_t nbIn = 0; - for (const std::shared_ptr<Node>& inputNode : mInputNodes) { - nbIn += inputNode->getNbFreeDataInputs(); - } - return nbIn; + return std::accumulate(mInputNodes.cbegin(), mInputNodes.cend(), 0, + [](IOIndex_t sumData, const std::shared_ptr<Node> inNode) { + return sumData + inNode->getNbFreeDataInputs(); + } + ); } diff --git a/src/graphRegex/matchFsm/MatchResult.cpp b/src/graphRegex/matchFsm/MatchResult.cpp index c871b3d0e..08be00dea 100644 --- a/src/graphRegex/matchFsm/MatchResult.cpp +++ b/src/graphRegex/matchFsm/MatchResult.cpp @@ -1,90 +1,87 @@ +#include <algorithm> // set_intersection, std::sort +#include <memory> +#include <set> +#include <string> +#include <vector> + #include "aidge/graphRegex/matchFsm/MatchResult.hpp" -using namespace Aidge; - - MatchSolution::MatchSolution(std::vector<std::shared_ptr<FsmRunTimeContext>>& precedence,const std::string query,const std::vector<NodePtr> startNode):mQueryFrom(query),mStartNode(startNode){ - //reformat the solution - for (const auto& context : precedence) { - for (const auto& pair : context->getValid()) { - - if(mSolution.find(pair.first->getKey()) == mSolution.end()){ - mSolution[pair.first->getKey()] = pair.second; - }else{ - mSolution[pair.first->getKey()].insert(pair.second.begin(), pair.second.end()); - } +Aidge::MatchSolution::MatchSolution(std::vector<std::shared_ptr<FsmRunTimeContext>>& precedence,const std::string query,const std::vector<NodePtr> startNode):mQueryFrom(query),mStartNode(startNode){ + //reformat the solution + for (const auto& context : precedence) { + for (const auto& pair : context->getValid()) { + + if(mSolution.find(pair.first->getKey()) == mSolution.end()){ + mSolution[pair.first->getKey()] = pair.second; + }else{ + mSolution[pair.first->getKey()].insert(pair.second.begin(), pair.second.end()); } } - } - - - const std::set<NodePtr> & MatchSolution::at(const std::string key){ - - return mSolution[key]; + } +} - } +const std::set<Aidge::NodePtr> Aidge::MatchSolution::getAll(){ - const std::set<NodePtr> MatchSolution::getAll(){ + // Create a unique set to store all the elements + std::set<NodePtr> uniqueSet; - // Create a unique set to store all the elements - std::set<NodePtr> uniqueSet; + // Iterate through the map and insert elements from each set into the unique set + for (const auto& pair : mSolution) { + const std::set<NodePtr>& nodeSet = pair.second; - // Iterate through the map and insert elements from each set into the unique set - for (const auto& pair : mSolution) { - const std::set<NodePtr>& nodeSet = pair.second; - - // Insert elements from the current set into the unique set - uniqueSet.insert(nodeSet.begin(), nodeSet.end()); - } - - return uniqueSet; + // Insert elements from the current set into the unique set + uniqueSet.insert(nodeSet.begin(), nodeSet.end()); + } - } + return uniqueSet; +} - bool MatchSolution::areCompatible(std::shared_ptr<MatchSolution> solution){ - std::set<NodePtr> set1 = solution->getAll(); - std::set<NodePtr> set2 = getAll(); - std::set<NodePtr> intersection ; - std::set_intersection(set1.begin(), set1.end(), set2.begin(), set2.end(), std::inserter(intersection, intersection.begin())); - if (intersection.empty()) { - return true; - } - return false; - } +bool Aidge::MatchSolution::areCompatible(std::shared_ptr<Aidge::MatchSolution> solution){ + std::set<NodePtr> set1 = solution->getAll(); + std::set<NodePtr> set2 = getAll(); + std::set<NodePtr> intersection ; + std::set_intersection(set1.begin(), set1.end(), set2.begin(), set2.end(), std::inserter(intersection, intersection.begin())); + return intersection.empty(); +} - //////////////////////////////// // //////////////////////////////// -MatchResult::MatchResult(std::vector<std::shared_ptr<FsmRunTimeContext>> allValid, std::size_t nbSubStm, -const std::string& query,const std::vector<NodePtr>& startNodes):mIdToRunTime(nbSubStm),mNbSubStm(nbSubStm){ - mAllValid = allValid; - - //mIdToRunTimm - for (const auto& contextPtr : allValid) { - mIdToRunTime[contextPtr->getSubStmId()].push_back(contextPtr); - } +Aidge::MatchResult::MatchResult(std::vector<std::shared_ptr<Aidge::FsmRunTimeContext>> allValid, + std::size_t nbSubStm, + const std::string& query, + const std::vector<Aidge::NodePtr>& startNodes) + : mIdToRunTime(nbSubStm), + mNbSubStm(nbSubStm) +{ + mAllValid = allValid; + + //mIdToRunTimm + for (const auto& contextPtr : allValid) { + mIdToRunTime[contextPtr->getSubStmId()].push_back(contextPtr); + } - std::vector<std::shared_ptr<FsmRunTimeContext>> precedence; - //make all solution possible - _generateCombination(0,precedence,query,startNodes); - //sort by solution number of elements - std::sort(mSolve.begin(), mSolve.end(), [](std::shared_ptr<MatchSolution>& set1, std::shared_ptr<MatchSolution>& set2) { + std::vector<std::shared_ptr<FsmRunTimeContext>> precedence; + //make all solution possible + _generateCombination(0,precedence,query,startNodes); + //sort by solution number of elements + std::sort(mSolve.begin(), mSolve.end(), [](std::shared_ptr<MatchSolution>& set1, std::shared_ptr<MatchSolution>& set2) { return set1->getAll().size() < set2->getAll().size(); - }); - - + }); } -void MatchResult::_generateCombination( std::size_t idxSubStm, std::vector<std::shared_ptr<FsmRunTimeContext>>& precedence, -const std::string& query,const std::vector<NodePtr>& startNodes){ - +void Aidge::MatchResult::_generateCombination( std::size_t idxSubStm, + std::vector<std::shared_ptr<Aidge::FsmRunTimeContext>>& precedence, + const std::string& query, + const std::vector<Aidge::NodePtr>& startNodes) +{ //it's end , we are below the number of stm if (idxSubStm == mNbSubStm) { - //precedence contain a list of FSM compatible, we just need to - //check if all the nodes have been validated by at least one context - + //precedence contain a list of FSM compatible, we just need to + //check if all the nodes have been validated by at least one context + //1) make the set of all node for the compute graph that are valid in all the FsmRunTimeContext std::set<NodePtr> validNode; std::set<NodePtr> rejectNode; @@ -94,10 +91,10 @@ const std::string& query,const std::vector<NodePtr>& startNodes){ std::set<NodePtr> tmpR = contextPtr->getRejectedNodes(); rejectNode.insert(tmpR.begin(),tmpR.end()); } - // 2) all RejectedNodes need to be valid by an others stm + // 2) all RejectedNodes need to be valid by an others stm // if it's not the case the match is not valid if(std::includes(validNode.begin(), validNode.end(), rejectNode.begin(), rejectNode.end())){ - //we can save the solution + //we can save the solution mSolve.push_back(std::make_shared<MatchSolution>(precedence,query,startNodes)); } precedence.pop_back(); @@ -105,12 +102,12 @@ const std::string& query,const std::vector<NodePtr>& startNodes){ } - for (const auto& contextPtrOneFsm : mIdToRunTime[idxSubStm]) + for (const auto& contextPtrOneFsm : mIdToRunTime[idxSubStm]) { if(idxSubStm == 0){ precedence.push_back(contextPtrOneFsm); _generateCombination(idxSubStm+1,precedence,query,startNodes); - + }else{ //test if the new context is compatible with all the context in the precedence // @@ -137,16 +134,6 @@ const std::string& query,const std::vector<NodePtr>& startNodes){ } -std::shared_ptr<MatchSolution> MatchResult::getBiggerSolution(void){ - - if(mSolve.empty()){ - return nullptr; - }else{ - return mSolve[0]; - } - -} - -std::vector<std::shared_ptr<MatchSolution>> MatchResult::getSolutions(void){ - return mSolve; +std::shared_ptr<Aidge::MatchSolution> Aidge::MatchResult::getBiggerSolution(void){ + return mSolve.empty() ? nullptr : mSolve[0]; } \ No newline at end of file diff --git a/src/operator/Operator.cpp b/src/operator/Operator.cpp index 05a1d8ab9..eb94db87d 100644 --- a/src/operator/Operator.cpp +++ b/src/operator/Operator.cpp @@ -25,7 +25,7 @@ // // ctor // } -Aidge::Operator::~Operator() = default; +Aidge::Operator::~Operator() noexcept = default; /////////////////////////////////////////////////////// // IMPLEMENTATION diff --git a/src/operator/OperatorTensor.cpp b/src/operator/OperatorTensor.cpp index 6fcb70f0f..1d16e9064 100644 --- a/src/operator/OperatorTensor.cpp +++ b/src/operator/OperatorTensor.cpp @@ -40,6 +40,8 @@ void Aidge::OperatorTensor::setInput(const Aidge::IOIndex_t inputIdx, const std: } } +Aidge::OperatorTensor::~OperatorTensor() = default; + void Aidge::OperatorTensor::setInput(const Aidge::IOIndex_t inputIdx, std::shared_ptr<Aidge::Data>&& data) { if (strcmp(data->type(), "Tensor") != 0) { AIDGE_THROW_OR_ABORT(std::runtime_error, "%s Operator only accepts Tensors as inputs", type().c_str()); -- GitLab