Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B-ASIC - Better ASIC Toolbox
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
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
Package registry
Model registry
Operate
Environments
Terraform modules
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
Computer Engineering
B-ASIC - Better ASIC Toolbox
Commits
729c11be
Commit
729c11be
authored
5 years ago
by
Kevin
Browse files
Options
Downloads
Patches
Plain Diff
implemented operation replacement and changed some test since we return a deepcopy of the sfg
parent
dca8af0e
Branches
Branches containing commit
No related tags found
1 merge request
!44
Resolve "Operation Replacement in a SFG"
Pipeline
#14841
passed
5 years ago
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
b_asic/signal_flow_graph.py
+25
-17
25 additions, 17 deletions
b_asic/signal_flow_graph.py
test/test_sfg.py
+5
-5
5 additions, 5 deletions
test/test_sfg.py
with
30 additions
and
22 deletions
b_asic/signal_flow_graph.py
+
25
−
17
View file @
729c11be
...
...
@@ -406,7 +406,7 @@ class SFG(AbstractOperation):
return
self
()
def
replace_operations
(
self
,
operation_ids
:
Sequence
[
GraphID
],
operation
:
Operation
):
"""
Replace multiple operations in the sfg with a operation
of equivalent functionallity
with the same
number
of inputs and outputs.
"""
Replace multiple operations in the sfg with a operation with the same
amount
of inputs and outputs.
Then return a new deepcopy of the sfg with the replaced operations.
Arguments:
...
...
@@ -414,28 +414,36 @@ class SFG(AbstractOperation):
operation: The operation used for replacement.
"""
operations
=
[
self
.
find_by_id
(
_id
)
for
_id
in
operation_ids
]
inputs
=
[]
outputs
=
[]
assert
sum
(
o
.
input_count
+
o
.
output_count
for
o
in
operations
)
==
operation
.
input_count
+
operation
.
output_count
,
\
"
The input and output count must match
"
# Create a copy of the sfg for manipulating
_sfg
=
self
()
for
_operation
in
self
.
operations
:
if
_operation
.
graph_id
not
in
operation_ids
:
continue
# Retrive input operations
for
_signal
in
_operation
.
input_signals
:
if
_signal
.
source
.
operation
.
graph_id
not
in
operation_ids
:
inputs
.
append
(
_signal
.
source
.
operation
)
for
operation
in
operations
:
operation
# Retrive output operations
for
_signal
in
_operation
.
output_signals
:
if
_signal
.
destination
.
operation
.
graph_id
not
in
operation_ids
:
outputs
.
append
(
_signal
.
destination
.
operation
)
assert
len
(
inputs
)
+
len
(
outputs
)
==
\
operation
.
input_count
+
operation
.
output_count
,
"
The input and output count must match
"
for
_
index
,
_inp
in
enumerate
(
inputs
):
for
_signal
in
_inp
.
output_signals
:
for
index
_in
,
_inp
ut
in
enumerate
(
inputs
):
for
_signal
in
_inp
ut
.
output_signals
:
_signal
.
remove_destination
()
_signal
.
set_destination
(
operation
.
input
(
_
index
))
_signal
.
set_destination
(
operation
.
input
(
index
_in
))
for
_
index
,
_out
in
enumerate
(
outputs
):
for
_signal
in
_out
.
input_signals
:
_signal
.
remove_
destination
()
_signal
.
set_source
(
operation
.
output
(
_
index
))
for
index
_out
,
_out
put
in
enumerate
(
outputs
):
for
_signal
in
_out
put
.
input_signals
:
_signal
.
remove_
source
()
_signal
.
set_source
(
operation
.
output
(
index
_out
))
return
self
()
def
_evaluate_source
(
self
,
src
:
OutputPort
,
results
:
MutableResultMap
,
registers
:
MutableRegisterMap
,
prefix
:
str
)
->
Number
:
...
...
This diff is collapsed.
Click to expand it.
test/test_sfg.py
+
5
−
5
View file @
729c11be
...
...
@@ -268,22 +268,22 @@ class TestReplaceOperations:
mad1
=
MAD
()
_sfg
=
sfg
.
replace_operations
([
'
add1
'
,
'
mul1
'
],
mad1
)
assert
mad1
in
_sfg
.
operati
on
s
assert
_sfg
.
find_by_id
(
'
mad1
'
)
is
not
N
on
e
assert
{
add1
,
mul1
}
not
in
_sfg
.
operations
def
test_replace_neg_add_with_sub
(
self
):
in1
=
Input
()
in2
=
Input
()
neg1
=
ConstantMultiplication
(
-
1
,
in1
)
neg1
=
ConstantMultiplication
(
-
1
,
in1
,
'
neg1
'
)
add1
=
neg1
+
in2
out1
=
Output
(
add1
)
sfg
=
SFG
(
inputs
=
[
in1
,
in2
],
outputs
=
[
out1
])
sub1
=
Subtraction
()
sfg
.
replace_operations
([
'
add1, neg1
'
],
sub1
)
_sfg
=
sfg
.
replace_operations
([
'
add1
'
,
'
neg1
'
],
sub1
)
assert
sub1
in
sfg
.
operati
on
s
assert
{
add1
,
neg1
}
not
in
sfg
.
operations
assert
_sfg
.
find_by_id
(
'
sub1
'
)
is
not
N
on
e
assert
{
add1
,
neg1
}
not
in
_
sfg
.
operations
def
test_different_input_output_count
(
self
,
operation_tree
):
sfg
=
SFG
(
outputs
=
[
Output
(
operation_tree
)])
...
...
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