Mercurial > hg > may
diff yetilab/matrix/test/speedtest.yeti @ 249:1ea5bf6e76b6 sparse
A reasonable sparse multiply, and a bit quicker dense one
author | Chris Cannam |
---|---|
date | Mon, 20 May 2013 22:17:19 +0100 |
parents | 586d46f64902 |
children | 9fe3192cce38 |
line wrap: on
line diff
--- a/yetilab/matrix/test/speedtest.yeti Mon May 20 18:11:44 2013 +0100 +++ b/yetilab/matrix/test/speedtest.yeti Mon May 20 22:17:19 2013 +0100 @@ -4,6 +4,10 @@ mat = load yetilab.matrix.matrix; vec = load yetilab.vector.vector; +{ compare, compareUsing } = load yetilab.test.test; + +compareMatrices = compareUsing mat.equal; + time f = (start = System#currentTimeMillis(); result = f (); @@ -17,10 +21,10 @@ makeSparse () = (print "Making \(sparsity * 100)% sparse version (as dense matrix)..."; t = time \(mat.thresholded sparsity m); - println "(Reported density: \(mat.density t))"; + println "Reported density: \(mat.density t) (non-zero values: \(mat.nonZeroValues t))"; print "Converting to sparse matrix..."; s = time \(mat.toSparse t); - println "(Reported density: \(mat.density s))"; + println "Reported density: \(mat.density s) (non-zero values: \(mat.nonZeroValues s))"; s); s = makeSparse (); println "Making types:"; @@ -38,58 +42,48 @@ println "\nR * M multiplies:\n"; sz = 2000; +sparsity = 0.98; -{ cmd, rmd, cms, rms } = makeMatrices sz 0.98; +{ cmd, rmd, cms, rms } = makeMatrices sz sparsity; row = mat.newRowVector (vec.fromList (map \(Math#random()) [1..sz])); col = mat.newColumnVector (vec.fromList (map \(Math#random()) [1..sz])); print "R * CMD... "; -\() (time \(mat.product row cmd)); +a = (time \(mat.product row cmd)); print "R * RMD... "; -\() (time \(mat.product row rmd)); +b = (time \(mat.product row rmd)); print "R * CMS... "; -\() (time \(mat.product row cms)); +c = (time \(mat.product row cms)); print "R * RMS... "; -\() (time \(mat.product row rms)); +d = (time \(mat.product row rms)); + +println "\nChecking results: \(compareMatrices a b) \(compareMatrices c d)"; println "\nM * C multiplies:\n"; print "CMD * C... "; -\() (time \(mat.product cmd col)); +a = (time \(mat.product cmd col)); print "RMD * C... "; -\() (time \(mat.product rmd col)); +b = (time \(mat.product rmd col)); print "CMS * C... "; -\() (time \(mat.product cms col)); +c = (time \(mat.product cms col)); print "RMS * C... "; -\() (time \(mat.product rms col)); +d = (time \(mat.product rms col)); +println "\nChecking results: \(compareMatrices a b) \(compareMatrices c d)"; println "\nM * M multiplies:\n"; sz = 500; -{ cmd, rmd, cms, rms } = makeMatrices sz 0.98; - -print "CMD * CMD... "; -\() (time \(mat.product cmd cmd)); - -print "CMD * RMD... "; -\() (time \(mat.product cmd rmd)); - -print "RMD * CMD... "; -\() (time \(mat.product rmd cmd)); - -print "RMD * RMD... "; -\() (time \(mat.product rmd rmd)); - -println ""; +{ cmd, rmd, cms, rms } = makeMatrices sz sparsity; print "CMS * CMD... "; \() (time \(mat.product cms cmd)); @@ -131,4 +125,18 @@ print "RMS * RMS... "; \() (time \(mat.product rms rms)); +println ""; + +print "CMD * CMD... "; +\() (time \(mat.product cmd cmd)); + +print "CMD * RMD... "; +\() (time \(mat.product cmd rmd)); + +print "RMD * CMD... "; +\() (time \(mat.product rmd cmd)); + +print "RMD * RMD... "; +\() (time \(mat.product rmd rmd)); + ();