Numlua: a n umer ical pac kage for Lua Luis Car v alho
BrownUniversity carvalho@dam.brown.edu LuaWorkshop July,2008Introduction NumericLuaLuaWor
•Alotofproblemsinscientificcomputingneedhighperformance numericalroutines
•Generalapproach:heavycomputationsinlowlevelroutines (FORTRANorC)wrappedinascriptingorOOlanguage(highlevel) •Promisingcandidate:Lua! •Performance:fastexecutionandsmallfootprint •Powerful:GC,functionalfacilities,coroutines,metamethods •Extensible:simpleandwelldefinedAPIinANSIC •Easy:semanticallyrichbutsimple •Free:MITlicense
Introduction NumericLuaLuaWor
•Alotofproblemsinscientificcomputingneedhighperformance numericalroutines •Generalapproach:heavycomputationsinlowlevelroutines (FORTRANorC)wrappedinascriptingorOOlanguage(highlevel)
•Promisingcandidate:Lua! •Performance:fastexecutionandsmallfootprint •Powerful:GC,functionalfacilities,coroutines,metamethods •Extensible:simpleandwelldefinedAPIinANSIC •Easy:semanticallyrichbutsimple •Free:MITlicense
Introduction NumericLuaLuaWor
•Alotofproblemsinscientificcomputingneedhighperformance numericalroutines •Generalapproach:heavycomputationsinlowlevelroutines (FORTRANorC)wrappedinascriptingorOOlanguage(highlevel) •Promisingcandidate:Lua!
•Performance:fastexecutionandsmallfootprint •Powerful:GC,functionalfacilities,coroutines,metamethods •Extensible:simpleandwelldefinedAPIinANSIC •Easy:semanticallyrichbutsimple •Free:MITlicense
Introduction NumericLuaLuaWor
•Alotofproblemsinscientificcomputingneedhighperformance numericalroutines •Generalapproach:heavycomputationsinlowlevelroutines (FORTRANorC)wrappedinascriptingorOOlanguage(highlevel) •Promisingcandidate:Lua! •Performance:fastexecutionandsmallfootprint
•Powerful:GC,functionalfacilities,coroutines,metamethods •Extensible:simpleandwelldefinedAPIinANSIC •Easy:semanticallyrichbutsimple •Free:MITlicense
Introduction NumericLuaLuaWor
•Alotofproblemsinscientificcomputingneedhighperformance numericalroutines •Generalapproach:heavycomputationsinlowlevelroutines (FORTRANorC)wrappedinascriptingorOOlanguage(highlevel) •Promisingcandidate:Lua! •Performance:fastexecutionandsmallfootprint •Powerful:GC,functionalfacilities,coroutines,metamethods
•Extensible:simpleandwelldefinedAPIinANSIC •Easy:semanticallyrichbutsimple •Free:MITlicense
Introduction NumericLuaLuaWor
•Alotofproblemsinscientificcomputingneedhighperformance numericalroutines •Generalapproach:heavycomputationsinlowlevelroutines (FORTRANorC)wrappedinascriptingorOOlanguage(highlevel) •Promisingcandidate:Lua! •Performance:fastexecutionandsmallfootprint •Powerful:GC,functionalfacilities,coroutines,metamethods •Extensible:simpleandwelldefinedAPIinANSIC
•Easy:semanticallyrichbutsimple •Free:MITlicense
Introduction NumericLuaLuaWor
•Alotofproblemsinscientificcomputingneedhighperformance numericalroutines •Generalapproach:heavycomputationsinlowlevelroutines (FORTRANorC)wrappedinascriptingorOOlanguage(highlevel) •Promisingcandidate:Lua! •Performance:fastexecutionandsmallfootprint •Powerful:GC,functionalfacilities,coroutines,metamethods •Extensible:simpleandwelldefinedAPIinANSIC •Easy:semanticallyrichbutsimple
•Free:MITlicense
Introduction NumericLuaLuaWor
•Alotofproblemsinscientificcomputingneedhighperformance numericalroutines •Generalapproach:heavycomputationsinlowlevelroutines (FORTRANorC)wrappedinascriptingorOOlanguage(highlevel) •Promisingcandidate:Lua! •Performance:fastexecutionandsmallfootprint •Powerful:GC,functionalfacilities,coroutines,metamethods •Extensible:simpleandwelldefinedAPIinANSIC •Easy:semanticallyrichbutsimple •Free:MITlicense
NumericLua NumericLuaLuaWor
•Basedon“classical”numericalpackages
•Motivation:keepminimalistapproachfromLuainordertoprovidea basisformoreelaboratedscientificpackages •Components •Complexnumbers •Specialfunctions(Exps+CDFs+PDFs) •Randomnumbergeneration(MT+Ranlib) •Numericallinearalgebra(BLAS+LAPACK)
NumericLua NumericLuaLuaWor
•Basedon“classical”numericalpackages •Motivation:keepminimalistapproachfromLuainordertoprovidea basisformoreelaboratedscientificpackages
•Components •Complexnumbers •Specialfunctions(Exps+CDFs+PDFs) •Randomnumbergeneration(MT+Ranlib) •Numericallinearalgebra(BLAS+LAPACK)
NumericLua NumericLuaLuaWor
•Basedon“classical”numericalpackages •Motivation:keepminimalistapproachfromLuainordertoprovidea basisformoreelaboratedscientificpackages •Components •Complexnumbers •Specialfunctions(Exps+CDFs+PDFs) •Randomnumbergeneration(MT+Ranlib) •Numericallinearalgebra(BLAS+LAPACK)
Numlua–Features NumericLuaLuaWor
•SomeOOandfunctionalflavor,butnoparadigmcompromise
•Matrixtypesystem:general,triangular,symmetric,andposdef •Small:interpreter+libs≈1.25Mb(staticlink)or200Kb(dynamiclink) •ImplementedinANSICandthusasportableasLua •StandardinterfacetoBLAS/LAPACK:canbelinkedtomanyoptimized libs •MITlicense
Numlua–Features NumericLuaLuaWor
•SomeOOandfunctionalflavor,butnoparadigmcompromise •Matrixtypesystem:general,triangular,symmetric,andposdef
•Small:interpreter+libs≈1.25Mb(staticlink)or200Kb(dynamiclink) •ImplementedinANSICandthusasportableasLua •StandardinterfacetoBLAS/LAPACK:canbelinkedtomanyoptimized libs •MITlicense
Numlua–Features NumericLuaLuaWor
•SomeOOandfunctionalflavor,butnoparadigmcompromise •Matrixtypesystem:general,triangular,symmetric,andposdef •Small:interpreter+libs≈1.25Mb(staticlink)or200Kb(dynamiclink)
•ImplementedinANSICandthusasportableasLua •StandardinterfacetoBLAS/LAPACK:canbelinkedtomanyoptimized libs •MITlicense
Numlua–Features NumericLuaLuaWor
•SomeOOandfunctionalflavor,butnoparadigmcompromise •Matrixtypesystem:general,triangular,symmetric,andposdef •Small:interpreter+libs≈1.25Mb(staticlink)or200Kb(dynamiclink) •ImplementedinANSICandthusasportableasLua
•StandardinterfacetoBLAS/LAPACK:canbelinkedtomanyoptimized libs •MITlicense
Numlua–Features NumericLuaLuaWorkshop’08
•SomeOOandfunctionalflavor,butnoparadigmcompromise •Matrixtypesystem:general,triangular,symmetric,andposdef •Small:interpreter+libs≈1.25Mb(staticlink)or200Kb(dynamiclink) •ImplementedinANSICandthusasportableasLua •StandardinterfacetoBLAS/LAPACK:canbelinkedtomanyoptimized libs
•MITlicense
Numlua–Features NumericLuaLuaWorkshop’08
•SomeOOandfunctionalflavor,butnoparadigmcompromise •Matrixtypesystem:general,triangular,symmetric,andposdef •Small:interpreter+libs≈1.25Mb(staticlink)or200Kb(dynamiclink) •ImplementedinANSICandthusasportableasLua •StandardinterfacetoBLAS/LAPACK:canbelinkedtomanyoptimized libs •MITlicense
Numlua–Examples NumericLuaLuaWor
functioncirc1(v) localn=table.getn(v) localm=matrix.zeros(n) fori=1,ndo forj=1,ndo m[i][j]=v[(j-i)%n+1] end end returnm end
functioncirc2(v) localn=table.getn(v) returnmatrix.zeros(n):apply( function(i,j)returnv[(j-i)%n+1]end) end
Numlua–Examples NumericLuaLuaWor
functioncirc1(v) localn=table.getn(v) localm=matrix.zeros(n) fori=1,ndo forj=1,ndo m[i][j]=v[(j-i)%n+1] end end returnm end functioncirc2(v) localn=table.getn(v) returnmatrix.zeros(n):apply( function(i,j)returnv[(j-i)%n+1]end) end
Numlua–Examples NumericLuaLuaWor
localr=rng(os.clock()) functionmvnorm(mean,var,n) localu,info=matrix.chol(var)--u’ *u=var assert(info==0,"matrixisnotpositivedefinite") --y:col(i)∼N(0_m,I_m) localm=mean:size() localy=matrix(m,n):map( function(e)returnr:norm(0,1)end) --u’*y+mean∼N(mean,var) y=#u*y fori,j,einy:entries()do y[i][j]=e+mean[i] end returny end
Futurework NumericLuaLuaWor
•Documentation!
•MovetoLuarocks •Newinternalrepresentationformatrices •Usetokenfilterstomakematrixdeclarationeasier(lesspainfull) •Extensions:HDF5,sparsematrices,statlibrary,plottinglibrary,...
Futurework NumericLuaLuaWor
•Documentation! •MovetoLuarocks
•Newinternalrepresentationformatrices •Usetokenfilterstomakematrixdeclarationeasier(lesspainfull) •Extensions:HDF5,sparsematrices,statlibrary,plottinglibrary,...
Futurework NumericLuaLuaWor
•Documentation! •MovetoLuarocks •Newinternalrepresentationformatrices
•Usetokenfilterstomakematrixdeclarationeasier(lesspainfull) •Extensions:HDF5,sparsematrices,statlibrary,plottinglibrary,...
Futurework NumericLuaLuaWor
•Documentation! •MovetoLuarocks •Newinternalrepresentationformatrices •Usetokenfilterstomakematrixdeclarationeasier(lesspainfull)
•Extensions:HDF5,sparsematrices,statlibrary,plottinglibrary,...
Futurework NumericLuaLuaWor
•Documentation! •MovetoLuarocks •Newinternalrepresentationformatrices •Usetokenfilterstomakematrixdeclarationeasier(lesspainfull) •Extensions:HDF5,sparsematrices,statlibrary,plottinglibrary,...
Thankyou! NumericLuaLuaWor