lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Mike Pall wrote:
> 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.]

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 = data
  _D[v] = data
  return v

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

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

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


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

Luis Carvalho (Kozure)
lua -e 'print(((""):gsub("(%u+%.)","")))'