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.

test_permanent.py 745B

il y a 4 ans
123456789101112131415161718192021222324252627
  1. import numpy as np
  2. from permanent.permanent import permanent
  3. import pytest
  4. def test_permanent():
  5. """ Test that basic functions work right """
  6. m = np.eye(10, dtype=complex)
  7. assert permanent(m) == 1
  8. m = np.zeros((10, 10), dtype=complex)
  9. assert permanent(m) == 0
  10. def test_floaty():
  11. """ More tests using a precomputed permanent """
  12. np.random.seed(1234)
  13. m = np.random.uniform(0, 1, 16) + 1j * np.random.uniform(0, 1, 16)
  14. m = m.reshape(4, 4)
  15. p = permanent(m)
  16. assert np.allclose(p, -8.766131870776363 + 1.072095650303524j)
  17. def test_error():
  18. """ Should raise a TypeError as we are using the wrong dtype """
  19. with pytest.raises(TypeError):
  20. m = np.eye(10, dtype=float)
  21. permanent(m)