Chris@248: Chris@248: program yetilab.matrix.test.speedtest; Chris@248: Chris@248: mat = load yetilab.matrix.matrix; Chris@248: vec = load yetilab.vector.vector; Chris@248: Chris@249: { compare, compareUsing } = load yetilab.test.test; Chris@249: Chris@249: compareMatrices = compareUsing mat.equal; Chris@249: Chris@248: time f = Chris@248: (start = System#currentTimeMillis(); Chris@248: result = f (); Chris@248: end = System#currentTimeMillis(); Chris@248: println " \(end-start)ms"; Chris@248: result); Chris@248: Chris@248: makeMatrices sz sparsity = Chris@248: (print "Making \(sz) * \(sz) random matrix..."; Chris@248: m = time \(mat.randomMatrix { rows = sz, columns = sz }); Chris@248: makeSparse () = Chris@248: (print "Making \(sparsity * 100)% sparse version (as dense matrix)..."; Chris@248: t = time \(mat.thresholded sparsity m); Chris@249: println "Reported density: \(mat.density t) (non-zero values: \(mat.nonZeroValues t))"; Chris@248: print "Converting to sparse matrix..."; Chris@248: s = time \(mat.toSparse t); Chris@249: println "Reported density: \(mat.density s) (non-zero values: \(mat.nonZeroValues s))"; Chris@248: s); Chris@248: s = makeSparse (); Chris@248: println "Making types:"; Chris@248: print "Col-major dense..."; Chris@248: cmd = time \(mat.toColumnMajor m); Chris@248: print "Row-major dense..."; Chris@248: rmd = time \(mat.toRowMajor m); Chris@248: print "Col-major sparse..."; Chris@248: cms = time \(mat.toColumnMajor s); Chris@248: print "Row-major sparse..."; Chris@248: rms = time \(mat.toRowMajor s); Chris@248: println ""; Chris@248: { cmd, rmd, cms, rms }); Chris@248: Chris@248: println "\nR * M multiplies:\n"; Chris@248: Chris@248: sz = 2000; Chris@249: sparsity = 0.98; Chris@248: Chris@249: { cmd, rmd, cms, rms } = makeMatrices sz sparsity; Chris@248: Chris@248: row = mat.newRowVector (vec.fromList (map \(Math#random()) [1..sz])); Chris@248: col = mat.newColumnVector (vec.fromList (map \(Math#random()) [1..sz])); Chris@248: Chris@248: print "R * CMD... "; Chris@249: a = (time \(mat.product row cmd)); Chris@248: Chris@248: print "R * RMD... "; Chris@249: b = (time \(mat.product row rmd)); Chris@248: Chris@248: print "R * CMS... "; Chris@249: c = (time \(mat.product row cms)); Chris@248: Chris@248: print "R * RMS... "; Chris@249: d = (time \(mat.product row rms)); Chris@249: Chris@249: println "\nChecking results: \(compareMatrices a b) \(compareMatrices c d)"; Chris@248: Chris@248: println "\nM * C multiplies:\n"; Chris@248: Chris@248: print "CMD * C... "; Chris@249: a = (time \(mat.product cmd col)); Chris@248: Chris@248: print "RMD * C... "; Chris@249: b = (time \(mat.product rmd col)); Chris@248: Chris@248: print "CMS * C... "; Chris@249: c = (time \(mat.product cms col)); Chris@248: Chris@248: print "RMS * C... "; Chris@249: d = (time \(mat.product rms col)); Chris@248: Chris@249: println "\nChecking results: \(compareMatrices a b) \(compareMatrices c d)"; Chris@248: Chris@248: println "\nM * M multiplies:\n"; Chris@248: Chris@248: sz = 500; Chris@248: Chris@249: { cmd, rmd, cms, rms } = makeMatrices sz sparsity; Chris@248: Chris@248: print "CMS * CMD... "; Chris@248: \() (time \(mat.product cms cmd)); Chris@248: Chris@248: print "CMS * RMD... "; Chris@248: \() (time \(mat.product cms rmd)); Chris@248: Chris@248: print "RMS * CMD... "; Chris@248: \() (time \(mat.product rms cmd)); Chris@248: Chris@248: print "RMS * RMD... "; Chris@248: \() (time \(mat.product rms rmd)); Chris@248: Chris@248: println ""; Chris@248: Chris@248: print "CMD * CMS... "; Chris@248: \() (time \(mat.product cmd cms)); Chris@248: Chris@248: print "CMD * RMS... "; Chris@248: \() (time \(mat.product cmd rms)); Chris@248: Chris@248: print "RMD * CMS... "; Chris@248: \() (time \(mat.product rmd cms)); Chris@248: Chris@248: print "RMD * RMS... "; Chris@248: \() (time \(mat.product rmd rms)); Chris@248: Chris@248: println ""; Chris@248: Chris@248: print "CMS * CMS... "; Chris@248: \() (time \(mat.product cms cms)); Chris@248: Chris@248: print "CMS * RMS... "; Chris@248: \() (time \(mat.product cms rms)); Chris@248: Chris@248: print "RMS * CMS... "; Chris@248: \() (time \(mat.product rms cms)); Chris@248: Chris@248: print "RMS * RMS... "; Chris@248: \() (time \(mat.product rms rms)); Chris@248: Chris@249: println ""; Chris@249: Chris@249: print "CMD * CMD... "; Chris@249: \() (time \(mat.product cmd cmd)); Chris@249: Chris@249: print "CMD * RMD... "; Chris@249: \() (time \(mat.product cmd rmd)); Chris@249: Chris@249: print "RMD * CMD... "; Chris@249: \() (time \(mat.product rmd cmd)); Chris@249: Chris@249: print "RMD * RMD... "; Chris@249: \() (time \(mat.product rmd rmd)); Chris@249: Chris@248: ();