From 10d91519bf2c5f09105b1aee662886ccdc8eb942 Mon Sep 17 00:00:00 2001 From: Eric Teunis de Boone Date: Thu, 24 Mar 2022 18:01:20 +0100 Subject: [PATCH] Simu: digitizer repacks partial callable --- simulations/lib/sampling/digitizer.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/simulations/lib/sampling/digitizer.py b/simulations/lib/sampling/digitizer.py index e285913..fd65fa2 100644 --- a/simulations/lib/sampling/digitizer.py +++ b/simulations/lib/sampling/digitizer.py @@ -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)