# Numerical package for Lua

Numlua–Features

NumericLuaLuaWorkshop’08
•SomeOOandfunctionalﬂavor,butnoparadigmcompromise •Matrixtypesystem:general,triangular,symmetric,andposdef •Small:interpreter+libs≈1.25Mb(staticlink)or200Kb(dynamiclink) •ImplementedinANSICandthusasportableasLua •StandardinterfacetoBLAS/LAPACK:canbelinkedtomanyoptimized libs •MITlicense
Numlua–Examples
NumericLuaLuaWorkshop’08
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
function
circ2(v)
local
n
=
table.getn (v)
return
matrix.zeros (n):apply( function (i, j) return v[(j
i)
%
n
+
1]
end
)
end

## Numlua–Examples

NumericLuaLuaWorkshop’08
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
NumericLuaLuaWorkshop’08
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