MCPcopy Create free account
hub / github.com/Meshcapade/difflocks / round_to_power_of_two

Function round_to_power_of_two

k_diffusion/config.py:11–20  ·  view source on GitHub ↗
(x, tol)

Source from the content-addressed store, hash-verified

9
10
11def round_to_power_of_two(x, tol):
12 approxs = []
13 for i in range(math.ceil(math.log2(x))):
14 mult = 2**i
15 approxs.append(round(x / mult) * mult)
16 for approx in reversed(approxs):
17 error = abs((approx - x) / x)
18 if error <= tol:
19 return approx
20 return approxs[0]
21
22
23def load_config(path_or_dict):

Callers 1

load_configFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected