in tutorials/LinearAlgebra/testing.py [0:0]
def is_matrix_unitary_test(fun):
for testId in range(12):
a = []
# The first two tests are edge cases, after that unitary and non-unitary matrices alternate
if testId < 2:
a = edge_unitary_matrices[testId]
elif testId % 2 == 0:
a = gen_unitary_matrix()
else:
n = r.randint(1,5)
a = gen_complex_matrix(n,n)
expected = is_matrix_unitary_ref(a)
actual = fun(a)
if actual == None:
print("Your function must return a value!")
return
if actual != expected:
print("Unexpected result:\n"
+ gen_matrix_message([a],
["Matrix ", (" is " if expected else " is not ")
+ "unitary, but misidentified as "
+ ("unitary" if actual else "not unitary")]))
return
print("Success!")