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
26b19e39
Commit
26b19e39
authored
5 years ago
by
Jacob Wahlman
Browse files
Options
Downloads
Patches
Plain Diff
Added tests and definition of method
parent
b8647143
No related branches found
No related tags found
1 merge request
!22
Resolve "Replacing Operations in SFG"
Pipeline
#12932
failed
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
+12
-0
12 additions, 0 deletions
b_asic/signal_flow_graph.py
test/test_sfg.py
+72
-0
72 additions, 0 deletions
test/test_sfg.py
with
84 additions
and
0 deletions
b_asic/signal_flow_graph.py
+
12
−
0
View file @
26b19e39
...
@@ -350,6 +350,18 @@ class SFG(AbstractOperation):
...
@@ -350,6 +350,18 @@ class SFG(AbstractOperation):
input_values
.
append
(
self
.
_evaluate_source
(
input_src
))
input_values
.
append
(
self
.
_evaluate_source
(
input_src
))
return
src
.
operation
.
evaluate_output
(
src
.
index
,
input_values
)
return
src
.
operation
.
evaluate_output
(
src
.
index
,
input_values
)
def
replace_component
(
self
,
component_type
,
_id
=
None
,
_type
=
None
):
"""
Find and replace all components matching either on GraphID, Type or both.
Then return a new deepcopy of the sfg with the replaced component.
Arguments:
component_type: The type of the new component, e.g Multiplication
Keyword arguments:
_id: The GraphID to match the component to replace.
_type: The Type to match the component to replace.
"""
pass
def
__str__
(
self
):
def
__str__
(
self
):
"""
Prints operations, inputs and outputs in a SFG
"""
Prints operations, inputs and outputs in a SFG
...
...
This diff is collapsed.
Click to expand it.
test/test_sfg.py
+
72
−
0
View file @
26b19e39
...
@@ -114,3 +114,75 @@ class TestComponents:
...
@@ -114,3 +114,75 @@ class TestComponents:
assert
set
([
comp
.
name
for
comp
in
mac_sfg
.
components
])
==
{
assert
set
([
comp
.
name
for
comp
in
mac_sfg
.
components
])
==
{
"
INP1
"
,
"
INP2
"
,
"
INP3
"
,
"
ADD1
"
,
"
ADD2
"
,
"
MUL1
"
,
"
OUT1
"
,
"
S1
"
,
"
S2
"
,
"
S3
"
,
"
S4
"
,
"
S5
"
,
"
S6
"
,
"
S7
"
}
"
INP1
"
,
"
INP2
"
,
"
INP3
"
,
"
ADD1
"
,
"
ADD2
"
,
"
MUL1
"
,
"
OUT1
"
,
"
S1
"
,
"
S2
"
,
"
S3
"
,
"
S4
"
,
"
S5
"
,
"
S6
"
,
"
S7
"
}
class
TestReplaceComponents
:
def
test_replace_addition
(
self
,
operation_tree
):
sfg
=
SFG
(
outputs
=
[
Output
(
operation_tree
)])
component_id
=
"
add3
"
sfg
=
sfg
.
replace_component
(
Multiplication
(
name
=
"
Multi
"
),
_id
=
component_id
)
assert
component_id
not
in
sfg
.
_components_by_id
.
keys
()
assert
"
Multi
"
in
sfg
.
_components_by_name
.
keys
()
def
test_replace_addition_large_tree
(
self
,
large_operation_tree
):
sfg
=
SFG
(
outputs
=
[
Output
(
large_operation_tree
)])
component_id
=
"
add2
"
sfg
=
sfg
.
replace_component
(
Multiplication
(
name
=
"
Multi
"
),
_id
=
component_id
)
assert
component_id
not
in
sfg
.
_components_by_id
.
keys
()
assert
"
Multi
"
in
sfg
.
_components_by_name
.
keys
()
def
test_replace_no_input_component
(
self
,
operation_tree
):
sfg
=
SFG
(
outputs
=
[
Output
(
operation_tree
)])
component_id
=
"
c1
"
sfg
=
sfg
.
replace_component
(
Constant
(
10
),
_id
=
component_id
)
assert
component_id
not
in
sfg
.
_components_by_id
.
keys
()
def
test_replace_no_destination_component
(
self
,
operation_tree
):
sfg
=
SFG
(
outputs
=
[
Output
(
operation_tree
)])
component_id
=
"
add1
"
sfg
.
replace_component
(
Multiplication
(
name
=
"
Multi
"
),
_id
=
component_id
)
assert
component_id
not
in
sfg
.
_components_by_id
.
keys
()
assert
"
Multi
"
in
sfg
.
_components_by_name
.
keys
()
def
test_replace_several_components
(
self
,
large_operation_tree
):
sfg
=
SFG
(
outputs
=
[
Output
(
large_operation_tree
)])
component_id
=
(
"
add1
"
,
"
add2
"
,
"
add3
"
)
sfg
=
sfg
.
replace_component
(
Multiplication
(
name
=
"
Multi
"
),
_id
=
component_id
)
assert
all
([
_id
not
in
sfg
.
_components_by_id
.
keys
()
for
_id
in
component_id
])
assert
"
Multi
"
in
sfg
.
_components_by_name
.
keys
()
assert
len
(
sfg
.
_components_by_name
[
"
Multi
"
])
==
3
def
test_replace_all_of_type_components
(
self
,
large_operation_tree
):
sfg
=
SFG
(
outputs
=
[
Output
(
large_operation_tree
)])
component_type
=
Addition
sfg
.
replace_component
(
Multiplication
(
name
=
"
Multi
"
),
_type
=
component_type
)
assert
all
([
not
isinstance
(
_type
,
Addition
)
for
_type
in
sfg
.
components
])
assert
"
Multi
"
in
sfg
.
_components_by_name
.
keys
()
assert
len
(
sfg
.
_components_by_name
[
"
Multi
"
])
==
3
def
test_no_match_on_replace
(
self
,
large_operation_tree
):
sfg
=
SFG
(
outputs
=
[
Output
(
large_operation_tree
)])
component_id
=
"
addd1
"
_sfg
=
sfg
.
replace_component
(
Multiplication
(
name
=
"
Multi
"
),
_id
=
component_id
)
assert
all
([
comp
in
sfg
.
components
for
comp
in
_sfg
])
assert
"
Multi
"
not
in
sfg
.
_components_by_name
.
keys
()
def
test_not_equal_input
(
self
,
large_operation_tree
):
sfg
=
SFG
(
outputs
=
[
Output
(
large_operation_tree
)])
component_id
=
"
c1
"
# Couldn't import pytest.raises
try
:
sfg
=
sfg
.
replace_component
(
Multiplication
(
name
=
"
Multi
"
),
component_id
)
except
AssertionError
:
assert
True
assert
False
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