Skip to content
Snippets Groups Projects
Commit 7f1ba66c authored by Olivier BICHLER's avatar Olivier BICHLER
Browse files

Merge branch 'fix_output' into 'dev'

Allow to specify any node as graph outputs

See merge request !193
parents 753f7e48 375a6a18
No related branches found
No related tags found
2 merge requests!212Version 0.3.0,!193Allow to specify any node as graph outputs
Pipeline #53871 passed
...@@ -318,6 +318,7 @@ void Aidge::GraphView::setOrderedInputs(const std::vector<std::pair<NodePtr, IOI ...@@ -318,6 +318,7 @@ void Aidge::GraphView::setOrderedInputs(const std::vector<std::pair<NodePtr, IOI
} }
void Aidge::GraphView::setOrderedOutputs(const std::vector<std::pair<NodePtr, IOIndex_t>>& outputs) { void Aidge::GraphView::setOrderedOutputs(const std::vector<std::pair<NodePtr, IOIndex_t>>& outputs) {
// Note: one can specify any node as graph output!
size_t nbOutputs = 0; size_t nbOutputs = 0;
std::vector<std::pair<NodePtr, IOIndex_t>> ignoredOutputs(mOutputNodes); std::vector<std::pair<NodePtr, IOIndex_t>> ignoredOutputs(mOutputNodes);
for (auto output : outputs) { for (auto output : outputs) {
...@@ -326,14 +327,13 @@ void Aidge::GraphView::setOrderedOutputs(const std::vector<std::pair<NodePtr, IO ...@@ -326,14 +327,13 @@ void Aidge::GraphView::setOrderedOutputs(const std::vector<std::pair<NodePtr, IO
// it into account. // it into account.
if (output.first != nullptr) { if (output.first != nullptr) {
auto it = std::find(ignoredOutputs.begin(), ignoredOutputs.end(), output); auto it = std::find(ignoredOutputs.begin(), ignoredOutputs.end(), output);
AIDGE_ASSERT(it != ignoredOutputs.end(), "unknown or duplicate output: {} (of type {})", output.first->name(), output.first->type()); if (it != ignoredOutputs.end()) {
ignoredOutputs.erase(it); ignoredOutputs.erase(it);
}
++nbOutputs; ++nbOutputs;
} }
} }
AIDGE_ASSERT(nbOutputs <= mOutputNodes.size(), "too many specified number of outputs: {} specified vs {} available", nbOutputs, mOutputNodes.size());
mOutputNodes = outputs; mOutputNodes = outputs;
mOutputNodes.insert(mOutputNodes.end(), ignoredOutputs.begin(), ignoredOutputs.end()); mOutputNodes.insert(mOutputNodes.end(), ignoredOutputs.begin(), ignoredOutputs.end());
} }
......
...@@ -108,13 +108,6 @@ TEST_CASE("clone_with_delete", "[GraphView][cloneDelete]") { ...@@ -108,13 +108,6 @@ TEST_CASE("clone_with_delete", "[GraphView][cloneDelete]") {
const size_t nbTests = 100; const size_t nbTests = 100;
size_t nbClonedWithDelete = 0; size_t nbClonedWithDelete = 0;
// Note: initial seed is chosen such that for nbTests=100, the generated
// graphs keep the same inputs/outputs despites the deleted nodes
// (meaning the deleted nodes are not input/output of the graph).
// Otherwise, the last two REQUIRE are not garanteed to be true!
// Warning: distributions are not required to behave the same way by the standard,
// therefore the seed has to work for both GCC and MSVC...
// See https://stackoverflow.com/questions/38532927/why-gcc-and-msvc-stdnormal-distribution-are-different
std::mt19937::result_type seed(243); std::mt19937::result_type seed(243);
for (int test = 0; test < nbTests; ++test) { for (int test = 0; test < nbTests; ++test) {
...@@ -124,7 +117,21 @@ TEST_CASE("clone_with_delete", "[GraphView][cloneDelete]") { ...@@ -124,7 +117,21 @@ TEST_CASE("clone_with_delete", "[GraphView][cloneDelete]") {
const auto g1 = std::make_shared<GraphView>("g1"); const auto g1 = std::make_shared<GraphView>("g1");
const bool unicity1 = g1->add(randGraph.gen(seed, 10)); const bool unicity1 = g1->add(randGraph.gen(seed, 10));
if (unicity1) { bool stableInOut = true;
for (auto node : g1->inputNodes()) {
if (node->type() == "DelFictive") {
stableInOut = false;
break;
}
}
for (auto node : g1->outputNodes()) {
if (node->type() == "DelFictive") {
stableInOut = false;
break;
}
}
if (unicity1 && stableInOut) {
randGraph.omitType = "DelFictive"; randGraph.omitType = "DelFictive";
const auto g2 = std::make_shared<GraphView>("g2"); const auto g2 = std::make_shared<GraphView>("g2");
const bool unicity2 = g2->add(randGraph.gen(seed, 10)); const bool unicity2 = g2->add(randGraph.gen(seed, 10));
......
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