Extrait du cours numerical Package for Lua
Introduction
-A lot of problems in scientific computing need high performance numerical routines
-General approach: heavy computations in low level routines (FORTRAN or C) wrapped in a scripting or OO language (high level)
-Promising candidate: Lua!
-Performance: fast execution and small footprint
• Powerful: GC, functional facilities, coroutines, metamethods
• Extensible: simple and well defined API in ANSI C
• Easy: semantically rich but simple
• Free: MIT license
NumericLua
Based on “classical” numerical packages
• Motivation: keep minimalist approach from Lua in order to provide a basis for more elaborated scientific packages
• Components
• Complex numbers
• Special functions (Exps + CDFs + PDFs)
• Random number generation (MT + Ranlib)
• Numerical linear algebra (BLAS + LAPACK)
Numlua–Features
Some OO and functional flavor, but no paradigm compromise
• Matrix type system: general, triangular, symmetric, and posdef
• Small: interpreter + libs ≈ 1.25Mb (static link) or 200Kb (dynamic link)
• Implemented in ANSI C and thus as portable as Lua
• Standard interface to BLAS/LAPACK: can be linked to many optimized libs
• MIT license
Numlua–Examples
function circ1(v)
local n = table.getn(v) local m = matrix.zeros(n) for i = 1, n do
for j = 1, n do
m[i][j] = v[(j – i) % n + 1]
end end return m
end
Numlua–Examples
function circ1(v)
local n = table.getn(v) local m = matrix.zeros(n) for i = 1, n do
for j = 1, n do
m[i][j] = v[(j – i) % n + 1]
end end return m
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
………
Télécharger cours: Numerical Package for Lua (131 KO) (Cours PDF)