Copyright (C) 2020 Andreas Kloeckner
import numpy as np
import scipy.linalg as spla
import scipy as sp
import matplotlib.pyplot as pt
from time import time
np.alterdot()
n_values = (10**np.linspace(1, 3.25, 15)).astype(np.int32)
n_values
array([ 10, 14, 20, 30, 43, 63, 92, 133, 193, 279, 404, 585, 848, 1228, 1778], dtype=int32)
def mat_mul(A):
return A.dot(A)
for name, f in [
("mat_mul", mat_mul),
("lu", spla.lu_factor),
]:
times = []
print("----->", name)
for n in n_values:
print(n)
A = np.random.randn(n, n)
start_time = time()
f(A)
times.append(time() - start_time)
pt.plot(n_values, times, label=name)
pt.grid()
pt.legend(loc="best")
pt.xlabel("Matrix size $n$")
pt.ylabel("Wall time [s]")
-----> mat_mul 10 14 20 30 43 63 92 133 193 279 404 585 848 1228 1778 -----> lu 10 14 20 30 43 63 92 133 193 279 404 585 848 1228 1778
<matplotlib.text.Text at 0x7fe3ac7e7a90>