From addf32f2935c756bb5cec01af905a29e6011dd42 Mon Sep 17 00:00:00 2001 From: SS <66886825+EarlMilktea@users.noreply.github.com> Date: Thu, 19 Sep 2024 23:41:47 +0900 Subject: [PATCH] :recycle: Use bit_length Co-authored-by: thierry-martinez --- graphix/channels.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/graphix/channels.py b/graphix/channels.py index eed024c5..83d4cde2 100644 --- a/graphix/channels.py +++ b/graphix/channels.py @@ -3,7 +3,6 @@ from __future__ import annotations import copy -import itertools import typing from typing import TYPE_CHECKING, SupportsIndex, TypeVar @@ -18,12 +17,9 @@ def _ilog2(n: int) -> int: - if n < 0: - raise ValueError("n must be non-negative.") - for p in itertools.count(): - if n <= 2**p: - return p - raise RuntimeError("Unreachable.") + if n <= 0: + raise ValueError("n must be positive.") + return (n - 1).bit_length() # MEMO: Too much?