benchmark.py :  » Math » SciPy » scipy » scipy » sparse » linalg » eigen » lobpcg » tests » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Math » SciPy 
SciPy » scipy » scipy » sparse » linalg » eigen » lobpcg » tests » benchmark.py
from scipy import *
from scipy.sparse.linalg import lobpcg
from symeig import symeig
from pylab import plot,show,legend,xlabel,ylabel
set_printoptions(precision=3,linewidth=90)
import time

def test(n):
    x = arange(1,n+1)
    B = diag(1./x)
    y = arange(n-1,0,-1)
    z = arange(2*n-1,0,-2)
    A = diag(z)-diag(y,-1)-diag(y,1)
    return A,B

def as2d( ar ):
    if ar.ndim == 2:
        return ar
    else: # Assume 1!
        aux = nm.array( ar, copy = False )
        aux.shape = (ar.shape[0], 1)
        return aux

def precond(x):
    y= linalg.cho_solve((LorU, lower),x)
    return as2d(y)

m = 10  # Blocksize
N = array(([128,256,512,1024,2048])) # Increasing matrix size

data1=[]
data2=[]

for n in N:
    print '******', n
    A,B = test(n) # Mikota pair
    X = rand(n,m)
    X = linalg.orth(X)

    tt = time.clock()
    (LorU, lower) = linalg.cho_factor(A, lower=0, overwrite_a=0)
    eigs,vecs = lobpcg.lobpcg(X,A,B,operatorT = precond,
                              residualTolerance = 1e-4, maxIterations = 40)
    data1.append(time.clock()-tt)
    eigs = sort(eigs)
    print
    print 'Results by LOBPCG'
    print
    print n,eigs

    tt = time.clock()
    w,v=symeig(A,B,range=(1,m))
    data2.append(time.clock()-tt)
    print
    print 'Results by symeig'
    print
    print n, w

xlabel(r'Size $n$')
ylabel(r'Elapsed time $t$')
plot(N,data1,label='LOBPCG')
plot(N,data2,label='SYMEIG')
legend()
show()
ww__w_.jav_a_2___s_._c_om_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.