Python C extension to compute the permanent.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
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)