Skip to content

Commit 6d96a0f

Browse files
authored
fix numpy array handling in strings to addresses (#333)
1 parent f40e524 commit 6d96a0f

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

python/ffsim/states/bitstring.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ def strings_to_addresses(
462462
"""
463463
if not len(strings):
464464
return np.array([])
465-
if isinstance(strings, np.ndarray):
465+
if isinstance(strings, np.ndarray) and strings.ndim == 2:
466466
bitstring_type = BitstringType.BIT_ARRAY
467467
elif isinstance(strings[0], str):
468468
bitstring_type = BitstringType.STRING

tests/python/states/bitstring_test.py

+13-11
Original file line numberDiff line numberDiff line change
@@ -549,17 +549,19 @@ def test_strings_to_addresses_int():
549549
nelec = (2, 1)
550550
dim = ffsim.dim(norb, nelec)
551551
indices = ffsim.strings_to_addresses(
552-
[
553-
0b001011,
554-
0b010011,
555-
0b100011,
556-
0b001101,
557-
0b010101,
558-
0b100101,
559-
0b001110,
560-
0b010110,
561-
0b100110,
562-
],
552+
np.array(
553+
[
554+
0b001011,
555+
0b010011,
556+
0b100011,
557+
0b001101,
558+
0b010101,
559+
0b100101,
560+
0b001110,
561+
0b010110,
562+
0b100110,
563+
]
564+
),
563565
norb,
564566
nelec,
565567
)

0 commit comments

Comments
 (0)