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
b07dc0ac
Commit
b07dc0ac
authored
1 year ago
by
Oscar Gustafsson
Browse files
Options
Downloads
Patches
Plain Diff
Add is_constant to Signal
parent
62ba2144
No related branches found
No related tags found
1 merge request
!277
Add is_constant to Signal
Pipeline
#93814
failed
1 year ago
Stage: test
Stage: deploy
Changes
3
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
b_asic/operation.py
+2
-2
2 additions, 2 deletions
b_asic/operation.py
b_asic/signal.py
+9
-0
9 additions, 0 deletions
b_asic/signal.py
test/test_signal.py
+16
-1
16 additions, 1 deletion
test/test_signal.py
with
27 additions
and
3 deletions
b_asic/operation.py
+
2
−
2
View file @
b07dc0ac
...
...
@@ -477,7 +477,7 @@ class Operation(GraphComponent, SignalSourceProvider):
@abstractmethod
def
is_constant
(
self
)
->
bool
:
"""
Return True if the output of the operation is constant.
Return True if the output
(s)
of the operation is
(are)
constant.
"""
raise
NotImplementedError
...
...
@@ -948,7 +948,7 @@ class AbstractOperation(Operation, AbstractGraphComponent):
for
i
,
input_port
in
enumerate
(
self
.
inputs
):
value
=
input_values
[
i
]
if
bits_override
is
None
and
input_port
.
signal_count
>=
1
:
input_port
.
signals
[
0
].
bits
bits_override
=
input_port
.
signals
[
0
].
bits
if
bits_override
is
not
None
:
if
isinstance
(
value
,
complex
):
raise
TypeError
(
...
...
This diff is collapsed.
Click to expand it.
b_asic/signal.py
+
9
−
0
View file @
b07dc0ac
...
...
@@ -193,3 +193,12 @@ class Signal(AbstractGraphComponent):
if
bits
<
0
:
raise
ValueError
(
"
Bits cannot be negative
"
)
self
.
set_param
(
"
bits
"
,
bits
)
@property
def
is_constant
(
self
)
->
bool
:
"""
Return True if the value of the signal (source) is constant.
"""
if
self
.
source
is
None
:
raise
ValueError
(
"
Signal source not set
"
)
return
self
.
source
.
operation
.
is_constant
This diff is collapsed.
Click to expand it.
test/test_signal.py
+
16
−
1
View file @
b07dc0ac
...
...
@@ -4,9 +4,10 @@ B-ASIC test suit for the signal module which consists of the Signal class.
import
pytest
from
b_asic.core_operations
import
Addition
,
Butterfly
,
ConstantMultiplication
from
b_asic.core_operations
import
Addition
,
Butterfly
,
Constant
,
ConstantMultiplication
from
b_asic.port
import
InputPort
,
OutputPort
from
b_asic.signal
import
Signal
from
b_asic.special_operations
import
Input
def
test_signal_creation_and_disconnection_and_connection_changing
():
...
...
@@ -105,6 +106,16 @@ def test_create_from_single_input_single_output():
assert
signal
.
source
.
operation
.
name
==
"
Zig
"
def
test_signal_is_constant
():
c
=
Constant
(
0.5
,
name
=
"
Foo
"
)
signal
=
Signal
(
c
)
assert
signal
.
is_constant
i
=
Input
()
signal
=
Signal
(
i
)
assert
not
signal
.
is_constant
def
test_signal_errors
():
cm1
=
ConstantMultiplication
(
0.5
,
name
=
"
Foo
"
)
add1
=
Addition
(
name
=
"
Zig
"
)
...
...
@@ -146,3 +157,7 @@ def test_signal_errors():
),
):
signal
.
set_source
(
bf
)
signal
=
Signal
()
with
pytest
.
raises
(
ValueError
,
match
=
"
Signal source not set
"
):
signal
.
is_constant
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