Simu: digitizer repacks partial callable

This commit is contained in:
Eric Teunis de Boone 2022-03-24 18:01:20 +01:00
parent 6e059a5db6
commit 10d91519bf

View file

@ -1,5 +1,5 @@
import numpy as np import numpy as np
from functools import wraps from functools import wraps, partial
from . import sampling as smp from . import sampling as smp
from .sampler import Sampler from .sampler import Sampler
@ -32,15 +32,29 @@ class Digitizer(Sampler):
""" """
if callable(signal): 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) @wraps(signal)
def func(*args, **kwargs): def wrapper(*args, **kwargs):
return smp.quantise( return smp.quantise(
self.sample(signal(*args, **kwargs), signal_sample_frequency), self.sample(signal(*args, **kwargs), signal_sample_frequency),
self.resolution, self.resolution,
self.bias self.bias
) )
return func # rebuild the partial if applicable
if rebuild_partial:
wrapper = partial(wrapper, *p_args, **p_kwargs)
return wrapper
else: else:
signal = np.asarray(signal) signal = np.asarray(signal)