def compareCholeskyCustomVSNumpy(): maxSize = 500 nbOfPoints = 200 nbValuesForAverage = 2 x, yCustom, yNumpy = [], [], [] for size in [round(i) for i in numpy.linspace(5, maxSize, nbOfPoints)]: # Computes matrix density x.append(size) # Computes average execution times on nbValuesForAverage calls # on different matrix customTime, numpyTime = 0, 0 for j in range(nbValuesForAverage): M = matgen.symmetricPositiveDefinite(size) wrapped1 = wrapper(cholesky.completeCholesky, M) customTime += timeit.timeit(wrapped1, number=1) wrapped2 = wrapper(numpy.linalg.cholesky, M) numpyTime += timeit.timeit(wrapped2, number=1) yCustom.append(customTime/nbValuesForAverage) yNumpy.append(numpyTime/nbValuesForAverage) p1 = plt.plot(x, yCustom, 'b', marker='o') p2 = plt.plot(x, yNumpy, 'g', marker='o') plt.title("Average execution time for the Cholesky factorization (custom and Numpy's) in function of size\n") plt.legend(["New custom Cholesky factorization", "Numpy Cholesky factorization"], loc=2) plt.ylabel("Execution time (s)") plt.xlabel("size") plt.show()
def test_cholesky(): random.seed() for i in range(10): print(".", end="", flush= True) size = random.randint(100, 200) M = matgen.symmetricPositiveDefinite(size) T = cholesky.completeCholesky(M) if not numpy.allclose(M, numpy.dot(T, T.transpose())): return False return True