Thread: OPR
View Single Post
  #14   Spotlight this post!  
Unread 27-02-2015, 11:26
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,044
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: OPR

Quote:
Originally Posted by plnyyanks View Post
Low hanging fruit, I call it
Here's some even tastier fruit:

Code:
Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)] on win32
>>> import numpy
>>> import time
>>> import scipy
>>> import scipy.sparse
>>> import scipy.sparse.linalg

>>> # Read M & s ...
>>> M = numpy.loadtxt(open('M.dat'))
>>> s = numpy.loadtxt(open('s.dat'))
>>> end = time.time()

>>> # solve...
... start = time.time()
>>> x = numpy.linalg.solve(M,s)
>>> end = time.time()
>>> print "%f seconds" % (end-start)
15.344000 seconds

>>># solve Cholesky...
... start = time.time()
>>> xc = scipy.linalg.cho_solve(scipy.linalg.cho_factor(M),s)
>>> end = time.time()
>>> print "%f seconds" % (end-start)
1.688000 seconds

>>> # Convert to sparse...
... start = time.time()
>>> Msparse = scipy.sparse.csr_matrix(M)
>>> end = time.time()
>>> print "%f seconds" % (end-start)
0.219000 seconds
>>>
>>> # solve sparse...
... start = time.time()
>>> xs = scipy.sparse.linalg.spsolve(Msparse,s)
>>> end = time.time()
>>> print "%f seconds" % (end-start)
0.468000 seconds
>>>
PS: above code was run on single core of 8-year-old Pentium D machine running XP SP3



Last edited by Ether : 27-02-2015 at 12:25.
Reply With Quote