Skip to content
Snippets Groups Projects

Add decompose and upsample util functions

Merged Oscar Gustafsson requested to merge moreutils into master
1 file
+ 15
11
Compare changes
  • Side-by-side
  • Inline
+ 15
11
"""B-ASIC Utils."""
"""B-ASIC Utilities."""
from typing import List, Sequence
@@ -17,12 +17,13 @@ def interleave(*args) -> List[Num]:
Examples
--------
>>> from b_asic.utils import interleave
>>> a = [1, 2]
>>> b = [3, 4]
>>> interleave(a, b)
...
... a = [1, 2]
... b = [3, 4]
... interleave(a, b)
[1, 3, 2, 4]
>>> c = [-1, 0]
>>> interleave(a, b, c)
... interleave(a, b, c)
[1, 3, -1, 2, 4, 0]
"""
return [val for tup in zip(*args) for val in tup]
@@ -46,8 +47,9 @@ def downsample(a: Sequence[Num], factor: int, phase: int = 0) -> List[Num]:
Examples
--------
>>> from b_asic.utils import downsample
>>> a = list(range(6))
>>> downsample(a, 3)
...
... a = list(range(6))
... downsample(a, 3)
[0, 3]
>>> downsample(a, 3, 1)
[1, 4]
@@ -73,8 +75,9 @@ def upsample(a: Sequence[Num], factor: int, phase: int = 0) -> List[Num]:
Examples
--------
>>> from b_asic.utils import upsample
>>> a = list(range(1, 4))
>>> upsample(a, 3)
...
... 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]
@@ -106,8 +109,9 @@ def decompose(a: Sequence[Num], factor: int) -> List[List[Num]]:
Examples
--------
>>> from b_asic.utils import decompose
>>> a = list(range(6))
>>> decompose(a, 2)
...
... a = list(range(6))
... decompose(a, 2)
[[0, 2, 4], [1, 3, 5]]
>>> decompose(a, 3)
[[0, 3], [1, 4], [2, 5]]
Loading