Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added C++ permanent source codes and removed Fortran ones #20

Merged
merged 8 commits into from
Jul 1, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion hafnian/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,13 @@
haf_rpt_real,
haf_rpt_complex,
reduction,
perm_complex,
perm_real,
josh146 marked this conversation as resolved.
Show resolved Hide resolved
)

from ._torontonian import tor

from ._permanent import perm, perm_real, perm_complex, permanent_repeated
from ._permanent import perm, permanent_repeated

__all__ = [
"hafnian",
Expand Down
2 changes: 1 addition & 1 deletion hafnian/_hafnian.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"""
import numpy as np

from .lib.libhaf import haf_complex, haf_real, haf_int, haf_rpt_real, haf_rpt_complex
from .lib.libhaf import haf_complex, haf_real, haf_int, haf_rpt_real, haf_rpt_complex, perm_complex, perm_real
josh146 marked this conversation as resolved.
Show resolved Hide resolved


def input_validation(A, tol=1e-12):
Expand Down
17 changes: 9 additions & 8 deletions hafnian/_permanent.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@
"""
import numpy as np

from .lib.libperm import perm as libperm
from ._hafnian import hafnian_repeated
from .lib.libhaf import perm_complex, perm_real

perm_real = libperm.re
perm_complex = libperm.comp
from ._hafnian import hafnian_repeated


def perm(A):
def perm(A, quad=True, fsum=False):
"""Returns the permanent of a matrix via the
`Ryser formula <https://en.wikipedia.org/wiki/Computing_the_permanent#Ryser_formula>`_.

Expand All @@ -32,6 +30,9 @@ def perm(A):

Args:
A (array): a square array.
quad (bool): quad (bool): If ``True``, the input matrix is cast to a ``long double``
josh146 marked this conversation as resolved.
Show resolved Hide resolved
matrix internally for a quadruple precision hafnian computation.
fsum (bool): If ``True``, ``fsum`` method is used for summation.
josh146 marked this conversation as resolved.
Show resolved Hide resolved

Returns:
np.float64 or np.complex128: the permanent of matrix A.
Expand Down Expand Up @@ -63,10 +64,10 @@ def perm(A):

if A.dtype == np.complex:
if np.any(np.iscomplex(A)):
return perm_complex(A)
return perm_real(np.float64(A.real))
return perm_complex(A, quad=quad)
return perm_real(np.float64(A.real), quad=quad, fsum=fsum)

return perm_real(A)
return perm_real(A, quad=quad, fsum=fsum)


def permanent_repeated(A, rpt):
Expand Down
Loading