Function libwalrus::hafnian_rpt_quad(std::vector<std::complex<double>>&, std::vector<int>&)

Function Documentation

std::complex<double> libwalrus::hafnian_rpt_quad(std::vector<std::complex<double>> &mat, std::vector<int> &rpt)

Returns the hafnian of a matrix using the algorithm described in From moments of sum to moments of product, doi:10.1016/j.jmva.2007.01.013.

Note that this algorithm, while generally slower than others, can be significantly more efficient in the cases where the matrix has repeated rows and columns.

This is a wrapper around the templated function libwalrus::hafnian_rpt for Python integration. It accepts and returns complex double numeric types, and returns sensible values for empty and non-even matrices.

In addition, this wrapper function automatically casts all matrices to type complex<long double>, allowing for greater precision than supported by Python and NumPy.

Return

hafnian of the input matrix

Parameters
  • mat: a flattened vector of size \(n^2\), representing an \(n\times n\) row-ordered symmetric matrix.

  • rpt: a vector of integers, representing the number of times each row/column in mat is repeated. For example, mat = [1] and rpt = [6] represents a \(6\times 6\) matrix of all ones.