Skip to content
Snippets Groups Projects
Commit 9c52d407 authored by Maxence Naud's avatar Maxence Naud
Browse files

[Rmv] inline destructor error, fix code quality in GraphView

parent b05c2231
No related branches found
No related tags found
No related merge requests found
...@@ -21,8 +21,6 @@ class GraphParser{ ...@@ -21,8 +21,6 @@ class GraphParser{
*/ */
GraphParser(const std::string gRegexExpressions); GraphParser(const std::string gRegexExpressions);
virtual ~GraphParser() = default;
/** /**
* @brief AST graph creation function * @brief AST graph creation function
* @return The AST tree * @return The AST tree
...@@ -31,7 +29,7 @@ class GraphParser{ ...@@ -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 * @return query
*/ */
const std::string getQuery(); const std::string getQuery();
......
#ifndef AIDGE_CORE_MATCH_RESULT_H_ #ifndef AIDGE_CORE_MATCH_RESULT_H_
#define AIDGE_CORE_MATCH_RESULT_H_ #define AIDGE_CORE_MATCH_RESULT_H_
#include <cstddef>
#include <map>
#include <memory> #include <memory>
#include <string>
#include <set>
#include <vector> #include <vector>
#include <map>
#include "aidge/graphRegex/matchFsm/FsmRunTimeContext.hpp" #include "aidge/graphRegex/matchFsm/FsmRunTimeContext.hpp"
#include "aidge/graph/Node.hpp" #include "aidge/graph/Node.hpp"
...@@ -12,23 +14,25 @@ ...@@ -12,23 +14,25 @@
namespace Aidge{ 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{ class MatchSolution{
private: private:
std::map<std::string,std::set<NodePtr>> mSolution; std::map<std::string, std::set<NodePtr>> mSolution;
const std::string mQueryFrom; const std::string mQueryFrom;
const std::vector<NodePtr> mStartNode; const std::vector<NodePtr> mStartNode;
public: public:
MatchSolution(std::vector<std::shared_ptr<FsmRunTimeContext>>& precedence,const std::string query,const std::vector<NodePtr> startNode); 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); inline const std::set<NodePtr>& at(const std::string key) {
const std::set<NodePtr> getAll(); return mSolution[key];
}
const std::set<NodePtr> getAll();
bool areCompatible(std::shared_ptr<MatchSolution> solution); bool areCompatible(std::shared_ptr<MatchSolution> solution);
const std::string& getQuery(){ return mQueryFrom ;} inline const std::string& getQuery() const noexcept { return mQueryFrom; }
const std::vector<NodePtr>& getStartNode(){ return mStartNode ;} inline const std::vector<NodePtr>& getStartNode() const noexcept { return mStartNode; }
}; };
...@@ -59,15 +63,15 @@ public: ...@@ -59,15 +63,15 @@ public:
MatchResult(std::vector<std::shared_ptr<FsmRunTimeContext>> allValid, std::size_t nbSubStm, MatchResult(std::vector<std::shared_ptr<FsmRunTimeContext>> allValid, std::size_t nbSubStm,
const std::string& query,const std::vector<NodePtr>& startNodes); const std::string& query,const std::vector<NodePtr>& startNodes);
virtual ~MatchResult() = default;
/** /**
* @brief get the set of the node match for une expression * @brief get the set of the node match for une expression
* @return the set of node of the graph that corresponding to an expression * @return the set of node of the graph that corresponding to an expression
*/ */
std::shared_ptr<MatchSolution> getBiggerSolution(void); 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: private:
...@@ -75,7 +79,6 @@ private: ...@@ -75,7 +79,6 @@ private:
* @brief recurrent function use to init mSolve in the constructor * @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); void _generateCombination( std::size_t idxSubStm, std::vector<std::shared_ptr<FsmRunTimeContext>>& precedence,const std::string& query,const std::vector<NodePtr>& startNodes);
}; };
......
...@@ -38,7 +38,6 @@ class ConditionalParser{ ...@@ -38,7 +38,6 @@ class ConditionalParser{
*/ */
ConditionalParser(const std::string ConditionalExpressions); ConditionalParser(const std::string ConditionalExpressions);
virtual ~ConditionalParser() = default;
/** /**
* @brief AST graph creation function * @brief AST graph creation function
* @return The AST tree * @return The AST tree
......
...@@ -68,7 +68,7 @@ public: ...@@ -68,7 +68,7 @@ public:
// Hooks are not copied. // Hooks are not copied.
} }
virtual ~Operator(); virtual ~Operator() noexcept;
public: public:
virtual std::shared_ptr<Operator> clone() const = 0; virtual std::shared_ptr<Operator> clone() const = 0;
......
...@@ -61,7 +61,7 @@ public: ...@@ -61,7 +61,7 @@ public:
} }
} }
virtual ~OperatorTensor() = default; ~OperatorTensor();
public: public:
/////////////////////////////////////////////////// ///////////////////////////////////////////////////
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include <cassert> #include <cassert>
#include <iterator> #include <iterator>
#include <utility> #include <utility>
#include <numeric>
#include "aidge/utils/Types.h" #include "aidge/utils/Types.h"
#include "aidge/graph/GraphView.hpp" #include "aidge/graph/GraphView.hpp"
...@@ -108,20 +109,19 @@ void Aidge::GraphView::save(std::string path, bool verbose) const { ...@@ -108,20 +109,19 @@ void Aidge::GraphView::save(std::string path, bool verbose) const {
/////////////////////////////////////////////////////// ///////////////////////////////////////////////////////
Aidge::IOIndex_t Aidge::GraphView::getNbDataInputs() const { Aidge::IOIndex_t Aidge::GraphView::getNbDataInputs() const {
IOIndex_t nbDataInput = 0; return std::accumulate(mInputNodes.cbegin(), mInputNodes.cend(), 0,
// assert(outputNodes().size() == static_cast<std::size_t>(1)); [](IOIndex_t sumData, const std::shared_ptr<Node> inNode) {
for (const std::shared_ptr<Node> &inNode : inputNodes()) { return sumData + inNode->nbData();
nbDataInput += inNode->nbData(); }
} );
return nbDataInput;
} }
Aidge::IOIndex_t Aidge::GraphView::getNbFreeDataInputs() const { Aidge::IOIndex_t Aidge::GraphView::getNbFreeDataInputs() const {
IOIndex_t nbIn = 0; return std::accumulate(mInputNodes.cbegin(), mInputNodes.cend(), 0,
for (const std::shared_ptr<Node>& inputNode : mInputNodes) { [](IOIndex_t sumData, const std::shared_ptr<Node> inNode) {
nbIn += inputNode->getNbFreeDataInputs(); return sumData + inNode->getNbFreeDataInputs();
} }
return nbIn; );
} }
......
#include <algorithm> // set_intersection, std::sort
#include <memory>
#include <set>
#include <string>
#include <vector>
#include "aidge/graphRegex/matchFsm/MatchResult.hpp" #include "aidge/graphRegex/matchFsm/MatchResult.hpp"
using namespace Aidge; 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
MatchSolution::MatchSolution(std::vector<std::shared_ptr<FsmRunTimeContext>>& precedence,const std::string query,const std::vector<NodePtr> startNode):mQueryFrom(query),mStartNode(startNode){ for (const auto& context : precedence) {
//reformat the solution for (const auto& pair : context->getValid()) {
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;
if(mSolution.find(pair.first->getKey()) == mSolution.end()){ }else{
mSolution[pair.first->getKey()] = pair.second; mSolution[pair.first->getKey()].insert(pair.second.begin(), pair.second.end());
}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 // Iterate through the map and insert elements from each set into the unique set
std::set<NodePtr> uniqueSet; 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 // Insert elements from the current set into the unique set
for (const auto& pair : mSolution) { uniqueSet.insert(nodeSet.begin(), nodeSet.end());
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;
} return uniqueSet;
}
bool MatchSolution::areCompatible(std::shared_ptr<MatchSolution> solution){ bool Aidge::MatchSolution::areCompatible(std::shared_ptr<Aidge::MatchSolution> solution){
std::set<NodePtr> set1 = solution->getAll(); std::set<NodePtr> set1 = solution->getAll();
std::set<NodePtr> set2 = getAll(); std::set<NodePtr> set2 = getAll();
std::set<NodePtr> intersection ; std::set<NodePtr> intersection ;
std::set_intersection(set1.begin(), set1.end(), set2.begin(), set2.end(), std::inserter(intersection, intersection.begin())); std::set_intersection(set1.begin(), set1.end(), set2.begin(), set2.end(), std::inserter(intersection, intersection.begin()));
if (intersection.empty()) { return intersection.empty();
return true; }
}
return false;
}
//////////////////////////////// ////////////////////////////////
// //
//////////////////////////////// ////////////////////////////////
MatchResult::MatchResult(std::vector<std::shared_ptr<FsmRunTimeContext>> allValid, std::size_t nbSubStm, Aidge::MatchResult::MatchResult(std::vector<std::shared_ptr<Aidge::FsmRunTimeContext>> allValid,
const std::string& query,const std::vector<NodePtr>& startNodes):mIdToRunTime(nbSubStm),mNbSubStm(nbSubStm){ std::size_t nbSubStm,
mAllValid = allValid; const std::string& query,
const std::vector<Aidge::NodePtr>& startNodes)
//mIdToRunTimm : mIdToRunTime(nbSubStm),
for (const auto& contextPtr : allValid) { mNbSubStm(nbSubStm)
mIdToRunTime[contextPtr->getSubStmId()].push_back(contextPtr); {
} mAllValid = allValid;
//mIdToRunTimm
for (const auto& contextPtr : allValid) {
mIdToRunTime[contextPtr->getSubStmId()].push_back(contextPtr);
}
std::vector<std::shared_ptr<FsmRunTimeContext>> precedence; std::vector<std::shared_ptr<FsmRunTimeContext>> precedence;
//make all solution possible //make all solution possible
_generateCombination(0,precedence,query,startNodes); _generateCombination(0,precedence,query,startNodes);
//sort by solution number of elements //sort by solution number of elements
std::sort(mSolve.begin(), mSolve.end(), [](std::shared_ptr<MatchSolution>& set1, std::shared_ptr<MatchSolution>& set2) { std::sort(mSolve.begin(), mSolve.end(), [](std::shared_ptr<MatchSolution>& set1, std::shared_ptr<MatchSolution>& set2) {
return set1->getAll().size() < set2->getAll().size(); return set1->getAll().size() < set2->getAll().size();
}); });
} }
void MatchResult::_generateCombination( std::size_t idxSubStm, std::vector<std::shared_ptr<FsmRunTimeContext>>& precedence, void Aidge::MatchResult::_generateCombination( std::size_t idxSubStm,
const std::string& query,const std::vector<NodePtr>& startNodes){ 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 //it's end , we are below the number of stm
if (idxSubStm == mNbSubStm) if (idxSubStm == mNbSubStm)
{ {
//precedence contain a list of FSM compatible, we just need to //precedence contain a list of FSM compatible, we just need to
//check if all the nodes have been validated by at least one context //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 //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> validNode;
std::set<NodePtr> rejectNode; std::set<NodePtr> rejectNode;
...@@ -94,10 +91,10 @@ const std::string& query,const std::vector<NodePtr>& startNodes){ ...@@ -94,10 +91,10 @@ const std::string& query,const std::vector<NodePtr>& startNodes){
std::set<NodePtr> tmpR = contextPtr->getRejectedNodes(); std::set<NodePtr> tmpR = contextPtr->getRejectedNodes();
rejectNode.insert(tmpR.begin(),tmpR.end()); 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 it's not the case the match is not valid
if(std::includes(validNode.begin(), validNode.end(), rejectNode.begin(), rejectNode.end())){ 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)); mSolve.push_back(std::make_shared<MatchSolution>(precedence,query,startNodes));
} }
precedence.pop_back(); precedence.pop_back();
...@@ -105,12 +102,12 @@ const std::string& query,const std::vector<NodePtr>& startNodes){ ...@@ -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){ if(idxSubStm == 0){
precedence.push_back(contextPtrOneFsm); precedence.push_back(contextPtrOneFsm);
_generateCombination(idxSubStm+1,precedence,query,startNodes); _generateCombination(idxSubStm+1,precedence,query,startNodes);
}else{ }else{
//test if the new context is compatible with all the context in the precedence //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){ ...@@ -137,16 +134,6 @@ const std::string& query,const std::vector<NodePtr>& startNodes){
} }
std::shared_ptr<MatchSolution> MatchResult::getBiggerSolution(void){ std::shared_ptr<Aidge::MatchSolution> Aidge::MatchResult::getBiggerSolution(void){
return mSolve.empty() ? nullptr : mSolve[0];
if(mSolve.empty()){
return nullptr;
}else{
return mSolve[0];
}
}
std::vector<std::shared_ptr<MatchSolution>> MatchResult::getSolutions(void){
return mSolve;
} }
\ No newline at end of file
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
// // ctor // // ctor
// } // }
Aidge::Operator::~Operator() = default; Aidge::Operator::~Operator() noexcept = default;
/////////////////////////////////////////////////////// ///////////////////////////////////////////////////////
// IMPLEMENTATION // IMPLEMENTATION
......
...@@ -40,6 +40,8 @@ void Aidge::OperatorTensor::setInput(const Aidge::IOIndex_t inputIdx, const std: ...@@ -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) { void Aidge::OperatorTensor::setInput(const Aidge::IOIndex_t inputIdx, std::shared_ptr<Aidge::Data>&& data) {
if (strcmp(data->type(), "Tensor") != 0) { if (strcmp(data->type(), "Tensor") != 0) {
AIDGE_THROW_OR_ABORT(std::runtime_error, "%s Operator only accepts Tensors as inputs", type().c_str()); AIDGE_THROW_OR_ABORT(std::runtime_error, "%s Operator only accepts Tensors as inputs", type().c_str());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment