From 9088f56831e096738be5e41737eb0ed2ddd72774 Mon Sep 17 00:00:00 2001 From: Thomas Fillon Date: Thu, 19 Jun 2014 15:51:25 +0200 Subject: [PATCH] feat(analyzer/utils.py): add a function to evaluate the next power of two --- timeside/analyzer/utils.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/timeside/analyzer/utils.py b/timeside/analyzer/utils.py index 497126d..b8ad23c 100644 --- a/timeside/analyzer/utils.py +++ b/timeside/analyzer/utils.py @@ -223,3 +223,15 @@ def entropy(serie, nbins=10, base=np.exp(1), approach='unbiased'): nbias = nbias / np.log(base) sigma = sigma / np.log(base) return estimate + + +def nextpow2(value): + """Compute the nearest power of two greater or equal to the input value""" + if value >= 1: + return 2**np.ceil(np.log2(value)).astype(int) + elif value > 0: + return 1 + elif value == 0: + return 0 + else: + raise ValueError('Value must be positive') -- 2.39.5