Skip to content

Commit

Permalink
fix numpy array handling in strings to addresses (#333)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinsung authored Oct 17, 2024
1 parent f40e524 commit 6d96a0f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion python/ffsim/states/bitstring.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ def strings_to_addresses(
"""
if not len(strings):
return np.array([])
if isinstance(strings, np.ndarray):
if isinstance(strings, np.ndarray) and strings.ndim == 2:
bitstring_type = BitstringType.BIT_ARRAY
elif isinstance(strings[0], str):
bitstring_type = BitstringType.STRING
Expand Down
24 changes: 13 additions & 11 deletions tests/python/states/bitstring_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,17 +549,19 @@ def test_strings_to_addresses_int():
nelec = (2, 1)
dim = ffsim.dim(norb, nelec)
indices = ffsim.strings_to_addresses(
[
0b001011,
0b010011,
0b100011,
0b001101,
0b010101,
0b100101,
0b001110,
0b010110,
0b100110,
],
np.array(
[
0b001011,
0b010011,
0b100011,
0b001101,
0b010101,
0b100101,
0b001110,
0b010110,
0b100110,
]
),
norb,
nelec,
)
Expand Down

0 comments on commit 6d96a0f

Please sign in to comment.