Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
aidge_core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Cyril Moineau
aidge_core
Commits
da735299
Commit
da735299
authored
1 year ago
by
Maxence Naud
Browse files
Options
Downloads
Patches
Plain Diff
[Upd] the replace function to use graph ordering
parent
dd23ae05
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
include/aidge/graph/GraphView.hpp
+15
-8
15 additions, 8 deletions
include/aidge/graph/GraphView.hpp
src/graph/GraphView.cpp
+152
-140
152 additions, 140 deletions
src/graph/GraphView.cpp
with
167 additions
and
148 deletions
include/aidge/graph/GraphView.hpp
+
15
−
8
View file @
da735299
...
@@ -391,17 +391,24 @@ public:
...
@@ -391,17 +391,24 @@ public:
IOIndex_t
newParentInputTensorIdx
,
IOIndex_t
newParentInputTensorIdx
,
IOIndex_t
newParentOutputTensorIdx
);
IOIndex_t
newParentOutputTensorIdx
);
/**
/**
* @brief Replace a set of Nodes in every available GraphView with a new set of Nodes if possible.
* @brief Replace a set of Nodes in every available GraphView with a new set of Nodes if possible.
* Both sets should include all the necessary Producers.
* Both sets should include all the necessary Producers.
* @details Replaced Nodes are removed from any GraphView pointing at them all.
* @details There are 3 cases of replacement:
* The oldNodes set should have only one input/output
* Case 1: same number of input/output connections for oldNodes and newNodes sets.
* Tensor for automatic connections of newNodes set.
* - input/output connections are replacated according to their IDs.
* @param oldNodes actual set of shared_ptr<Node> to replace.
* Case 2: different number of input/output connections for oldNodes and newNodes sets.
* @param newNodes new set of shared_ptr<Node>.
* - only a single parent/child node for the newNodes set, every input/output is
* @return true
* connected to it.
* @return false
* - several parents/children nodes for newNodes set => impossible to know, return false
* Case 3: newNodes set is empty
* - same number of input/output connections in oldNodes, parents and children are linked according
* to these connections IDs
* - different number of input/output connections in oldNodes => return false
* @param oldNodes
* @param newNodes
* @return true replacement has been performed
* @return false no replacement has been performed
*/
*/
static
bool
replace
(
const
std
::
set
<
NodePtr
>&
oldNodes
,
const
std
::
set
<
NodePtr
>&
newNodes
);
static
bool
replace
(
const
std
::
set
<
NodePtr
>&
oldNodes
,
const
std
::
set
<
NodePtr
>&
newNodes
);
...
...
This diff is collapsed.
Click to expand it.
src/graph/GraphView.cpp
+
152
−
140
View file @
da735299
...
@@ -74,7 +74,7 @@ void Aidge::GraphView::save(std::string path, bool verbose) const {
...
@@ -74,7 +74,7 @@ void Aidge::GraphView::save(std::string path, bool verbose) const {
std
::
string
givenName
=
std
::
string
givenName
=
(
node_ptr
->
name
().
empty
())
(
node_ptr
->
name
().
empty
())
?
"<em>"
+
currentType
+
"#"
+
std
::
to_string
(
typeCounter
[
currentType
])
+
"</em>"
?
"<em>"
+
currentType
+
"#"
+
std
::
to_string
(
typeCounter
[
currentType
])
+
"</em>"
:
node_ptr
->
name
()
+
"
<sub><em>"
+
currentType
+
"</em></sub>"
;
:
"
\"
"
+
node_ptr
->
name
()
+
"
\\
n
<sub><em>
(
"
+
currentType
+
"
)
</em></sub>
\"
"
;
namePtrTable
[
node_ptr
]
=
namePtrTable
[
node_ptr
]
=
(
currentType
+
"_"
+
std
::
to_string
(
typeCounter
[
currentType
]));
(
currentType
+
"_"
+
std
::
to_string
(
typeCounter
[
currentType
]));
...
@@ -117,14 +117,14 @@ void Aidge::GraphView::save(std::string path, bool verbose) const {
...
@@ -117,14 +117,14 @@ void Aidge::GraphView::save(std::string path, bool verbose) const {
size_t
inputIdx
=
0
;
size_t
inputIdx
=
0
;
for
(
auto
input
:
mInputNodes
)
{
for
(
auto
input
:
mInputNodes
)
{
std
::
fprintf
(
fp
,
"input%lu((in#%lu)):::inputCls-->|→%u|%s
\n
"
,
inputIdx
,
inputIdx
,
std
::
fprintf
(
fp
,
"input%lu((in#%lu)):::inputCls--
-
>|→%u|%s
\n
"
,
inputIdx
,
inputIdx
,
input
.
second
,
namePtrTable
[
input
.
first
].
c_str
());
input
.
second
,
namePtrTable
[
input
.
first
].
c_str
());
++
inputIdx
;
++
inputIdx
;
}
}
size_t
outputIdx
=
0
;
size_t
outputIdx
=
0
;
for
(
auto
output
:
mOutputNodes
)
{
for
(
auto
output
:
mOutputNodes
)
{
std
::
fprintf
(
fp
,
"%s-->|%u→|output%lu((out#%lu)):::outputCls
\n
"
,
std
::
fprintf
(
fp
,
"%s--
-
>|%u→|output%lu((out#%lu)):::outputCls
\n
"
,
namePtrTable
[
output
.
first
].
c_str
(),
output
.
second
,
namePtrTable
[
output
.
first
].
c_str
(),
output
.
second
,
outputIdx
,
outputIdx
);
outputIdx
,
outputIdx
);
++
outputIdx
;
++
outputIdx
;
...
@@ -694,128 +694,150 @@ void Aidge::GraphView::insertParent(NodePtr childNode,
...
@@ -694,128 +694,150 @@ void Aidge::GraphView::insertParent(NodePtr childNode,
add
(
newParentNode
);
add
(
newParentNode
);
}
}
bool
Aidge
::
GraphView
::
replace
(
const
std
::
set
<
Aidge
::
NodePtr
>&
oldNodes
,
const
std
::
set
<
Aidge
::
NodePtr
>&
newNodes
)
{
bool
Aidge
::
GraphView
::
replace
(
const
std
::
set
<
Aidge
::
NodePtr
>&
oldNodes
,
const
std
::
set
<
Aidge
::
NodePtr
>&
newNodes
)
{
// TODO: handle case where an oldNodes parameter does not come from a Producer but another Node (not included in oldNodes)
// TODO: handle case where an oldNodes parameter does not come from a Producer but another Node (not included in oldNodes)
// How to distinguish it from data input?
// How to distinguish it from data input?
// TODO: Parameter Tensors could be identified with their dimensions
// TODO: Parameter Tensors could be identified with their dimensions
// TODO: Take GraphView as input parameters since new Nodes should be connected whatever.
// TODO: Take GraphView as input parameters since new Nodes should be connected whatever.
// It also avoids specifying each producer since they are automatically included
// It also avoids specifying each producer since they are automatically included
// (1) create GraphViews from both sets of Nodes
auto
oldG
=
std
::
make_shared
<
GraphView
>
(
"oldG"
);
auto
oldG
=
std
::
make_shared
<
GraphView
>
(
"oldG"
);
oldG
->
add
(
oldNodes
,
false
);
oldG
->
add
(
oldNodes
,
false
);
auto
newG
=
std
::
make_shared
<
GraphView
>
(
"newG"
);
auto
newG
=
std
::
make_shared
<
GraphView
>
(
"newG"
);
newG
->
add
(
newNodes
,
false
);
newG
->
add
(
newNodes
,
false
);
if
((
oldG
->
inputNodes
().
size
()
==
0
)
||
(
oldG
->
outputNodes
().
size
()
!=
1
))
{
const
auto
oldOI
=
oldG
->
getOrderedInputs
();
return
false
;
const
auto
oldOO
=
oldG
->
getOrderedOutputs
();
}
const
auto
newOI
=
newG
->
getOrderedInputs
();
if
(
!
(
newNodes
.
empty
())
&&
((
newG
->
inputNodes
().
size
()
==
0
)
||
const
auto
newOO
=
newG
->
getOrderedOutputs
();
(
newG
->
outputNodes
().
size
()
!=
1
)))
{
std
::
vector
<
std
::
pair
<
std
::
shared_ptr
<
Node
>
,
IOIndex_t
>>
inputParents
=
std
::
vector
<
std
::
pair
<
std
::
shared_ptr
<
Node
>
,
IOIndex_t
>>
(
oldOI
.
size
());
return
false
;
std
::
vector
<
std
::
pair
<
std
::
shared_ptr
<
Node
>
,
IOIndex_t
>>
outputChildren
=
std
::
vector
<
std
::
pair
<
std
::
shared_ptr
<
Node
>
,
IOIndex_t
>>
(
oldOO
.
size
());
// keep in memory every parent
for
(
std
::
size_t
i
=
0
;
i
<
oldOI
.
size
();
++
i
)
{
auto
inputParent
=
oldOI
[
i
].
first
->
input
(
oldOI
[
i
].
second
);
inputParents
[
i
]
=
inputParent
;
// inputParent.first -> addChild(newOI[i].first, inputParent.second, newOI[i].second);
}
}
for
(
std
::
size_t
i
=
0
;
i
<
oldOO
.
size
();)
{
// there is at least one inputNode in the old/new GraphView
auto
outputChildList
=
oldOO
[
i
].
first
->
output
(
oldOO
[
i
].
second
);
std
::
shared_ptr
<
Node
>
firstPreviousInputNode
=
(
*
(
oldG
->
inputNodes
()).
begin
());
if
(
outputChildList
.
empty
())
{
std
::
shared_ptr
<
Node
>
firstPreviousOutputNode
=
(
*
(
oldG
->
outputNodes
()).
begin
());
outputChildren
[
i
]
=
std
::
pair
<
std
::
shared_ptr
<
Node
>
,
IOIndex_t
>
({
nullptr
,
gk_IODefaultIndex
});
++
i
;
// find Node to link to new input Node
//compute number of input for firstPreviousInputNode not in oldNodes set
std
::
size_t
nbExternalInputs
=
0
;
std
::
shared_ptr
<
Node
>
externalInput
=
nullptr
;
IOIndex_t
externalInputId
=
gk_IODefaultIndex
;
for
(
const
auto
&
input
:
firstPreviousInputNode
->
inputs
())
{
if
(
oldNodes
.
find
(
input
.
first
)
==
oldNodes
.
end
())
{
// Node connected to another Node outside of oldG
nbExternalInputs
++
;
externalInput
=
input
.
first
;
externalInputId
=
input
.
second
;
}
}
}
else
{
if
(
nbExternalInputs
>
1
)
{
for
(
const
auto
&
child
:
outputChildList
)
{
AIDGE_INTERNAL_ASSERT
(
"To many input to link for oldNodes set"
);
if
(
oldNodes
.
find
(
child
.
first
)
==
oldNodes
.
cend
())
{
}
outputChildren
[
i
]
=
child
;
++
i
;
if
(
oldG
->
inputNodes
().
size
()
>
1
){
// one or no input has been identified. Checking every input points to the same source
for
(
const
auto
&
previousInputNode
:
oldG
->
inputNodes
())
{
for
(
const
auto
&
input
:
previousInputNode
->
inputs
())
{
if
(
oldNodes
.
find
(
input
.
first
)
==
oldNodes
.
end
())
{
if
(
(
externalInput
!=
input
.
first
)
||
(
externalInputId
!=
input
.
second
)
)
{
return
false
;
// an inputNode points to an external Node different from the registered one
}
}
}
}
}
}
}
}
}
if
(
firstPreviousOutputNode
->
nbOutputs
()
!=
1
)
{
return
false
;
}
// find Node to replicate output connections
std
::
shared_ptr
<
Node
>
newOutputNode
=
newNodes
.
empty
()
?
externalInput
:
*
(
newG
->
outputNodes
().
begin
());
auto
copyOutputs
=
firstPreviousOutputNode
->
outputs
();
// manage Views for newNodes
// only keep common views to each node for the new set
// only keep common views to each node for the new set
// set of common GraphView for oldNodes' Nodes
std
::
set
<
std
::
shared_ptr
<
GraphView
>>
commonGraphViews
=
(
*
oldNodes
.
begin
())
->
views
();
std
::
set
<
std
::
shared_ptr
<
GraphView
>>
commonGraphViews
=
(
*
oldNodes
.
begin
())
->
views
();
for
(
const
auto
&
nodePtr
:
oldNodes
)
{
for
(
const
auto
&
nodePtr
:
oldNodes
)
{
const
auto
nodeView
=
nodePtr
->
views
();
const
auto
nodeView
=
nodePtr
->
views
();
std
::
set
<
std
::
shared_ptr
<
GraphView
>>
intersection
;
std
::
set
<
std
::
shared_ptr
<
GraphView
>>
intersection
;
std
::
set_intersection
(
commonGraphViews
.
begin
(),
commonGraphViews
.
end
(),
std
::
set_intersection
(
commonGraphViews
.
begin
(),
commonGraphViews
.
end
(),
nodeView
.
begin
(),
nodeView
.
end
(),
nodeView
.
begin
(),
nodeView
.
end
(),
std
::
inserter
(
intersection
,
intersection
.
begin
()));
std
::
inserter
(
intersection
,
intersection
.
begin
()));
commonGraphViews
=
intersection
;
commonGraphViews
=
intersection
;
}
}
commonGraphViews
.
erase
(
oldG
);
commonGraphViews
.
erase
(
oldG
);
commonGraphViews
.
erase
(
newG
);
commonGraphViews
.
erase
(
newG
);
// clean Nodes to replace
if
((
newNodes
.
size
()
>
0
)
&&
(
oldOI
.
size
()
!=
newOI
.
size
())
&&
(
oldOO
.
size
()
!=
newOO
.
size
()))
{
// Do not include common Nodes to avoid cleaning Producers linked to newNodes
for
(
const
auto
&
nodePtr
:
oldNodes
)
{
std
::
set
<
std
::
shared_ptr
<
Node
>>
nodesToClean
;
nodePtr
->
removeView
(
oldG
);
std
::
set_difference
(
oldNodes
.
begin
(),
oldNodes
.
end
(),
}
newNodes
.
begin
(),
newNodes
.
end
(),
for
(
const
auto
&
nodePtr
:
newNodes
)
{
std
::
inserter
(
nodesToClean
,
nodesToClean
.
begin
()));
nodePtr
->
removeView
(
newG
);
for
(
auto
&
nodePtr
:
nodesToClean
)
{
nodePtr
->
resetConnections
(
true
);
}
}
return
false
;
// copy output connections
}
if
(
newOutputNode
)
{
for
(
IOIndex_t
o
=
0
;
o
<
firstPreviousOutputNode
->
nbOutputs
();
++
o
)
{
for
(
const
auto
&
nodePtr
:
oldNodes
)
{
auto
outputPairs
=
copyOutputs
[
o
];
for
(
const
auto
&
g
:
commonGraphViews
)
{
for
(
const
auto
&
onePair
:
outputPairs
)
{
g
->
remove
(
nodePtr
,
false
);
newOutputNode
->
addChild
(
onePair
.
first
,
o
,
onePair
.
second
);
g
->
updateInputsOutputsDelete
(
nodePtr
);
}
}
}
nodePtr
->
resetConnections
(
true
);
}
}
// copy input connections
if
((
oldOI
.
size
()
==
newOI
.
size
())
&&
if
(
!
newNodes
.
empty
()
&&
externalInput
)
{
(
oldOO
.
size
()
==
newOO
.
size
()))
{
for
(
const
auto
&
newInputNode
:
newG
->
inputNodes
())
{
// Case 1
IOIndex_t
inputId
=
0
;
for
(
std
::
size_t
i
=
0
;
i
<
oldOI
.
size
();
++
i
)
{
for
(
const
auto
&
input
:
newInputNode
->
inputs
())
{
if
(
inputParents
[
i
].
first
)
{
if
(
newNodes
.
find
(
input
.
first
)
==
newNodes
.
end
())
{
inputParents
[
i
].
first
->
addChild
(
newOI
[
i
].
first
,
inputParents
[
i
].
second
,
newOI
[
i
].
second
);
externalInput
->
addChild
(
newInputNode
,
externalInputId
,
inputId
);
}
}
for
(
std
::
size_t
o
=
0
;
o
<
oldOO
.
size
();
++
o
)
{
if
(
outputChildren
[
o
].
first
)
{
newOO
[
o
].
first
->
addChild
(
outputChildren
[
o
].
first
,
newOO
[
o
].
second
,
outputChildren
[
o
].
second
);
}
}
}
else
{
// get the number of Parents for oldG->inputNodes()
// get the number of Children for oldg->outputNodes()
if
(
newNodes
.
size
()
==
0
)
{
// Case 3
if
(
oldOI
.
size
()
==
oldOO
.
size
())
{
for
(
std
::
size_t
i
=
0
;
i
<
oldOI
.
size
();
++
i
)
{
inputParents
[
i
].
first
->
addChild
(
outputChildren
[
i
].
first
,
inputParents
[
i
].
second
,
outputChildren
[
i
].
second
);
}
}
else
if
(
oldOI
.
size
()
==
1
)
{
for
(
std
::
size_t
i
=
0
;
i
<
oldOI
.
size
();
++
i
)
{
inputParents
[
0
].
first
->
addChild
(
outputChildren
[
i
].
first
,
inputParents
[
0
].
second
,
outputChildren
[
i
].
second
);
}
}
}
else
if
(
// for tiling-like cases. The number of inputNodes changes but not outputNodes
((
oldOI
.
size
()
==
1
)
||
(
newOI
.
size
()
==
1
))
&&
// (oldOI.size() == newOI.size()) already handled in Case 1
((
oldOO
.
size
()
==
newOO
.
size
()))
)
{
// Case 2
if
((
oldOI
.
size
()
==
1
))
{
for
(
std
::
size_t
i
=
0
;
i
<
newOI
.
size
();
++
i
)
{
inputParents
[
0
].
first
->
addChild
(
newOI
[
i
].
first
,
inputParents
[
0
].
second
,
newOI
[
i
].
second
);
}
}
else
{
for
(
std
::
size_t
i
=
0
;
i
<
oldOI
.
size
();
++
i
)
{
inputParents
[
i
].
first
->
addChild
(
newOI
[
0
].
first
,
inputParents
[
i
].
second
,
newOI
[
0
].
second
);
}
}
for
(
std
::
size_t
o
=
0
;
o
<
oldOO
.
size
();
++
o
)
{
if
(
outputChildren
[
o
].
first
)
{
newOO
[
o
].
first
->
addChild
(
outputChildren
[
o
].
first
,
newOO
[
o
].
second
,
outputChildren
[
o
].
second
);
}
}
inputId
++
;
}
}
}
}
else
{
for
(
const
auto
&
nodePtr
:
oldNodes
)
{
nodePtr
->
removeView
(
oldG
);
}
for
(
const
auto
&
nodePtr
:
newNodes
)
{
nodePtr
->
removeView
(
newG
);
}
return
false
;
}
}
}
for
(
const
auto
&
nodePtr
:
newNodes
)
{
// insert new Nodes in the right GraphViews
for
(
const
auto
&
g
:
commonGraphViews
)
{
for
(
const
auto
&
graphPtr
:
commonGraphViews
)
{
g
->
add
(
nodePtr
);
graphPtr
->
add
(
newNodes
,
false
);
if
(
newNodes
.
empty
())
{
// TODO: FIXME: this function should not be called anymore!
graphPtr
->
updateInputsOutputsNodes_DEPRECATED
();
}
}
}
}
for
(
const
auto
&
nodePtr
:
oldNodes
)
{
for
(
const
auto
&
node
:
oldNodes
)
{
nodePtr
->
removeView
(
oldG
);
node
->
removeView
(
oldG
);
}
}
for
(
const
auto
&
node
:
newNodes
)
{
for
(
const
auto
&
node
Ptr
:
newNodes
)
{
node
->
removeView
(
newG
);
node
Ptr
->
removeView
(
newG
);
}
}
return
true
;
return
true
;
}
}
...
@@ -824,22 +846,22 @@ void Aidge::GraphView::updateInputsOutputsNew(std::shared_ptr<Node> newNode) {
...
@@ -824,22 +846,22 @@ void Aidge::GraphView::updateInputsOutputsNew(std::shared_ptr<Node> newNode) {
// Can be called several times with the same node, e.g. when addChild() is
// Can be called several times with the same node, e.g. when addChild() is
// called on a node already part of the GraphView. In this case, inputs/outputs
// called on a node already part of the GraphView. In this case, inputs/outputs
// need to be updated!
// need to be updated!
std
::
vector
<
std
::
pair
<
NodePtr
,
IOIndex_t
>>::
iterator
newInputsInsertionPoint
=
mInputNodes
.
end
();
std
::
vector
<
std
::
pair
<
NodePtr
,
IOIndex_t
>>::
const_
iterator
newInputsInsertionPoint
=
mInputNodes
.
c
end
();
// Remove inputs that are not input anymore because connected to newNode
// Remove inputs that are not input anymore because connected to newNode
for
(
auto
orderedChilds
:
newNode
->
getOrderedChildren
())
{
for
(
auto
orderedChilds
:
newNode
->
getOrderedChildren
())
{
for
(
auto
ch_ptr
:
orderedChilds
)
{
for
(
auto
ch_ptr
:
orderedChilds
)
{
// Check that newNode child is in current GraphView
// Check that newNode child is in current GraphView
if
(
mNodes
.
find
(
ch_ptr
)
!=
mNodes
.
end
())
{
if
(
mNodes
.
find
(
ch_ptr
)
!=
mNodes
.
c
end
())
{
IOIndex_t
inputIdx
=
0
;
IOIndex_t
inputIdx
=
0
;
for
(
const
std
::
shared_ptr
<
Node
>&
pa_ptr
:
ch_ptr
->
getParents
())
{
for
(
const
std
::
shared_ptr
<
Node
>&
pa_ptr
:
ch_ptr
->
getParents
())
{
// If newNode is connected to it
// If newNode is connected to it
if
(
pa_ptr
==
newNode
)
{
if
(
pa_ptr
==
newNode
)
{
const
auto
val
=
std
::
make_pair
(
ch_ptr
,
inputIdx
);
const
auto
val
=
std
::
make_pair
(
ch_ptr
,
inputIdx
);
const
auto
iter
=
std
::
find
(
mInputNodes
.
begin
(),
mInputNodes
.
end
(),
val
);
const
auto
iter
=
std
::
find
(
mInputNodes
.
c
begin
(),
mInputNodes
.
c
end
(),
val
);
// Check that it was not already the case (if node UPDATE)
// Check that it was not already the case (if node UPDATE)
if
(
iter
!=
mInputNodes
.
end
())
{
if
(
iter
!=
mInputNodes
.
c
end
())
{
// newNode is linked to an actual inputNode to an input connection
// The first old (removed) input becomes the insertion point for newNode GraphView inputs
// The first old (removed) input becomes the insertion point for newNode GraphView inputs
if
(
std
::
distance
(
newInputsInsertionPoint
,
iter
)
<=
0
)
{
if
(
std
::
distance
(
newInputsInsertionPoint
,
iter
)
<=
0
)
{
newInputsInsertionPoint
=
mInputNodes
.
erase
(
iter
);
newInputsInsertionPoint
=
mInputNodes
.
erase
(
iter
);
...
@@ -855,55 +877,45 @@ void Aidge::GraphView::updateInputsOutputsNew(std::shared_ptr<Node> newNode) {
...
@@ -855,55 +877,45 @@ void Aidge::GraphView::updateInputsOutputsNew(std::shared_ptr<Node> newNode) {
}
}
}
}
// Check if node inputs are inputs for the GraphView and add them to the input list if so
// Manage newNode parents
// Inputs addition order follows node inputs order
// Check if any input connection is an input for the GraphView
// Inputs are inserted at the position of the first input removed
IOIndex_t
inputIdx
=
0U
;
IOIndex_t
inputIdx
=
0U
;
for
(
const
std
::
shared_ptr
<
Node
>&
pa_ptr
:
newNode
->
getParents
())
{
for
(
const
std
::
shared_ptr
<
Node
>&
pa_ptr
:
newNode
->
getParents
())
{
const
auto
val
=
std
::
make_pair
(
newNode
,
inputIdx
);
if
((
pa_ptr
==
nullptr
)
||
const
auto
it
=
std
::
find
(
mInputNodes
.
cbegin
(),
mInputNodes
.
cend
(),
val
);
(
mNodes
.
find
(
pa_ptr
)
==
if
((
pa_ptr
==
nullptr
)
||
mNodes
.
end
()))
{
// Parent doesn't exist || Parent not in the graph
(
mNodes
.
find
(
pa_ptr
)
==
mNodes
.
cend
()))
{
const
auto
val
=
std
::
make_pair
(
newNode
,
inputIdx
);
// Parent doesn't exist || Parent not in the graph
if
(
std
::
find
(
mInputNodes
.
begin
(),
mInputNodes
.
end
(),
val
)
==
mInputNodes
.
end
())
{
if
(
it
==
mInputNodes
.
cend
())
{
newInputsInsertionPoint
=
mInputNodes
.
insert
(
newInputsInsertionPoint
,
val
);
// If node's inputs are inputs for the GraphView: add them to the input list
newInputsInsertionPoint
=
std
::
next
(
newInputsInsertionPoint
);
// Addition rule:
}
// - Inputs addition order follows node inputs order
}
// - Inputs are inserted at the position of the first input removed
++
inputIdx
;
newInputsInsertionPoint
=
mInputNodes
.
insert
(
newInputsInsertionPoint
,
val
);
}
newInputsInsertionPoint
=
std
::
next
(
newInputsInsertionPoint
);
}
// (if node UPDATE)
}
else
if
(
it
!=
mInputNodes
.
cend
())
{
// newNode may already exists in the graph and may have been updated
// Parent already in the graph SO edge is not an input anymore for the graph
// Check and remove inputs that are not inputs anymore
mInputNodes
.
erase
(
it
);
inputIdx
=
0U
;
}
for
(
const
std
::
shared_ptr
<
Node
>&
pa_ptr
:
newNode
->
getParents
())
{
++
inputIdx
;
if
((
pa_ptr
!=
nullptr
)
&&
(
mNodes
.
find
(
pa_ptr
)
!=
mNodes
.
end
()))
{
const
auto
val
=
std
::
make_pair
(
newNode
,
inputIdx
);
auto
it
=
std
::
find
(
mInputNodes
.
begin
(),
mInputNodes
.
end
(),
val
);
if
(
it
!=
mInputNodes
.
end
())
{
mInputNodes
.
erase
(
it
);
}
}
}
++
inputIdx
;
}
std
::
vector
<
std
::
pair
<
NodePtr
,
IOIndex_t
>>::
iterator
newOutputsInsertionPoint
=
mOutputNodes
.
end
();
std
::
vector
<
std
::
pair
<
NodePtr
,
IOIndex_t
>>::
const_
iterator
newOutputsInsertionPoint
=
mOutputNodes
.
c
end
();
// Remove outputs that are not output anymore because connected to newNode
// Remove outputs that are not output anymore because connected to newNode
for
(
const
std
::
shared_ptr
<
Node
>&
parent
:
newNode
->
getParents
())
{
for
(
const
std
::
shared_ptr
<
Node
>&
parent
:
newNode
->
getParents
())
{
// Check that newNode parent is in current GraphView
// Check that newNode parent is in current GraphView
if
(
mNodes
.
find
(
parent
)
!=
mNodes
.
end
())
{
if
(
mNodes
.
find
(
parent
)
!=
mNodes
.
c
end
())
{
IOIndex_t
outputIdx
=
0
;
IOIndex_t
outputIdx
=
0
;
for
(
auto
orderedChilds
:
parent
->
getOrderedChildren
())
{
for
(
auto
orderedChilds
:
parent
->
getOrderedChildren
())
{
for
(
auto
ch_ptr
:
orderedChilds
)
{
for
(
auto
ch_ptr
:
orderedChilds
)
{
// If newNode is connected to it
// If newNode is connected to it
if
(
ch_ptr
==
newNode
)
{
if
(
ch_ptr
==
newNode
)
{
const
auto
val
=
std
::
make_pair
(
parent
,
outputIdx
);
const
auto
val
=
std
::
make_pair
(
parent
,
outputIdx
);
const
auto
iter
=
std
::
find
(
mOutputNodes
.
begin
(),
mOutputNodes
.
end
(),
val
);
const
auto
iter
=
std
::
find
(
mOutputNodes
.
c
begin
(),
mOutputNodes
.
c
end
(),
val
);
if
(
iter
!=
mOutputNodes
.
end
())
{
if
(
iter
!=
mOutputNodes
.
c
end
())
{
// The first old (removed) output becomes the insertion point for newNode GraphView outputs
// The first old (removed) output becomes the insertion point for newNode GraphView outputs
if
(
std
::
distance
(
newOutputsInsertionPoint
,
iter
)
<=
0
)
{
if
(
std
::
distance
(
newOutputsInsertionPoint
,
iter
)
<=
0
)
{
newOutputsInsertionPoint
=
mOutputNodes
.
erase
(
iter
);
newOutputsInsertionPoint
=
mOutputNodes
.
erase
(
iter
);
...
@@ -943,14 +955,14 @@ void Aidge::GraphView::updateInputsOutputsNew(std::shared_ptr<Node> newNode) {
...
@@ -943,14 +955,14 @@ void Aidge::GraphView::updateInputsOutputsNew(std::shared_ptr<Node> newNode) {
}
}
void
Aidge
::
GraphView
::
updateInputsOutputsDelete
(
std
::
shared_ptr
<
Node
>
deletedNode
)
{
void
Aidge
::
GraphView
::
updateInputsOutputsDelete
(
std
::
shared_ptr
<
Node
>
deletedNode
)
{
std
::
vector
<
std
::
pair
<
NodePtr
,
IOIndex_t
>>::
iterator
newInputsInsertionPoint
=
mInputNodes
.
end
();
std
::
vector
<
std
::
pair
<
NodePtr
,
IOIndex_t
>>::
const_
iterator
newInputsInsertionPoint
=
mInputNodes
.
c
end
();
// Check if node inputs were inputs for the GraphView and remove them from the list if so
// Check if node inputs were inputs for the GraphView and remove them from the list if so
for
(
IOIndex_t
inputIdx
=
0
;
inputIdx
<
deletedNode
->
getParents
().
size
();
++
inputIdx
)
{
for
(
IOIndex_t
inputIdx
=
0
;
inputIdx
<
deletedNode
->
getParents
().
size
();
++
inputIdx
)
{
const
auto
val
=
std
::
make_pair
(
deletedNode
,
inputIdx
);
const
auto
val
=
std
::
make_pair
(
deletedNode
,
inputIdx
);
const
auto
iter
=
std
::
find
(
mInputNodes
.
begin
(),
mInputNodes
.
end
(),
val
);
const
auto
iter
=
std
::
find
(
mInputNodes
.
c
begin
(),
mInputNodes
.
c
end
(),
val
);
if
(
iter
!=
mInputNodes
.
end
())
{
if
(
iter
!=
mInputNodes
.
c
end
())
{
// The first old (removed) input becomes the insertion point for new GraphView inputs
// The first old (removed) input becomes the insertion point for new GraphView inputs
if
(
std
::
distance
(
newInputsInsertionPoint
,
iter
)
<=
0
)
{
if
(
std
::
distance
(
newInputsInsertionPoint
,
iter
)
<=
0
)
{
newInputsInsertionPoint
=
mInputNodes
.
erase
(
iter
);
newInputsInsertionPoint
=
mInputNodes
.
erase
(
iter
);
...
@@ -966,13 +978,13 @@ void Aidge::GraphView::updateInputsOutputsDelete(std::shared_ptr<Node> deletedNo
...
@@ -966,13 +978,13 @@ void Aidge::GraphView::updateInputsOutputsDelete(std::shared_ptr<Node> deletedNo
for
(
auto
orderedChilds
:
deletedNode
->
getOrderedChildren
())
{
for
(
auto
orderedChilds
:
deletedNode
->
getOrderedChildren
())
{
for
(
auto
ch_ptr
:
orderedChilds
)
{
for
(
auto
ch_ptr
:
orderedChilds
)
{
// Check that deletedNode child is in current GraphView
// Check that deletedNode child is in current GraphView
if
(
mNodes
.
find
(
ch_ptr
)
!=
mNodes
.
end
())
{
if
(
mNodes
.
find
(
ch_ptr
)
!=
mNodes
.
c
end
())
{
IOIndex_t
inputIdx
=
0
;
IOIndex_t
inputIdx
=
0
;
for
(
const
std
::
shared_ptr
<
Node
>&
pa_ptr
:
ch_ptr
->
getParents
())
{
for
(
const
std
::
shared_ptr
<
Node
>&
pa_ptr
:
ch_ptr
->
getParents
())
{
// If newNode was connected to it
// If newNode was connected to it
if
(
pa_ptr
==
deletedNode
)
{
if
(
pa_ptr
==
deletedNode
)
{
const
auto
val
=
std
::
make_pair
(
ch_ptr
,
inputIdx
);
const
auto
val
=
std
::
make_pair
(
ch_ptr
,
inputIdx
);
if
(
std
::
find
(
mInputNodes
.
begin
(),
mInputNodes
.
end
(),
val
)
==
mInputNodes
.
end
())
{
if
(
std
::
find
(
mInputNodes
.
c
begin
(),
mInputNodes
.
c
end
(),
val
)
==
mInputNodes
.
c
end
())
{
newInputsInsertionPoint
=
mInputNodes
.
insert
(
newInputsInsertionPoint
,
val
);
newInputsInsertionPoint
=
mInputNodes
.
insert
(
newInputsInsertionPoint
,
val
);
newInputsInsertionPoint
=
std
::
next
(
newInputsInsertionPoint
);
newInputsInsertionPoint
=
std
::
next
(
newInputsInsertionPoint
);
}
}
...
@@ -982,15 +994,15 @@ void Aidge::GraphView::updateInputsOutputsDelete(std::shared_ptr<Node> deletedNo
...
@@ -982,15 +994,15 @@ void Aidge::GraphView::updateInputsOutputsDelete(std::shared_ptr<Node> deletedNo
}
}
}
}
}
}
std
::
vector
<
std
::
pair
<
NodePtr
,
IOIndex_t
>>::
iterator
newOutputsInsertionPoint
=
mOutputNodes
.
end
();
std
::
vector
<
std
::
pair
<
NodePtr
,
IOIndex_t
>>::
const_
iterator
newOutputsInsertionPoint
=
mOutputNodes
.
c
end
();
// Check if node outputs were outputs for the GraphView and remove them from the list if so
// Check if node outputs were outputs for the GraphView and remove them from the list if so
for
(
IOIndex_t
outputIdx
=
0
;
outputIdx
<
deletedNode
->
getOrderedChildren
().
size
();
++
outputIdx
)
{
for
(
IOIndex_t
outputIdx
=
0
;
outputIdx
<
deletedNode
->
getOrderedChildren
().
size
();
++
outputIdx
)
{
const
auto
val
=
std
::
make_pair
(
deletedNode
,
outputIdx
);
const
auto
val
=
std
::
make_pair
(
deletedNode
,
outputIdx
);
const
auto
iter
=
std
::
find
(
mOutputNodes
.
begin
(),
mOutputNodes
.
end
(),
val
);
const
auto
iter
=
std
::
find
(
mOutputNodes
.
c
begin
(),
mOutputNodes
.
c
end
(),
val
);
if
(
iter
!=
mOutputNodes
.
end
())
{
if
(
iter
!=
mOutputNodes
.
c
end
())
{
// The first old (removed) output becomes the insertion point for newNode GraphView outputs
// The first old (removed) output becomes the insertion point for newNode GraphView outputs
if
(
std
::
distance
(
newOutputsInsertionPoint
,
iter
)
<=
0
)
{
if
(
std
::
distance
(
newOutputsInsertionPoint
,
iter
)
<=
0
)
{
newOutputsInsertionPoint
=
mOutputNodes
.
erase
(
iter
);
newOutputsInsertionPoint
=
mOutputNodes
.
erase
(
iter
);
...
@@ -1004,7 +1016,7 @@ void Aidge::GraphView::updateInputsOutputsDelete(std::shared_ptr<Node> deletedNo
...
@@ -1004,7 +1016,7 @@ void Aidge::GraphView::updateInputsOutputsDelete(std::shared_ptr<Node> deletedNo
// Add parent node outputs that become GraphView output following the removal of the node
// Add parent node outputs that become GraphView output following the removal of the node
// Outputs addition order follows deletedNode inputs order
// Outputs addition order follows deletedNode inputs order
for
(
const
std
::
shared_ptr
<
Node
>&
parent
:
deletedNode
->
getParents
())
{
for
(
const
std
::
shared_ptr
<
Node
>&
parent
:
deletedNode
->
getParents
())
{
if
(
parent
!=
nullptr
&&
mNodes
.
find
(
parent
)
!=
mNodes
.
end
())
{
if
(
mNodes
.
find
(
parent
)
!=
mNodes
.
end
())
{
IOIndex_t
outputIdx
=
0
;
IOIndex_t
outputIdx
=
0
;
for
(
auto
orderedChilds
:
parent
->
getOrderedChildren
())
{
for
(
auto
orderedChilds
:
parent
->
getOrderedChildren
())
{
bool
noInsideConnection
=
true
;
bool
noInsideConnection
=
true
;
...
@@ -1017,7 +1029,7 @@ void Aidge::GraphView::updateInputsOutputsDelete(std::shared_ptr<Node> deletedNo
...
@@ -1017,7 +1029,7 @@ void Aidge::GraphView::updateInputsOutputsDelete(std::shared_ptr<Node> deletedNo
if
(
noInsideConnection
)
{
if
(
noInsideConnection
)
{
const
auto
val
=
std
::
make_pair
(
parent
,
outputIdx
);
const
auto
val
=
std
::
make_pair
(
parent
,
outputIdx
);
if
(
std
::
find
(
mOutputNodes
.
begin
(),
mOutputNodes
.
end
(),
val
)
==
mOutputNodes
.
end
())
{
if
(
std
::
find
(
mOutputNodes
.
c
begin
(),
mOutputNodes
.
c
end
(),
val
)
==
mOutputNodes
.
c
end
())
{
newOutputsInsertionPoint
=
mOutputNodes
.
insert
(
newOutputsInsertionPoint
,
val
);
newOutputsInsertionPoint
=
mOutputNodes
.
insert
(
newOutputsInsertionPoint
,
val
);
newOutputsInsertionPoint
=
std
::
next
(
newOutputsInsertionPoint
);
newOutputsInsertionPoint
=
std
::
next
(
newOutputsInsertionPoint
);
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment