diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2020-08-04 14:56:32 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2020-08-04 14:56:32 +0100 |
commit | 9fd03abf5d911af6732b180707d9cb92d662572a (patch) | |
tree | c1b0d51f76ec8e8028f49689a728480524a749e2 /lualib/lua_ffi | |
parent | d7d71002117e4ec30d96ca91c54f971b8e835325 (diff) | |
download | rspamd-9fd03abf5d911af6732b180707d9cb92d662572a.tar.gz rspamd-9fd03abf5d911af6732b180707d9cb92d662572a.zip |
[Project] Add ssyev method interface
Diffstat (limited to 'lualib/lua_ffi')
-rw-r--r-- | lualib/lua_ffi/linalg.lua | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/lualib/lua_ffi/linalg.lua b/lualib/lua_ffi/linalg.lua index c3f6eff5a..85e84b5ac 100644 --- a/lualib/lua_ffi/linalg.lua +++ b/lualib/lua_ffi/linalg.lua @@ -25,13 +25,14 @@ local exports = {} ffi.cdef[[ void kad_sgemm_simple(int trans_A, int trans_B, int M, int N, int K, const float *A, const float *B, float *C); + bool kad_ssyev_simple (int N, float *A, float *output); ]] local function table_to_ffi(a, m, n) - local a_conv = ffi.new(string.format("float[%d][%d]", m, n), {}) + local a_conv = ffi.new("float[?]", m * n) for i=1,m or #a do for j=1,n or #a[1] do - a_conv[i - 1][j - 1] = a[i][j] + a_conv[(i - 1) * n + (j - 1)] = a[i][j] end end return a_conv @@ -58,12 +59,28 @@ exports.sgemm = function(a, m, b, n, k, trans_a, trans_b) if type(b) == 'table' then b = table_to_ffi(b, k, n) end - local res = ffi.new(string.format("float[%d][%d]", m, n), {}) + local res = ffi.new("float[?]", m * n) ffi.C.kad_sgemm_simple(trans_a or 0, trans_b or 0, m, n, k, ffi.cast('const float*', a), ffi.cast('const float*', b), ffi.cast('float*', res)) return res end +exports.eugen = function(a, n) + if type(a) == 'table' then + -- Need to convert, slow! + n = n or #a + a = table_to_ffi(a, n, n) + end + + local res = ffi.new("float[?]", n) + + if ffi.C.kad_ssyev_simple(n, ffi.cast('float*', a), res) then + return res,a + end + + return nil +end + exports.ffi_to_table = ffi_to_table exports.table_to_ffi = table_to_ffi |