From 1d966f3fa9b290c51b9770893dac9c75d141a796 Mon Sep 17 00:00:00 2001 From: "Kevin J. Sung" Date: Fri, 12 Jul 2024 06:16:10 -0400 Subject: [PATCH] use bit arithmetic to convert int to bitarray --- python/ffsim/states/bitstring.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/python/ffsim/states/bitstring.py b/python/ffsim/states/bitstring.py index a4205f253..ad55a31e1 100644 --- a/python/ffsim/states/bitstring.py +++ b/python/ffsim/states/bitstring.py @@ -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)