Skip to content

Commit

Permalink
use bit arithmetic to convert int to bitarray
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinsung committed Jul 12, 2024
1 parent d51e103 commit 1d966f3
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion python/ffsim/states/bitstring.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,10 @@ def convert_bitstring_type(
return [f"{string:0{length}b}" for string in strings]

if output_type is BitstringType.BIT_ARRAY:
return np.array([[b == "1" for b in f"{s:0{length}b}"] for s in strings])
return np.array(
[[s >> i & 1 for i in range(length - 1, -1, -1)] for s in strings],
dtype=bool,
)

if input_type is BitstringType.BIT_ARRAY:
strings = cast(np.ndarray, strings)
Expand Down

0 comments on commit 1d966f3

Please sign in to comment.