Python C extension to compute the permanent.
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

28 Zeilen
745B

  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)