Python C extension to compute the permanent.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

34 lignes
1.0KB

  1. /* Computes the permanent, given a numpy array */
  2. #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
  3. #include <Python.h>
  4. #include <numpy/arrayobject.h>
  5. #include "npy_util.h"
  6. #include "bithacks.h"
  7. #include "permanents.h"
  8. // Forward function declaration
  9. static PyObject *permanent(PyObject *self, PyObject *args);
  10. // Method list
  11. static PyMethodDef methods[] = {
  12. { "permanent", permanent, METH_VARARGS, "Compute the permanent"},
  13. { NULL, NULL, 0, NULL } // Sentinel
  14. };
  15. // Module initialization
  16. PyMODINIT_FUNC initpermanent(void) {
  17. (void) Py_InitModule("permanent", methods);
  18. import_array();
  19. }
  20. // This is a wrapper which chooses the optimal permanent function
  21. static PyObject *permanent(PyObject *self, PyObject *args) {
  22. // Parse the input
  23. PyArrayObject *submatrix;
  24. if (!PyArg_ParseTuple(args, "O!", &PyArray_Type, &submatrix)) {return NULL;}
  25. // Compute the permanent
  26. npy_complex128 p = perm_ryser(submatrix);
  27. return PyComplex_FromDoubles(p.real, p.imag);
  28. }