def test_int_wrapper_loop(self): """Check hafnian(A, loop=True)=haf_real(A, loop=True) for a random integer matrix. """ A = np.int64(np.ones([6, 6])) haf = hafnian(A, loop=True) expected = haf_real(np.float64(A), loop=True) assert np.allclose(haf, expected)
def test_real_wrapper(self): """Check hafnian(A)=haf_real(A) for a random real matrix. """ A = np.random.random([6, 6]) A += A.T haf = hafnian(A) expected = haf_real(A) assert np.allclose(haf, expected) haf = hafnian(A, loop=True) expected = haf_real(A, loop=True) assert np.allclose(haf, expected) A = np.random.random([6, 6]) A += A.T A = np.array(A, dtype=np.complex128) haf = hafnian(A) expected = haf_real(np.float64(A.real)) assert np.allclose(haf, expected)
start = time.time() for i in range(reps): matrix = np.random.randint(low=-1, high=2, size=[size, size]) A = np.complex128(np.clip(matrix + matrix.T, -1, 1)) res = haf_complex(A, recursive=True) end = time.time() print("Mean time taken (complex, recursive): ", (end - start) / reps) # print('\t Haf result: ', res) times[ind, 1] = (end - start) / reps start = time.time() for i in range(reps): matrix = np.random.randint(low=-1, high=2, size=[size, size]) A = np.float64(np.clip(matrix + matrix.T, -1, 1)) res = haf_real(A) end = time.time() print("Mean time taken (real): ", (end - start) / reps) # print('\t Haf result: ', res) times[ind, 2] = (end - start) / reps start = time.time() for i in range(reps): matrix = np.random.randint(low=-1, high=2, size=[size, size]) A = np.float64(np.clip(matrix + matrix.T, -1, 1)) res = haf_real(A, recursive=True) end = time.time() print("Mean time taken (real, recursive): ", (end - start) / reps) # print('\t Haf result: ', res)