from IST import * I = imread('./lenna.jpg') sample = zeros_like(I) for i in arange(3): x, ys = ISTreal(I[:,:,i], its=100, p=0.5) # takes around 20 minutes on this machine I[:,:,i] = idwt2_full(x) sample[:,:,i] = ys figure(figsize=(14,14)) subplot(121) imshow(sample) axis('off') title('The sampled image') subplot(122) imshow(I) axis('off') title('The reconstructed image') show() %%capture string import ISTpython as ISTp #%timeit ISTp.IST() # it takes a long time for this to finish #print string.stdout #python = float(string.stdout.split()[-4]) string = '1 loops, best of 3: 283 s per loop' print string python = float(string.split()[-4]) %%capture string import IST as ISTnumpy %timeit ISTnumpy.IST() print string.stdout numpy = float(string.stdout.split()[-4]) %%capture string import ISTnumba %timeit ISTnumba.IST() print string.stdout numba = float(string.stdout.split()[-4]) string = !matlab -nodisplay -nosplash -r "run IST.m; exit" string = string[-1] print string matlab = float(string.split()[-2]) !gcc IST.c -o IST.o string = !time ./IST.o c = float(string[1].split()[1][2:-1]) print "Total time in seconds: ", c !gcc -O2 IST.c -o IST_O2.o string = !time ./IST.o c_O2 = float(string[1].split()[1][2:-1]) print "Total time in seconds: ", c_O2 !gcc -O3 IST.c -o IST_O3.o string = !time ./IST_O3.o c_O3 = float(string[1].split()[1][2:-1]) print "Total time in seconds: ", c_O3 !llvm-gcc -O3 IST.c -o IST_llvm.o string = !time ./IST_llvm.o c_llvm = float(string[1].split()[1][2:-1]) print "Total time in seconds: ", c_llvm !mpicc -O3 ISt.c -o ISTparallel.o string = !time ./ISTparallel.o mpicc = float(string[1].split()[1][2:-1]) print "Total time in seconds: ", mpicc from pylab import * labels = ['python', 'numpy', 'numba', \ 'matlab', 'gcc', 'gcc --O2', \ 'gcc --O3', 'llvm --O3'] timings = [python, numpy, numba, matlab, c, c_O2, c_O3, c_llvm] x = np.arange(len(labels)) # plotting from slowest to fastest i = argsort(timings) timings = sort(timings)[::-1] labels = asarray(labels) labels = labels[i][::-1] fastest = timings[-1] figure(figsize=(10,10)) matplotlib.rcParams.update({'font.size': 15}) ax = plt.axes(xticks=x, yscale='log') ax.bar(x - 0.3, timings, width=0.6, alpha=0.4, bottom=1E-6) ax.grid() ax.set_xlim(-0.5, len(labels) - 0.5) ax.set_ylim(1E-1, python*1.3) ax.xaxis.set_major_formatter(plt.FuncFormatter(lambda i, loc: labels[int(i)])) ax.set_ylabel('\\textrm{time (s)}') ax.set_title("\\textrm{Iterative Soft Thresholding}") show() labels = ['numpy', 'numba', 'matlab'] timings = [ numpy, numba, matlab] x = np.arange(len(labels)) # plotting from max to min times i = argsort(timings) timings = sort(timings)[::-1] labels = asarray(labels) labels = labels[i][::-1] ax = plt.axes(xticks=x)#, yscale='log') ax.bar(x - 0.3, timings, width=0.6, alpha=0.4, bottom=1E-6) ax.grid() ax.set_xlim(-0.5, len(labels) - 0.5) ax.set_ylim(0, 1.05*max(timings)) ax.xaxis.set_major_formatter(plt.FuncFormatter(lambda i, loc: labels[int(i)])) ax.set_ylabel('\\textrm{time (s)}') ax.set_title("\\textrm{Iterative Soft Thresholding}") show() print "C comparisions:" print "NumPy / C :", numpy / fastest print "Numba / C :", numba / fastest print "Matlab / C :", matlab / fastest print "\nThe comparision that we care about, NumPy and Matlab:" print "Matlab / NumPy: ", matlab / numpy print "Matlab / Numba: " , matlab / numba