From: Jérôme Benoit Date: Sun, 31 Aug 2025 11:15:31 +0000 (+0200) Subject: perf(qav3): add integer fastpath to round_to_step() X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=a23e3f170f2119b3651a0e25496e6c060b44239e;p=freqai-strategies.git perf(qav3): add integer fastpath to round_to_step() Signed-off-by: Jérôme Benoit --- diff --git a/quickadapter/user_data/strategies/Utils.py b/quickadapter/user_data/strategies/Utils.py index b8e64c0..840b323 100644 --- a/quickadapter/user_data/strategies/Utils.py +++ b/quickadapter/user_data/strategies/Utils.py @@ -1015,10 +1015,18 @@ def round_to_step(value: float | int, step: int) -> int: """ if not isinstance(value, (int, float)): raise ValueError("value must be an integer or float") - if not np.isfinite(value): - raise ValueError("value must be finite") if not isinstance(step, int) or step <= 0: raise ValueError("step must be a positive integer") + if isinstance(value, (int, np.integer)): + q, r = divmod(value, step) + twice_r = r * 2 + if twice_r < step: + return q * step + if twice_r > step: + return (q + 1) * step + return int(round(value / step) * step) + if not np.isfinite(value): + raise ValueError("value must be finite") return int(round(float(value) / step) * step)