import scipy.io as sio import scipy.linalg as la import scipy.sparse.linalg as sla import numpy as np import matplotlib.pyplot as plt import time #dict = sio.loadmat('MFDLapl_primal.mat') #A = dict['A1'] dict = sio.loadmat('MFDLapl.mat') A = dict['A'] N,M=A.shape nelement = N*M nnz = A.nnz print('Number of elements, A: %e' % nelement) print('Number of non-zeros, A: %e' % nnz) print('Percentage of non-zeros, A: %e%%' % (100*float(nnz)/nelement)) plt.spy(A, markersize=1) plt.show() # Sparse LU, reorder to minimize fill-in start1 = time.time() lu1 = sla.splu(A,permc_spec='COLAMD') end1 = time.time() print('Time elapsed, lu1: %e' % (end1-start1)) print('Number of non-zeros, lu1: %e' % (lu1.L.nnz+lu1.U.nnz)) # Sparse LU, no reordering to minimize fill-in start2 = time.time() lu2 = sla.splu(A,permc_spec='natural') end2 = time.time() print('Time elapsed, lu2: %e' % (end2-start2)) print('Number of non-zeros, lu2: %e' % (lu2.L.nnz+lu2.U.nnz)) # Dense LU, takes a while start3 = time.time() [P,L,U]= la.lu(A.todense()) end3 = time.time() print('Time elapsed, lu3: %e' % (end3-start3)) print('Number of non-zeros, lu3: %e' % (nelement))