Skip to content

Commit

Permalink
Merge pull request #26 from RaphaelRobidas/master
Browse files Browse the repository at this point in the history
Increased the speed of _transition_matrix_dense twofold
  • Loading branch information
sametz committed Dec 8, 2023
2 parents b4d4db0 + ec53688 commit 681749f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ jobs:
name: dist
path: dist # unmangle to `./dist` to actually publish

- uses: pypa/gh-action-pypi-publish@v1.5.0
- uses: pypa/gh-action-pypi-publish@v1.8.5
with:
user: __token__
password: ${{ secrets.PYPI_PASSWORD }}
2 changes: 1 addition & 1 deletion .github/workflows/test_pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ jobs:
name: dist
path: dist # unmangle to `./dist` to actually publish

- uses: pypa/gh-action-pypi-publish@v1.5.0
- uses: pypa/gh-action-pypi-publish@v1.8.5
with:
user: __token__
password: ${{ secrets.TEST_PYPI_PASSWORD }}
Expand Down
7 changes: 6 additions & 1 deletion src/nmrsim/qm.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,12 @@ def _transition_matrix_dense(nspins):
T = np.zeros((n, n))
for i in range(n - 1):
for j in range(i + 1, n):
if bin(i ^ j).count("1") == 1:
m = i ^ j
# Check if m is a power of two:
# If m is a power of two, it will look like 100[...]00 in binary
# m-1 will look like 011[...]11 in binary.
# Using a binary and, we should then get 0.
if m > 0 and m & (m-1) == 0:
T[i, j] = 1
T += T.T
return T
Expand Down

0 comments on commit 681749f

Please sign in to comment.