Skip to content

Commit

Permalink
♻️ Use bit_length
Browse files Browse the repository at this point in the history
Co-authored-by: thierry-martinez <[email protected]>
  • Loading branch information
EarlMilktea and thierry-martinez committed Sep 19, 2024
1 parent a72d682 commit addf32f
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions graphix/channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from __future__ import annotations

import copy
import itertools
import typing
from typing import TYPE_CHECKING, SupportsIndex, TypeVar

Expand All @@ -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.")

Check warning on line 21 in graphix/channels.py

View check run for this annotation

Codecov / codecov/patch

graphix/channels.py#L21

Added line #L21 was not covered by tests
return (n - 1).bit_length()


# MEMO: Too much?
Expand Down

0 comments on commit addf32f

Please sign in to comment.