Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return result
return A[0, 1] * A[2, 3] + A[0, 2] * A[1, 3] + A[0, 3] * A[1, 2]
if approx:
if np.any(np.iscomplex(A)):
raise ValueError("Input matrix must be real")
if np.any(A < 0):
raise ValueError("Input matrix must not have negative entries")
if A.dtype == np.complex:
# array data is complex type
if np.any(np.iscomplex(A)):
# array values contain non-zero imaginary parts
return haf_complex(A, loop=loop, recursive=recursive, quad=quad)
# all array values have zero imaginary parts
return haf_real(np.float64(A.real), loop=loop, recursive=recursive, quad=quad)
if np.issubdtype(A.dtype, np.integer) and not loop:
# array data is an integer type, and the user is not
# requesting the loop hafnian
return haf_int(np.int64(A))
if np.issubdtype(A.dtype, np.integer) and loop:
# array data is an integer type, and the user is
# requesting the loop hafnian. Currently no
# integer function for loop hafnians, have to instead
# convert to float and use haf_real
A = np.float64(A)
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)
end = time.time()
print('Mean time taken (complex): ', (end - start)/reps)
# print('\t Haf result: ', res)
times[ind, 0] = (end - start)/reps
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
r = (anm1/a0)**(1./(n-1))
nreps = [(int)(a0*(r**((i)))) for i in range(n)]
times = np.empty([n, 5])
for ind, reps in enumerate(nreps):
size = 2*(ind+1)
print('\nTesting matrix size {}, with {} reps...'.format(size,reps))
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)
end = time.time()
print('Mean time taken (complex): ', (end - start)/reps)
# print('\t Haf result: ', res)
times[ind, 0] = (end - start)/reps
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