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
b2e57330
Commit
b2e57330
authored
1 year ago
by
Oscar Gustafsson
Browse files
Options
Downloads
Patches
Plain Diff
Add decompose and upsample util functions
parent
6e489f73
No related branches found
No related tags found
1 merge request
!285
Add decompose and upsample util functions
Pipeline
#93970
passed
1 year ago
Stage: test
Stage: deploy
Changes
2
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
b_asic/utils.py
+83
-10
83 additions, 10 deletions
b_asic/utils.py
test/test_utils.py
+16
-1
16 additions, 1 deletion
test/test_utils.py
with
99 additions
and
11 deletions
b_asic/utils.py
+
83
−
10
View file @
b2e57330
"""
B-ASIC Utils.
"""
"""
B-ASIC Util
itie
s.
"""
from
typing
import
List
,
Sequence
from
typing
import
List
,
Sequence
...
@@ -9,17 +9,22 @@ def interleave(*args) -> List[Num]:
...
@@ -9,17 +9,22 @@ def interleave(*args) -> List[Num]:
"""
"""
Interleave a number of arrays.
Interleave a number of arrays.
For the input ``interleave([1, 2], [3, 4])``, return ``[1, 3, 2, 4]``.
Parameters
Parameters
----------
----------
*args : a number of arrays
*args : a number of arrays
Arrays to interleave. Must be of the same length.
Arrays to interleave. Must be of the same length.
Returns
Examples
-------
--------
>>>
from
b_asic.utils
import
interleave
...
...
a
=
[
1
,
2
]
...
b
=
[
3
,
4
]
...
interleave
(
a
,
b
)
[
1
,
3
,
2
,
4
]
>>>
c
=
[
-
1
,
0
]
...
interleave
(
a
,
b
,
c
)
[
1
,
3
,
-
1
,
2
,
4
,
0
]
"""
"""
return
[
val
for
tup
in
zip
(
*
args
)
for
val
in
tup
]
return
[
val
for
tup
in
zip
(
*
args
)
for
val
in
tup
]
...
@@ -39,9 +44,77 @@ def downsample(a: Sequence[Num], factor: int, phase: int = 0) -> List[Num]:
...
@@ -39,9 +44,77 @@ def downsample(a: Sequence[Num], factor: int, phase: int = 0) -> List[Num]:
phase : int, default: 0
phase : int, default: 0
The phase of the downsampling.
The phase of the downsampling.
Returns
Examples
-------
--------
>>>
from
b_asic.utils
import
downsample
...
...
a
=
list
(
range
(
6
))
...
downsample
(
a
,
3
)
[
0
,
3
]
>>>
downsample
(
a
,
3
,
1
)
[
1
,
4
]
"""
return
a
[
phase
::
factor
]
def
upsample
(
a
:
Sequence
[
Num
],
factor
:
int
,
phase
:
int
=
0
)
->
List
[
Num
]:
"""
"""
return
a
[
phase
::
factor
]
Upsample a sequence with an integer factor.
Insert *factor* - 1 zeros between every value, starting with *phase* zeros.
Parameters
----------
a : array
The array to upsample.
factor : int
The factor to upsample with.
phase : int, default: 0
The phase of the upsampling.
Examples
--------
>>>
from
b_asic.utils
import
upsample
...
...
a
=
list
(
range
(
1
,
4
))
...
upsample
(
a
,
3
)
[
1
,
0
,
0
,
2
,
0
,
0
,
3
,
0
,
0
]
>>>
upsample
(
a
,
3
,
1
)
[
0
,
1
,
0
,
0
,
2
,
0
,
0
,
3
,
0
]
"""
length
=
len
(
a
)
zeros
=
[
0
]
*
length
args
=
[]
for
_
in
range
(
phase
):
args
.
append
(
zeros
)
args
.
append
(
a
)
for
_
in
range
(
factor
-
phase
-
1
):
args
.
append
(
zeros
)
return
interleave
(
*
args
)
def
decompose
(
a
:
Sequence
[
Num
],
factor
:
int
)
->
List
[
List
[
Num
]]:
"""
Polyphase decompose signal *a* into *factor* parts.
Return *factor* lists, each with every *factor* value.
Parameters
----------
a : array
The array to polyphase decompose.
factor : int
The number of polyphase components with.
Examples
--------
>>>
from
b_asic.utils
import
decompose
...
...
a
=
list
(
range
(
6
))
...
decompose
(
a
,
2
)
[[
0
,
2
,
4
],
[
1
,
3
,
5
]]
>>>
decompose
(
a
,
3
)
[[
0
,
3
],
[
1
,
4
],
[
2
,
5
]]
"""
return
[
downsample
(
a
,
factor
,
phase
)
for
phase
in
range
(
factor
)]
This diff is collapsed.
Click to expand it.
test/test_utils.py
+
16
−
1
View file @
b2e57330
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
B-ASIC test suite for the utils module.
B-ASIC test suite for the utils module.
"""
"""
from
b_asic.utils
import
downsample
,
interleave
from
b_asic.utils
import
decompose
,
downsample
,
interleave
,
upsample
def
test_interleave
():
def
test_interleave
():
...
@@ -20,3 +20,18 @@ def test_downsample():
...
@@ -20,3 +20,18 @@ def test_downsample():
assert
downsample
(
a
,
6
,
3
)
==
[
3
,
9
]
assert
downsample
(
a
,
6
,
3
)
==
[
3
,
9
]
assert
downsample
(
a
,
4
)
==
[
0
,
4
,
8
]
assert
downsample
(
a
,
4
)
==
[
0
,
4
,
8
]
assert
downsample
(
a
,
3
,
1
)
==
[
1
,
4
,
7
,
10
]
assert
downsample
(
a
,
3
,
1
)
==
[
1
,
4
,
7
,
10
]
def
test_upsample
():
a
=
list
(
range
(
3
))
assert
upsample
(
a
,
2
)
==
[
0
,
0
,
1
,
0
,
2
,
0
]
assert
upsample
(
a
,
2
,
1
)
==
[
0
,
0
,
0
,
1
,
0
,
2
]
a
=
list
(
range
(
1
,
4
))
assert
upsample
(
a
,
3
)
==
[
1
,
0
,
0
,
2
,
0
,
0
,
3
,
0
,
0
]
assert
upsample
(
a
,
3
,
1
)
==
[
0
,
1
,
0
,
0
,
2
,
0
,
0
,
3
,
0
]
def
test_decompose
():
a
=
list
(
range
(
6
))
assert
decompose
(
a
,
2
)
==
[[
0
,
2
,
4
],
[
1
,
3
,
5
]]
assert
decompose
(
a
,
3
)
==
[[
0
,
3
],
[
1
,
4
],
[
2
,
5
]]
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