def test_rpt_zero(self): """Check 2x2 permanent when rpt is all 0""" A = np.array([[2, 1], [1, 3]]) rpt = [0, 0] res = permanent_repeated(A, rpt) assert res == 1.0
def test_3x3(self, random_matrix): """Check 3x3 permanent""" A = random_matrix(3) p = permanent_repeated(A, [1] * 3) exp = (A[0, 0] * A[1, 1] * A[2, 2] + A[0, 1] * A[1, 2] * A[2, 0] + A[0, 2] * A[1, 0] * A[2, 1] + A[2, 0] * A[1, 1] * A[0, 2] + A[0, 1] * A[1, 0] * A[2, 2] + A[0, 0] * A[1, 2] * A[2, 1]) assert np.allclose(p, exp)
def test_ones(self, n): """Check all ones matrix has perm(J_n)=n!""" A = np.array([[1]]) p = permanent_repeated(A, [n]) assert np.allclose(p, fac(n))
def test_2x2(self, random_matrix): """Check 2x2 permanent""" A = random_matrix(2) p = permanent_repeated(A, [1] * 2) assert np.allclose(p, A[0, 0] * A[1, 1] + A[1, 0] * A[0, 1])