Skip to content

Commit

Permalink
removes unnecesary statements (#329)
Browse files Browse the repository at this point in the history
* removes unnecesary statements

* Adds missing term

* Updates CHANGELOG

Co-authored-by: Nicolas Quesada <nquesada@pop-os.localdomain>
  • Loading branch information
nquesada and Nicolas Quesada authored Feb 9, 2022
1 parent 2e32e46 commit 7f56333
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
4 changes: 3 additions & 1 deletion .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

* Recursive Torontonian added for faster computation based on paper ["Polynomial speedup in Torontonian calculation by a scalable recursive algorithm" by Ágoston Kaposi, Zoltán Kolarovszki, Tamás Kozsik, Zoltán Zimborás, and Péter Rakyta](https://arxiv.org/pdf/2109.04528.pdf). [#321](https://github.com/XanaduAI/thewalrus/pull/321)

* Hafnians of odd-sized matrices are calculated roughly twice as fast. [#329](https://github.com/XanaduAI/thewalrus/pull/329)

### Bug fixes

* Permanent algorithms handle 0x0 cases correctly. [#320](https://github.com/XanaduAI/thewalrus/pull/320)
Expand All @@ -23,7 +25,7 @@

This release contains contributions from (in alphabetical order):

Jake Bulmer, Gregory Morse
Jake Bulmer, Gregory Morse, Nicolas Quesada

---

Expand Down
9 changes: 5 additions & 4 deletions thewalrus/_hafnian.py
Original file line number Diff line number Diff line change
Expand Up @@ -778,17 +778,18 @@ def hafnian(
return np.prod(np.diag(A))
return 0

if matshape[0] % 2 != 0 and loop:
A = np.pad(A, pad_width=((0, 1), (0, 1)), mode="constant")
A[-1, -1] = 1.0

matshape = A.shape

if matshape[0] == 2:
if loop:
return A[0, 1] + A[0, 0] * A[1, 1]
return A[0][1]

if matshape[0] == 3 and loop:
return (
A[0, 0] * A[1, 2] + A[1, 1] * A[0, 2] + A[2, 2] * A[0, 1] + A[0, 0] * A[1, 1] * A[2, 2]
)

if matshape[0] == 4:
if loop:
result = (
Expand Down

0 comments on commit 7f56333

Please sign in to comment.