next_power_of_two
¶
Helpers for rounding up to a power of two.
next_power_of_two
¶
Return the first power of two greater than or equal to n.
Useful when allocating padded Hilbert-space dimensions or buffer sizes that must be a power of two.
Parameters:
-
n(int) –Non-negative integer.
Returns:
-
int–The smallest power of two that is at least
n. Forn <= 1the -
int–result is
1.
Raises:
-
AssertionError–If
nis not a non-negative integer.
Examples:
from shadowsim.utils.next_power_of_two import next_power_of_two
print(next_power_of_two(5))
print(next_power_of_two(8))