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.

48 lignes
1.3KB

  1. // Array access macros.
  2. #define SM(x0, x1) (*(npy_complex128*)((PyArray_DATA(submatrix) + \
  3. (x0) * PyArray_STRIDES(submatrix)[0] + \
  4. (x1) * PyArray_STRIDES(submatrix)[1])))
  5. #define SM_shape(x0) (int) PyArray_DIM(submatrix, x0)
  6. // Complex numbers
  7. static const npy_complex128 complex_one = {.real=1, .imag=0};
  8. static const npy_complex128 complex_zero = {.real=0, .imag=0};
  9. // Add two numbers
  10. npy_complex128 complex_add(npy_complex128 a, npy_complex128 b) {
  11. npy_complex128 x;
  12. x.real = a.real+b.real;
  13. x.imag = a.imag+b.real;
  14. return x;
  15. }
  16. // Product of two numbers
  17. npy_complex128 complex_prod(npy_complex128 a, npy_complex128 b) {
  18. npy_complex128 x;
  19. x.real = a.real*b.real - a.imag*b.imag;
  20. x.imag = a.imag*b.real + a.real*b.imag;
  21. return x;
  22. }
  23. // Product of complex and float
  24. npy_complex128 complex_float_prod(npy_complex128 a, float b) {
  25. npy_complex128 x;
  26. x.real = a.real*b;
  27. x.imag = a.imag*b;
  28. return x;
  29. }
  30. // Increment a number
  31. void complex_inc(npy_complex128 *a, npy_complex128 b) {
  32. a->real += b.real;
  33. a->imag += b.imag;
  34. }
  35. // Multipy a number by another one
  36. void complex_multiply(npy_complex128 *a, npy_complex128 b) {
  37. double c = a->real;
  38. a->real = a->real*b.real-a->imag*b.imag;
  39. a->imag = c*b.imag+a->imag*b.real;
  40. }