pfapack: Efficient numerical computation of the Pfaffian for dense and banded skew-symmetric matrices
Code and algorithms are taken from arXiv:1102.3440 which is authored by Michael Wimmer.
Install
pip install pfapack
Or using conda:
conda install -c conda-forge pfapack
Usage
from pfapack import pfaffian as pf
import numpy.random
A = numpy.random.rand(100, 100)
A = A - A.T
pfa1 = pf.pfaffian(A)
pfa2 = pf.pfaffian(A, method="H")
pfa3 = pf.pfaffian_schur(A)
print(pfa1, pfa2, pfa3)
The package includes optimized C/FORTRAN implementations that can be used for better performance:
from pfapack.ctypes import pfaffian as cpf
pfa1 = cpf(A)
pfa2 = cpf(A, method="H")
print(pfa1, pfa2)
Note
Building from source on Windows (only needed if no wheel is available for your platform) requires MSYS2 with the MinGW64 toolchain (mingw-w64-x86_64-gcc-fortran, mingw-w64-x86_64-openblas, and mingw-w64-x86_64-pkgconf).
Citing
If you have used pfapack in your research, please cite it using the following bib entry:
@article{wimmer2012algorithm,
title={Efficient numerical computation of the pfaffian for dense and banded skew-symmetric matrices},
author={Michael Wimmer},
journal={ACM Transactions on Mathematical Software (TOMS)},
volume={38},
number={4},
pages={1--17},
year={2012},
publisher={ACM New York, NY, USA}
}
License
MIT License
Contributions
Bas Nijholt