ubuntu2204
#check if function exists1import time2#import multiprocessing3testk=np.linspace(1,5,10)4567assert "make_matrix" in dir(), 'Make sure you define your function and use the specified function name.'891011try:12out = make_matrix(testk)13except TypeError:141516171819raise AssertionError('Your function should take 2 input arguments and ignore eigenvectors.')202122232425else:26pass272829303132testM=make_matrix(testk)33tnb=len(testk)-13435363738394041#test output42assert type(testM)==np.ndarray, 'Your function output should be a 2D numpy array.'434445464748assert np.size(testM)/tnb==tnb, 'Your matrix should have a size of a x a where a is the number of beads (NOT strings!)'495051525354assert testM[tnb-1][tnb-1]==testk[-1]+testk[-2], 'Your matrix values are incorrect.'5556575859tN=36061626364assert np.isclose(testM[tN][tN+1],-testk[tN+1]), 'Your matrix values are incorrect.'6566#check if for loops used67testk=np.linspace(1,100,100)68import timeit69assert timeit.timeit('make_matrix(testk)','from __main__ import make_matrix, testk',number=100000)<8.5, 'Your code is inefficient for large matrices. Try to simplify it by avoiding the use of if statements.'7071727374## CHANGES HERE: check if for loops used75767778798081# check if local variables used82assert not testM==make_matrix(testk*2), 'Do not use global variables - your function should work for any input.'838485868788from IPython.display import clear_output89clear_output(wait=False)90print('************\n Well done! All test passed. You can move to the next part of the task.\n************')9192