mirror of
https://gitlab.science.ru.nl/mthesis-edeboone/m-thesis-introduction.git
synced 2024-12-22 11:33:32 +01:00
Simu: digitizer repacks partial callable
This commit is contained in:
parent
6e059a5db6
commit
10d91519bf
1 changed files with 17 additions and 3 deletions
|
@ -1,5 +1,5 @@
|
|||
import numpy as np
|
||||
from functools import wraps
|
||||
from functools import wraps, partial
|
||||
|
||||
from . import sampling as smp
|
||||
from .sampler import Sampler
|
||||
|
@ -32,15 +32,29 @@ class Digitizer(Sampler):
|
|||
"""
|
||||
|
||||
if callable(signal):
|
||||
# if signal is already a partial,
|
||||
# try to rebuild it after setting the wrapper
|
||||
if isinstance(signal, partial):
|
||||
rebuild_partial = True
|
||||
p_args = signal.args
|
||||
p_kwargs = signal.keywords
|
||||
signal = signal.func
|
||||
else:
|
||||
rebuild_partial = False
|
||||
|
||||
@wraps(signal)
|
||||
def func(*args, **kwargs):
|
||||
def wrapper(*args, **kwargs):
|
||||
return smp.quantise(
|
||||
self.sample(signal(*args, **kwargs), signal_sample_frequency),
|
||||
self.resolution,
|
||||
self.bias
|
||||
)
|
||||
|
||||
return func
|
||||
# rebuild the partial if applicable
|
||||
if rebuild_partial:
|
||||
wrapper = partial(wrapper, *p_args, **p_kwargs)
|
||||
|
||||
return wrapper
|
||||
|
||||
else:
|
||||
signal = np.asarray(signal)
|
||||
|
|
Loading…
Reference in a new issue