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.

run-tests.py 1.2KB

il y a 9 ans
il y a 9 ans
il y a 9 ans
il y a 9 ans
il y a 9 ans
123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import os, sys
  2. import numpy as np
  3. import time
  4. from matplotlib import pyplot as plt
  5. from permanent import permanent
  6. import itertools as it
  7. def permanent(a):
  8. """ Slow way to compute the permanent """
  9. r = range(len(a))
  10. return sum([np.prod(a[r, p]) for p in it.permutations(r)])
  11. if __name__ == '__main__':
  12. maxtime=1
  13. dimensions=range(1,11)
  14. for (function, label) in zip((permanent, perm_ryser), ("C", "Python")):
  15. counts=[]
  16. for dimension in dimensions:
  17. print dimension
  18. real=np.random.uniform(-1, 1, dimension*dimension).reshape((dimension, dimension))
  19. imag=np.random.uniform(-1, 1, dimension*dimension).reshape((dimension, dimension))
  20. submatrix=real+1j*imag
  21. t=time.clock()
  22. n=0
  23. while time.clock()-t < maxtime:
  24. for i in range(5):
  25. function(submatrix)
  26. n+=5
  27. counts.append(n)
  28. plt.plot(dimensions, counts, ".-", label=label)
  29. plt.ylabel("Number of permanents per second")
  30. plt.xlabel("Dimension")
  31. plt.xlim(min(dimensions), max(dimensions))
  32. plt.legend()
  33. plt.semilogy()
  34. plt.savefig("out.pdf")