Mercurial > hg > pycsalgos
changeset 7:9079a9f7c4cf
More tests
author | nikcleju |
---|---|
date | Sat, 05 Nov 2011 11:41:38 +0000 |
parents | cc7239d5e972 |
children | 64fbc37c8c06 |
files | tests/RecomTST_test.py tests/testLstsq.py tests/testmatlab.m tests/testnumpy.py |
diffstat | 4 files changed, 111 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/tests/RecomTST_test.py Sat Nov 05 11:08:35 2011 +0000 +++ b/tests/RecomTST_test.py Sat Nov 05 11:41:38 2011 +0000 @@ -58,6 +58,8 @@ if __name__ == "__main__": - unittest.main(verbosity=2) + #import cProfile + #cProfile.run('unittest.main()', 'profres') + unittest.main() #suite = unittest.TestLoader().loadTestsFromTestCase(CompareResults) - #unittest.TextTestRunner(verbosity=2).run(suite) \ No newline at end of file + #unittest.TextTestRunner(verbosity=2).run(suite)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/testLstsq.py Sat Nov 05 11:41:38 2011 +0000 @@ -0,0 +1,20 @@ +import numpy as np +import numpy.linalg +import scipy.io +import scipy.linalg +import time + +def main(): + mdict = scipy.io.loadmat('testLstsq.mat') + A = mdict['A'].newbyteorder('=') + b = mdict['b'] + + starttime = time.time() + for i in np.arange(mdict['nruns']): + #for i in np.arange(100): + #np.linalg.lstsq(A, b) + np.linalg.svd(A) + print "Elapsed time = ",(time.time() - starttime) + +if __name__ == "__main__": + main()
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/testmatlab.m Sat Nov 05 11:41:38 2011 +0000 @@ -0,0 +1,6 @@ +disp('Eig');tic;data=rand(500,500);eig(data);toc; +disp('Svd');tic;data=rand(1000,1000);[u,s,v]=svd(data);s=svd(data);toc; +disp('Inv');tic;data=rand(1000,1000);result=inv(data);toc; +disp('Det');tic;data=rand(1000,1000);result=det(data);toc; +disp('Dot');tic;a=rand(1000,1000);b=inv(a);result=a*b-eye(1000);toc; +disp('Done');
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/testnumpy.py Sat Nov 05 11:41:38 2011 +0000 @@ -0,0 +1,81 @@ +""" +Benchmark script to be used to evaluate the performance improvement of the MKL +""" + +import os +import sys +import timeit + +import numpy +from numpy.random import random + +def test_eigenvalue(): + """ + Test eigen value computation of a matrix + """ + i = 500 + data = random((i,i)) + result = numpy.linalg.eig(data) + +def test_svd(): + """ + Test single value decomposition of a matrix + """ + i = 1000 + data = random((i,i)) + result = numpy.linalg.svd(data) + result = numpy.linalg.svd(data, full_matrices=False) + +def test_inv(): + """ + Test matrix inversion + """ + i = 1000 + data = random((i,i)) + result = numpy.linalg.inv(data) + +def test_det(): + """ + Test the computation of the matrix determinant + """ + i = 1000 + data = random((i,i)) + result = numpy.linalg.det(data) + +def test_dot(): + """ + Test the dot product + """ + i = 1000 + a = random((i, i)) + b = numpy.linalg.inv(a) + result = numpy.dot(a, b) - numpy.eye(i) + +# Test to start. The dict is the value I had with the MKL using EPD 6.0 and without MKL using EPD 5.1 +tests = {test_eigenvalue : (752., 3376.), + test_svd : (4608., 15990.), + test_inv : (418., 1457.), + test_det : (186.0, 400.), + test_dot : (666., 2444.) } + +# Setting the following environment variable in the shell executing the script allows +# you limit the maximal number threads used for computation +THREADS_LIMIT_ENV = 'OMP_NUM_THREADS' + +def start_benchmark(): + print """Benchmark is made against EPD 6.0,NumPy 1.4 with MKL and EPD 5.1, NumPy 1.3 with ATLAS +on a Thinkpad T60 with Intel CoreDuo 2Ghz CPU on Windows Vista 32 bit + """ + if os.environ.has_key(THREADS_LIMIT_ENV): + print "Maximum number of threads used for computation is : %s" % os.environ[THREADS_LIMIT_ENV] + print ("-" * 80) + print "Starting timing with numpy %s\nVersion: %s" % (numpy.__version__, sys.version) + print "%20s : %10s - %5s / %5s" % ("Function", "Timing [ms]", "MKL", "No MKL") + for fun, bench in tests.items(): + t = timeit.Timer(stmt="%s()" % fun.__name__, setup="from __main__ import %s" % fun.__name__) + res = t.repeat(repeat=3, number=1) + timing = 1000.0 * sum(res)/len(res) + print "%20s : %7.1f ms - %3.2f / %3.2f" % (fun.__name__, timing, bench[0]/timing, bench[1]/timing) + +if __name__ == '__main__': + start_benchmark()