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
d86cbdb8
Commit
d86cbdb8
authored
2 years ago
by
Oscar Gustafsson
Browse files
Options
Downloads
Patches
Plain Diff
Add utils module and functions
parent
3f9dd294
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!280
Add utils module and functions
Pipeline
#93884
passed
2 years ago
Stage: test
Stage: deploy
Changes
4
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
b_asic/utils.py
+47
-0
47 additions, 0 deletions
b_asic/utils.py
docs_sphinx/api/index.rst
+1
-0
1 addition, 0 deletions
docs_sphinx/api/index.rst
docs_sphinx/api/utils.rst
+7
-0
7 additions, 0 deletions
docs_sphinx/api/utils.rst
test/test_utils.py
+22
-0
22 additions, 0 deletions
test/test_utils.py
with
77 additions
and
0 deletions
b_asic/utils.py
0 → 100644
+
47
−
0
View file @
d86cbdb8
"""
B-ASIC Utils.
"""
from
typing
import
List
,
Sequence
from
b_asic.types
import
Num
def
interleave
(
*
args
)
->
List
[
Num
]:
"""
Interleave a number of arrays.
For the input ``interleave([1, 2], [3, 4])``, return ``[1, 2, 3, 4]``.
Parameters
----------
*args : a number of arrays
Arrays to interleave. Must be of the same length.
Returns
-------
"""
return
[
val
for
tup
in
zip
(
*
args
)
for
val
in
tup
]
def
downsample
(
a
:
Sequence
[
Num
],
factor
:
int
,
phase
:
int
=
0
)
->
List
[
Num
]:
"""
Downsample a sequence with an integer factor.
Keeps every *factor* value, starting with *phase*.
Parameters
----------
a : array
The array to downsample.
factor : int
The factor to downsample with.
phase : int, default: 0
The phase of the downsampling.
Returns
-------
"""
return
a
[
phase
::
factor
]
This diff is collapsed.
Click to expand it.
docs_sphinx/api/index.rst
+
1
−
0
View file @
d86cbdb8
...
@@ -19,3 +19,4 @@ API
...
@@ -19,3 +19,4 @@ API
signal_generator.rst
signal_generator.rst
simulation.rst
simulation.rst
special_operations.rst
special_operations.rst
utils.rst
This diff is collapsed.
Click to expand it.
docs_sphinx/api/utils.rst
0 → 100644
+
7
−
0
View file @
d86cbdb8
****************
``b_asic.utils``
****************
.. automodule:: b_asic.utils
:members:
:undoc-members:
This diff is collapsed.
Click to expand it.
test/test_utils.py
0 → 100644
+
22
−
0
View file @
d86cbdb8
"""
B-ASIC test suite for the utils module.
"""
from
b_asic.utils
import
downsample
,
interleave
def
test_interleave
():
a
=
[
1
,
2
]
b
=
[
3
,
4
]
assert
interleave
(
a
,
b
)
==
[
1
,
3
,
2
,
4
]
c
=
[
5
,
6
]
assert
interleave
(
a
,
b
,
c
)
==
[
1
,
3
,
5
,
2
,
4
,
6
]
def
test_downsample
():
a
=
list
(
range
(
12
))
assert
downsample
(
a
,
6
)
==
[
0
,
6
]
assert
downsample
(
a
,
6
,
3
)
==
[
3
,
9
]
assert
downsample
(
a
,
4
)
==
[
0
,
4
,
8
]
assert
downsample
(
a
,
3
,
1
)
==
[
1
,
4
,
7
,
10
]
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