• Subject: Re: LuaJIT2 performance for number crunching
• From: Luis Carvalho <lexcarvalho@...>
• Date: Tue, 22 Feb 2011 23:15:37 -0500

```Mike Pall wrote:
<snip>
> Loops over vectors are certainly faster if written in plain Lua
> and compiled with LuaJIT (provided the vectors are not too short).
>
> [I can understand the desire to avoid rewriting all of cblas in
> Lua, but a daxpy loop seems easy. And BTW: do NOT unroll it by
> hand, this is counter-productive on modern CPUs.]
<snip>

Talking about vectors, how does luajit fare when dealing with strided vectors?
Simple example:

local ffi = require "ffi"
ffi.cdef"typedef struct { int size, stride; double *data; } Vector;"
local newvector = ffi.typeof "Vector"
local datablock = ffi.typeof "double[?]"
local _D = setmetatable({}, {__mode = "k"})

function vector (n)
local data = datablock(n)
local v = newvector()
v.size = n
v.stride = 1
v.data = data
_D[v] = data
return v
end

-- assumes unitary stride
function set1 (u, v)
for i = 0, u.size - 1 do
u.data[i] = v.data[i]
end
return u
end

function set (u, v)
for i = 0, u.size - 1 do
u.data[i * u.stride] = v.data[i * v.stride]
end
return u
end

Are set1 and set comparable? (I'm not sure "set" is the best way of
implementing a strided version...)

Cheers,
Luis

--
Computers are useless. They can only give you answers.
-- Pablo Picasso

--
Luis Carvalho (Kozure)
lua -e 'print((("lexcarvalho@NO.gmail.SPAM.com"):gsub("(%u+%.)","")))'

```