diff --git a/CMakeLists.txt b/CMakeLists.txt deleted file mode 100644 index 34cd712..0000000 --- a/CMakeLists.txt +++ /dev/null @@ -1,21 +0,0 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 2.8) -PROJECT(ArrayFire-Lua) - -SET_PROPERTY(GLOBAL PROPERTY USE_FOLDERS ON) - -OPTION(USE_LOCAL_LUA "Build Lua as external project" OFF) - -SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules") - -ADD_SUBDIRECTORY(wrapper/Lua) - -######################################## -# Installation -######################################## -INSTALL(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/examples/" - DESTINATION "examples" - COMPONENT examples) - -INSTALL(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/wrapper/arrayfire/" - DESTINATION "arrayfire" - COMPONENT scripts) diff --git a/CMakeModules/build_lua.cmake b/CMakeModules/build_lua.cmake deleted file mode 100644 index 8a82109..0000000 --- a/CMakeModules/build_lua.cmake +++ /dev/null @@ -1,76 +0,0 @@ -INCLUDE(ExternalProject) - -SET(prefix ${CMAKE_BINARY_DIR}/third_party/lua) -SET(lua_lib_prefix "${prefix}/lib") - -SET(lua_location "${prefix}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}lua${CMAKE_SHARED_LIBRARY_SUFFIX}") -IF(CMAKE_VERSION VERSION_LESS 3.2) - IF(CMAKE_GENERATOR MATCHES "Ninja") - MESSAGE(WARNING "Building forge with Ninja has known issues with CMake older than 3.2") - endif() - SET(byproducts) -ELSE() - SET(byproducts BYPRODUCTS ${lua_location}) -ENDIF() - -IF(WIN32) - SET(LUA_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DLUA_DL_DLL") - SET(LUA_C_FLAGS "${CMAKE_C_FLAGS} -DLUA_DL_DLL") - SET(LUA_BUILD_AS_DLL ON) -ELSE() - SET(LUA_CXX_FLAGS "${CMAKE_CXX_FLAGS}") - SET(LUA_C_FLAGS "${CMAKE_C_FLAGS}") - SET(LUA_BUILD_AS_DLL OFF) -ENDIF() - -# FIXME Tag forge correctly during release -ExternalProject_Add( - lua-ext - GIT_REPOSITORY https://github.com/LuaDist/lua.git - GIT_TAG 5.3.2 - PATCH_COMMAND patch -p1 -t -N < ${CMAKE_MODULE_PATH}/lua_MSVC.patch - PREFIX "${prefix}" - INSTALL_DIR "${prefix}" - UPDATE_COMMAND "" - CONFIGURE_COMMAND ${CMAKE_COMMAND} -Wno-dev "-G${CMAKE_GENERATOR}" - -DCMAKE_SOURCE_DIR:PATH= - -DCMAKE_CXX_COMPILER:FILEPATH=${CMAKE_CXX_COMPILER} - -DCMAKE_C_COMPILER:FILEPATH=${CMAKE_C_COMPILER} - -DCMAKE_CXX_FLAGS:STRING=${LUA_CXX_FLAGS} - -DCMAKE_C_FLAGS:STRING=${LUA_C_FLAGS} - -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE} - -DCMAKE_INSTALL_PREFIX:PATH= - -DBUILD_SHARED_LIBS=ON - -DLUA_BUILD_AS_DLL=${LUA_BUILD_AS_DLL} - ${byproducts} - ) - -ExternalProject_Get_Property(lua-ext binary_dir) -ExternalProject_Get_Property(lua-ext install_dir) - -ADD_LIBRARY(lua IMPORTED SHARED) -SET_TARGET_PROPERTIES(lua PROPERTIES IMPORTED_LOCATION ${lua_location}) -IF(WIN32) - SET_TARGET_PROPERTIES(lua PROPERTIES IMPORTED_IMPLIB ${lua_lib_prefix}/lua.lib) -ENDIF(WIN32) - -ADD_DEPENDENCIES(lua lua-ext) -SET(LUA_INCLUDE_DIR ${install_dir}/include) -SET(LUA_LIBRARIES lua) -SET(LUA_FOUND ON) - -######################################## -# Installation -######################################## -INSTALL(DIRECTORY "${prefix}/bin" - DESTINATION "lua/" - USE_SOURCE_PERMISSIONS - COMPONENT lua_bin) -INSTALL(DIRECTORY "${prefix}/lib" - DESTINATION "lua/" - USE_SOURCE_PERMISSIONS - COMPONENT lua_lib) -INSTALL(DIRECTORY "${prefix}/include" - DESTINATION "lua/" - USE_SOURCE_PERMISSIONS - COMPONENT lua_include) diff --git a/CMakeModules/lua_MSVC.patch b/CMakeModules/lua_MSVC.patch deleted file mode 100644 index e463320..0000000 --- a/CMakeModules/lua_MSVC.patch +++ /dev/null @@ -1,21 +0,0 @@ -commit 4b61e31e44bac6b09bb70d3dbcd1b470b754bb71 -Author: Shehzan Mohammed -Date: Wed Dec 23 15:01:27 2015 -0500 - - Lua MSVC snprintf patch - -diff --git a/src/lprefix.h b/src/lprefix.h -index 02daa83..b56f8f6 100644 ---- a/src/lprefix.h -+++ b/src/lprefix.h -@@ -39,6 +39,10 @@ - #define _CRT_SECURE_NO_WARNINGS /* avoid warnings about ISO C functions */ - #endif - -+#if _MSC_VER < 1900 -+#define snprintf sprintf_s -+#endif -+ - #endif /* } */ - - #endif diff --git a/README.md b/README.md index 1749f7e..e1d0c66 100644 --- a/README.md +++ b/README.md @@ -2,42 +2,32 @@ [ArrayFire](https://github.com/arrayfire/arrayfire) is a high performance library for parallel computing with an easy-to-use API. It enables users to write scientific computing code that is portable across CUDA, OpenCL and CPU devices. This project provides Lua bindings for the ArrayFire library. -The wrapper is currently compliant with ArrayFire 3.2 API (and higher). If you find any bugs, please report them [here](https://github.com/arrayfire/arrayfire-lua/issues). +The wrapper is currently compliant with ArrayFire 3.4 API (and higher). If you find any bugs, please report them [here](https://github.com/arrayfire/arrayfire-lua/issues). ## Example -```lua -local AF = require("arrayfire") +Sample code: -AF.main(function() - local x = AF.randu(5, "f32") - AF.print("x", x) - AF.print("min of x", AF.min(x)) - AF.print("max of x", AF.max(x)) -end) ``` +local af = require('arrayfire') +af.info() +a = af.Array{1, 2, 3, 4} +af.print(a) +``` + +Sample output: ``` -$ lua examples/lua/helloworld/intro.lua -ArrayFire v3.2.1 (CUDA, 64-bit Linux, build f263db0) -Platform: CUDA Toolkit 7.5, Driver: 358.16 -[0] GeForce GTX 690, 2047 MB, CUDA Compute 3.0 --1- GeForce GTX 690, 2048 MB, CUDA Compute 3.0 - -x -[5 1 1 1] -0.7402 -0.9210 -0.0390 -0.9690 -0.9251 - -min of x -[1 1 1 1] -0.0390 -max of x -[1 1 1 1] -0.9690 +ArrayFire v3.5.0 (CUDA, 64-bit Linux, build 06e605b0) +Platform: CUDA Toolkit 8, Driver: 378.13 +[0] GeForce GTX 950, 1996 MB, CUDA Compute 5.2 + +ArrayFire Array +[4 1 1 1] +1.0000 +2.0000 +3.0000 +4.0000 ``` @@ -52,6 +42,11 @@ TODO - `cmake` - `Visual Studio` on Windows, `clang` / `gcc` on Linux / OSX. +Addiitonally, if you install the following Lua packages: + +- [luarocks](https://github.com/keplerproject/luarocks) +- [luaffi](https://github.com/facebook/luaffifb) (Not required for LuaJIT) + ### Get ArrayFire libraries You can install ArrayFire using one of the following two ways. @@ -65,37 +60,10 @@ You can install ArrayFire using one of the following two ways. ### Building the Lua module -**Windows** - -1. Launch `cmake-gui`. Set source and build directories. -2. Press configure. -3. Select `generator` as `Visual Studio 12 2013 Win64`. - - You can choose a different generator as long as it is Win64. -4. Set `CMAKE_INSTALL_PREFIX` to a location of choice. -5. Press generate. The generated visual studio solution file will be present in the build directory. -6. Open the VS solution file and build the `INSTALL` project. - -**Linux / OSX** - -1. Make sure the environment variable `ArrayFire_DIR` is set to `/path/to/arrayfire/share/ArrayFire/cmake`. -2. Create a build directory and `cd` into it. -3. Run `cmake /path/to/arrayfire-lua/ -DCMAKE_INSTALL_PREFIX=package`. -4. Run `make` - -### Setting up Lua paths - -**Windows** - - > SET LUA_PATH=C:\path\to\install\location\arrayfire\?.lua;; - > SET LUA_CPATH=C:\path\to\install\location\?.dll;; - > lua.exe helloworld/helloworld.lua - -**Linux** - - $ export LUA_PATH="/path/to/install/location/arrayfire/?.lua;;" - $ export LUA_CPATH="/path/to/install/location/?.so;;" - $ lua helloworld/helloworld.lua - +``` +cd /path/to/arrayfire-lua/ +luarocks make +``` You should now be good to go! diff --git a/arrayfire.lua b/arrayfire.lua new file mode 100644 index 0000000..ec4738c --- /dev/null +++ b/arrayfire.lua @@ -0,0 +1,11 @@ +require('arrayfire.lib') +require('arrayfire.defines') +require('arrayfire.dim4') +require('arrayfire.util') +require('arrayfire.array') +require('arrayfire.arith') +require('arrayfire.algorithm') +require('arrayfire.blas') +require('arrayfire.device') + +return af diff --git a/arrayfire/algorithm.lua b/arrayfire/algorithm.lua new file mode 100644 index 0000000..ce0dabd --- /dev/null +++ b/arrayfire/algorithm.lua @@ -0,0 +1,200 @@ +require('arrayfire.lib') +require('arrayfire.defines') +require('arrayfire.array') +local ffi = require( "ffi" ) + +local funcs = {} + +funcs[30] = [[ + af_err af_sum(af_array *out, const af_array in, const int dim); + af_err af_product(af_array *out, const af_array in, const int dim); + af_err af_min(af_array *out, const af_array in, const int dim); + af_err af_max(af_array *out, const af_array in, const int dim); + af_err af_all_true(af_array *out, const af_array in, const int dim); + af_err af_any_true(af_array *out, const af_array in, const int dim); + af_err af_count(af_array *out, const af_array in, const int dim); + af_err af_sum_all(double *real, double *imag, const af_array in); + af_err af_product_all(double *real, double *imag, const af_array in); + af_err af_min_all(double *real, double *imag, const af_array in); + af_err af_max_all(double *real, double *imag, const af_array in); + af_err af_all_true_all(double *real, double *imag, const af_array in); + af_err af_any_true_all(double *real, double *imag, const af_array in); + af_err af_count_all(double *real, double *imag, const af_array in); + af_err af_imin(af_array *out, af_array *idx, const af_array in, const int dim); + af_err af_imax(af_array *out, af_array *idx, const af_array in, const int dim); + af_err af_imin_all(double *real, double *imag, unsigned *idx, const af_array in); + af_err af_imax_all(double *real, double *imag, unsigned *idx, const af_array in); + af_err af_accum(af_array *out, const af_array in, const int dim); + af_err af_where(af_array *idx, const af_array in); + af_err af_diff1(af_array *out, const af_array in, const int dim); + af_err af_diff2(af_array *out, const af_array in, const int dim); + af_err af_sort(af_array *out, const af_array in, const unsigned dim, const bool isAscending); + af_err af_sort_index(af_array *out, af_array *indices, const af_array in, + const unsigned dim, const bool isAscending); + af_err af_sort_by_key(af_array *out_keys, af_array *out_values, + const af_array keys, const af_array values, + const unsigned dim, const bool isAscending); + af_err af_set_unique(af_array *out, const af_array in, const bool is_sorted); + af_err af_set_union(af_array *out, const af_array first, const af_array second, const bool is_unique); + af_err af_set_intersect(af_array *out, const af_array first, const af_array second, const bool is_unique); +]] + +funcs[31] = [[ + af_err af_sum_nan(af_array *out, const af_array in, const int dim, const double nanval); + af_err af_product_nan(af_array *out, const af_array in, const int dim, const double nanval); + af_err af_sum_nan_all(double *real, double *imag, const af_array in, const double nanval); + af_err af_product_nan_all(double *real, double *imag, const af_array in, const double nanval); +]] + +funcs[34] = [[ + af_err af_scan(af_array *out, const af_array in, const int dim, af_binary_op op, bool inclusive_scan); + af_err af_scan_by_key(af_array *out, const af_array key, const af_array in, const int dim, af_binary_op op, bool inclusive_scan); +]] + +af.lib.cdef(funcs) + +local c_array_p = af.ffi.c_array_p +local init = af.Array.init +local c_ptr_t = af.ffi.c_ptr_t + +local reduceFuncsWithNan = {'sum', 'product'} +for _, func in pairs(reduceFuncsWithNan) do + af[func] = function(input, dim, nanval) + if dim then + local res = c_array_p() + if nanval then + af.clib['af_' .. func .. '_nan'](res, input:get(), dim, nanval) + else + af.clib['af_' .. func .. ''](res, input:get(), dim) + end + return init(res[0]) + else + local res = c_ptr_t('double', 2) + if nanval then + af.clib['af_' .. func .. '_nan_all'](res + 0, res + 1, input:get(), nanval) + else + af.clib['af_' .. func .. '_all'](res + 0, res + 1, input:get()) + end + return (res[1] == 0) and res[0] or {real = res[0], imag = res[1]} + end + end +end + +local reduceFuncs = { + min = 'min', + max = 'max', + anyTrue = 'any_true', + allTrue = 'all_true', + count = count, +} + +for func,cfunc in pairs(reduceFuncs) do + af[func] = function(input, dim) + if dim then + local res = c_array_p() + af.clib['af_' .. cfunc .. ''](res, input:get(), dim) + return init(res[0]) + else + local res = c_ptr_t('double', 2) + af.clib['af_' .. cfunc .. '_all'](res + 0, res + 1, input:get()) + return (res[1] == 0) and res[0] or {real = res[0], imag = res[1]} + end + end +end + +local ireduceFuncs = {'imin', 'imax'} + +for _,func in pairs(reduceFuncs) do + af[func] = function(input, dim) + if dim then + local val = c_array_p() + local idx = c_array_p() + af.clib['af_' .. func .. ''](val, idx, input:get(), dim) + return init(val[0]), init(idx[0]) + else + local val = c_ptr_t('double', 2) + local idx = c_ptr_t('unsigned int') + af.clib['af_' .. func .. '_all'](val + 0, val + 1, idx + 0, input:get()) + if (val[1] == 0) then + return val[0], idx[0] + else + return {real = val[0], imag = val[1]}, idx[0] + end + end + end +end + +local dimAlgos = { + 'accum', + 'diff1', + 'diff2', +} + +for _, func in ipairs(dimAlgos) do + af[func] = function(input, dim) + local res = c_array_p() + af.clib['af_' .. func](res, input:get(), dim or 0) + return init(res[0]) + end +end + +af.where = function(input) + local res = c_array_p() + af.clib.af_where(res, input:get()); + return init(res[0]) +end + +af.sort = function(input, dim, isAscending) + local res = c_array_p() + af.clib.af_sort(res, input:get(), dim or 0, isAscending == nil and true or isAscending) + return init(res[0]) +end + +af.sortIndex = function(input, dim, isAscending) + local val = c_array_p() + local idx = c_array_p() + af.clib.af_sort_index(val, idx, input:get(), dim or 0, isAscending == nil and true or isAscending) + return init(val[0]), init(res[0]) +end + +af.sortByKey = function(inputKeys, inputVals, dim, isAscending) + local outVals = c_array_p() + local outKeys = c_array_p() + af.clib.af_sort_by_key(outKeys, outVals, + inputKeys:get(), inputVals:get(), + dim or 0, isAscending == nil and true or isAscending) + return init(outKeys[0]), init(outVals[0]) +end + +af.setUnique = function(input, isSorted) + local res = c_array_p() + af.clib.af_set_unique(res, input:get(), isSorted == nil and false or isSorted) + return init(res[0]) +end + +local setOps = { + setUnion = 'set_union', + setIntersect = 'set_intersect', +} + +for func, cfunc in pairs(setOps) do + af[func] = function(first, second, isUnique) + local res = c_array_p() + af.clib['af_' .. cfunc](res, first:get(), second:get(), isUnique == nil and false or isUnique) + return init(res[0]) + end +end + +af.scan = function(input, dim, op, isInclusive) + local res = c_array_p() + af.clib.af_scan(res, input:get(), dim or 0, + op or af.binary_op.add, isInclusive == nil and true or isInclusive) + return init(res[0]) +end + +af.scanByKey = function(inputKey, inputVal, dim, op, isInclusive) + local res = c_array_p() + af.clib.af_scan_by_key(res, inputKey:get(), inputVal:get(), dim or 0, + op or af.binary_op.add, isInclusive == nil and true or isInclusive) + return init(res[0]) +end diff --git a/arrayfire/arith.lua b/arrayfire/arith.lua new file mode 100644 index 0000000..0c9bd47 --- /dev/null +++ b/arrayfire/arith.lua @@ -0,0 +1,188 @@ +require('arrayfire.lib') +require('arrayfire.defines') +require('arrayfire.array') +local ffi = require( "ffi" ) + +local funcs = {} + +funcs[30] = [[ + af_err af_add (af_array *out, const af_array lhs, const af_array rhs, const bool batch); + af_err af_sub (af_array *out, const af_array lhs, const af_array rhs, const bool batch); + af_err af_mul (af_array *out, const af_array lhs, const af_array rhs, const bool batch); + af_err af_div (af_array *out, const af_array lhs, const af_array rhs, const bool batch); + af_err af_lt (af_array *out, const af_array lhs, const af_array rhs, const bool batch); + af_err af_gt (af_array *out, const af_array lhs, const af_array rhs, const bool batch); + af_err af_le (af_array *out, const af_array lhs, const af_array rhs, const bool batch); + af_err af_ge (af_array *out, const af_array lhs, const af_array rhs, const bool batch); + af_err af_eq (af_array *out, const af_array lhs, const af_array rhs, const bool batch); + af_err af_neq (af_array *out, const af_array lhs, const af_array rhs, const bool batch); + af_err af_and (af_array *out, const af_array lhs, const af_array rhs, const bool batch); + af_err af_or (af_array *out, const af_array lhs, const af_array rhs, const bool batch); + af_err af_not (af_array *out, const af_array in); + af_err af_bitand (af_array *out, const af_array lhs, const af_array rhs, const bool batch); + af_err af_bitor (af_array *out, const af_array lhs, const af_array rhs, const bool batch); + af_err af_bitxor (af_array *out, const af_array lhs, const af_array rhs, const bool batch); + af_err af_bitshiftl(af_array *out, const af_array lhs, const af_array rhs, const bool batch); + af_err af_bitshiftr(af_array *out, const af_array lhs, const af_array rhs, const bool batch); + af_err af_cast (af_array *out, const af_array in, const af_dtype type); + af_err af_minof (af_array *out, const af_array lhs, const af_array rhs, const bool batch); + af_err af_maxof (af_array *out, const af_array lhs, const af_array rhs, const bool batch); + af_err af_rem (af_array *out, const af_array lhs, const af_array rhs, const bool batch); + af_err af_mod (af_array *out, const af_array lhs, const af_array rhs, const bool batch); + af_err af_abs (af_array *out, const af_array in); + af_err af_arg (af_array *out, const af_array in); + af_err af_sign (af_array *out, const af_array in); + af_err af_round (af_array *out, const af_array in); + af_err af_trunc (af_array *out, const af_array in); + af_err af_floor (af_array *out, const af_array in); + af_err af_ceil (af_array *out, const af_array in); + af_err af_hypot (af_array *out, const af_array lhs, const af_array rhs, const bool batch); + af_err af_sin (af_array *out, const af_array in); + af_err af_cos (af_array *out, const af_array in); + af_err af_tan (af_array *out, const af_array in); + af_err af_asin (af_array *out, const af_array in); + af_err af_acos (af_array *out, const af_array in); + af_err af_atan (af_array *out, const af_array in); + af_err af_atan2 (af_array *out, const af_array lhs, const af_array rhs, const bool batch); + af_err af_cplx2 (af_array *out, const af_array lhs, const af_array rhs, const bool batch); + af_err af_cplx (af_array *out, const af_array in); + af_err af_real (af_array *out, const af_array in); + af_err af_imag (af_array *out, const af_array in); + af_err af_conjg (af_array *out, const af_array in); + af_err af_sinh (af_array *out, const af_array in); + af_err af_cosh (af_array *out, const af_array in); + af_err af_tanh (af_array *out, const af_array in); + af_err af_asinh (af_array *out, const af_array in); + af_err af_acosh (af_array *out, const af_array in); + af_err af_atanh (af_array *out, const af_array in); + af_err af_root (af_array *out, const af_array lhs, const af_array rhs, const bool batch); + af_err af_pow (af_array *out, const af_array lhs, const af_array rhs, const bool batch); + af_err af_pow2 (af_array *out, const af_array in); + af_err af_exp (af_array *out, const af_array in); + + af_err af_expm1 (af_array *out, const af_array in); + af_err af_erf (af_array *out, const af_array in); + af_err af_erfc (af_array *out, const af_array in); + af_err af_log (af_array *out, const af_array in); + af_err af_log1p (af_array *out, const af_array in); + af_err af_log10 (af_array *out, const af_array in); + af_err af_log2 (af_array *out, const af_array in); + af_err af_sqrt (af_array *out, const af_array in); + af_err af_cbrt (af_array *out, const af_array in); + af_err af_factorial (af_array *out, const af_array in); + af_err af_tgamma (af_array *out, const af_array in); + af_err af_lgamma (af_array *out, const af_array in); + af_err af_iszero (af_array *out, const af_array in); + af_err af_isinf (af_array *out, const af_array in); + af_err af_isnan (af_array *out, const af_array in); +]] + +funcs[31] = [[ + af_err af_sigmoid (af_array *out, const af_array in); +]] + +funcs[34] = [[ + af_err af_clamp(af_array *out, const af_array in, + const af_array lo, const af_array hi, const bool batch); +]] + +af.lib.cdef(funcs) +local c_array_p = af.ffi.c_array_p +local init = af.Array.init + +local binaryFuncs = { + 'add', + 'sub', + 'mul', + 'div', + 'lt', + 'gt', + 'le', + 'ge', + 'eq', + 'neq', + 'and', + 'or', + 'bitand', + 'bitor', + 'bitxor', + 'bitshiftl', + 'bitshiftr', + 'minof', + 'maxof', + 'rem', + 'mod', + 'hypot', + 'atan2', + 'cplx2', + 'root', + 'pow', +} + + +for _, func in ipairs(binaryFuncs) do + af[func] = function(lhs, rhs, batch) + -- TODO: add support for numbers + -- TODO: add support for batch mode + local res = c_array_p() + af.clib['af_' .. func](res, lhs:get(), rhs:get(), batch and true or false) + return init(res[0]) + end +end + +local unaryFuncs = { + 'abs', + 'arg', + 'sign', + 'round', + 'trunc', + 'floor', + 'ceil', + 'sin', + 'cos', + 'tan', + 'asin', + 'acos', + 'atan', + 'cplx', + 'real', + 'imag', + 'conjg', + 'sinh', + 'cosh', + 'tanh', + 'asinh', + 'acosh', + 'atanh', + 'pow2', + 'exp', + 'expm1', + 'erf', + 'erfc', + 'log', + 'log1p', + 'log10', + 'log2', + 'sqrt', + 'cbrt', + 'factorial', + 'tgamma', + 'lgamma', + 'iszero', + 'isinf', + 'isnan' +} + +for _, func in ipairs(unaryFuncs) do + af[func] = function(input) + local res = c_array_p() + af.clib['af_' .. func](res, input:get()) + return init(res[0]) + end +end + +af.cast = function(input, rtype) + local res = c_array_p() + af.clib.af_cast(res, input:get(), rtype) + return init(res[0]) +end diff --git a/arrayfire/array.lua b/arrayfire/array.lua new file mode 100644 index 0000000..3822426 --- /dev/null +++ b/arrayfire/array.lua @@ -0,0 +1,218 @@ +require('arrayfire.lib') +require('arrayfire.defines') +require('arrayfire.dim4') +local ffi = require( "ffi" ) + +local funcs = {} +funcs[30] = [[ + af_err af_create_array(af_array *arr, const void * const data, + const unsigned ndims, const dim_t * const dims, const af_dtype type); + + af_err af_create_handle(af_array *arr, const unsigned ndims, + const dim_t * const dims, const af_dtype type); + + af_err af_copy_array(af_array *arr, const af_array in); + + af_err af_write_array(af_array arr, const void *data, const size_t bytes, af_source src); + + af_err af_get_data_ptr(void *data, const af_array arr); + + af_err af_release_array(af_array arr); + + af_err af_retain_array(af_array *out, const af_array in); + + af_err af_get_elements(dim_t *elems, const af_array arr); + + af_err af_get_type(af_dtype *type, const af_array arr); + af_err af_get_dims(dim_t *d0, dim_t *d1, dim_t *d2, dim_t *d3, + const af_array arr); + + af_err af_get_numdims(unsigned *result, const af_array arr); + + af_err af_is_empty (bool *result, const af_array arr); + + af_err af_is_scalar (bool *result, const af_array arr); + + af_err af_is_row (bool *result, const af_array arr); + af_err af_is_column (bool *result, const af_array arr); + + af_err af_is_vector (bool *result, const af_array arr); + af_err af_is_complex (bool *result, const af_array arr); + + af_err af_is_real (bool *result, const af_array arr); + af_err af_is_double (bool *result, const af_array arr); + af_err af_is_single (bool *result, const af_array arr); + af_err af_is_realfloating (bool *result, const af_array arr); + af_err af_is_floating (bool *result, const af_array arr); + af_err af_is_integer (bool *result, const af_array arr); + af_err af_is_bool (bool *result, const af_array arr); + af_err af_eval(af_array in); +]] + +funcs[31] = [[ + af_err af_get_data_ref_count(int *use_count, const af_array in); +]] + + +funcs[34] = [[ + af_err af_eval_multiple(const int num, af_array *arrays); + af_err af_set_manual_eval_flag(bool flag); + af_err af_get_manual_eval_flag(bool *flag); + af_err af_is_sparse (bool *result, const af_array arr); +]] + +af.lib.cdef(funcs) + +local Array = {} +Array.__index = Array + +local c_dim4_t = af.ffi.c_dim4_t +local c_uint_t = af.ffi.c_uint_t +local c_ptr_t = af.ffi.c_ptr_t +local Dim4 = af.Dim4 + +function release_array(ptr) + local res = af.clib.af_release_array(ptr) + -- TODO: Error handling logic +end + +local c_array_p = function(ptr) + local arr_ptr = ffi.new('void *[1]', ptr) + return arr_ptr +end + +local init = function(ptr) + local self = setmetatable({}, Array) + self._ptr = ffi.gc(ptr, release_array) + self.isArray = true + return self +end + +Array.__init = function(data, dims, dtype, source) + if data then + assert(af.istable(data)) + end + + if dims then + assert(af.istable(dims)) + end + + c_dims = c_dim4_t(dims or (data and {#data} or {})) + c_ndims = c_uint_t(dims and #dims or (data and 1 or 0)) + + count = 1 + for i = 1,tonumber(c_ndims) do + count = count * c_dims[i - 1] + end + count = tonumber(count) + + local atype = dtype or af.dtype.f32 + local res = c_array_p() + if not data then + af.clib.af_create_handle(res, c_ndims, c_dims, atype) + else + c_data = c_ptr_t(af.dtype_names[atype + 1], count, data) + af.clib.af_create_array(res, c_data, c_ndims, c_dims, atype) + end + return Array.init(res[0]) +end + +Array.__tostring = function(self) + return 'arrayfire.Array\n' +end + +Array.get = function(self) + return self._ptr +end + +-- TODO: implement Array.write + +Array.copy = function(self) + local res = c_array_p() + af.clib.af_copy_array(res, self:get()) + return Array.init(res[0]) +end + +Array.softCopy = function(self) + local res = c_array_p() + af.clib.af_copy_array(res, self:get()) + return Array.init(res[0]) +end + +Array.elements = function(self) + local res = c_ptr_t('dim_t') + af.clib.af_get_elements(res, self:get()) + return tonumber(res[0]) +end + +Array.type = function(self) + local res = c_ptr_t('af_dtype') + af.clib.af_get_type(res, self:get()) + return tonumber(res[0]) +end + +Array.typeName = function(self) + local res = c_ptr_t('af_dtype') + af.clib.af_get_type(res, self:get()) + return af.dtype_names[tonumber(res[0])] +end + +Array.dims = function(self) + local res = c_dim4_t() + af.clib.af_get_dims(res + 0, res + 1, res + 2, res + 3, self:get()) + return Dim4(tonumber(res[0]), tonumber(res[1]), + tonumber(res[2]), tonumber(res[3])) +end + +Array.numdims = function(self) + local res = c_ptr_t('unsigned int') + af.clib.af_get_numdims(res, self:get()) + return tonumber(res[0]) +end + +local funcs = { + isEmpty = 'is_empty', + isScalar = 'is_scalar', + isRow = 'is_row', + isColumn = 'is_column', + isVector = 'is_vector', + isComplex = 'is_complex', + isReal = 'is_real', + isDouble = 'is_double', + isSingle = 'is_single', + isRealFloating = 'is_realfloating', + isFloating = 'is_floating', + isInteger = 'is_integer', + isBool = 'is_bool', +} + +for name, cname in pairs(funcs) do + Array[name] = function(self) + local res = c_ptr_t('bool') + af.clib['af_' .. cname](res, self:get()) + return res[0] + end +end + +Array.eval = function(self) + af.clib.af_eval(self:get()) +end + +-- Useful aliases +Array.ndims = Array.numdims +Array.nElement = Array.elements +Array.clone = Array.copy + +setmetatable( + Array, + { + __call = function(cls, ...) + return cls.__init(...) + end + } +) + +af.Array = Array +af.ffi.add_finalizer = add_finalizer +af.ffi.c_array_p = c_array_p +af.Array.init = init diff --git a/arrayfire/blas.lua b/arrayfire/blas.lua new file mode 100644 index 0000000..988d8ab --- /dev/null +++ b/arrayfire/blas.lua @@ -0,0 +1,68 @@ +require('arrayfire.lib') +require('arrayfire.defines') +require('arrayfire.array') +local ffi = require( "ffi" ) + +local funcs = {} + +funcs[30] = [[ + af_err af_matmul( af_array *out , + const af_array lhs, const af_array rhs, + const af_mat_prop optLhs, const af_mat_prop optRhs); + af_err af_dot(af_array *out, + const af_array lhs, const af_array rhs, + const af_mat_prop optLhs, const af_mat_prop optRhs); + af_err af_transpose(af_array *out, af_array in, const bool conjugate); + af_err af_transpose_inplace(af_array in, const bool conjugate); +]] + +funcs[35] = [[ + af_err af_dot_all(double *real, double *imag, + const af_array lhs, const af_array rhs, + const af_mat_prop optLhs, const af_mat_prop optRhs); +]] + +af.lib.cdef(funcs) +local c_array_p = af.ffi.c_array_p +local init = af.Array.init +local c_ptr_t = af.ffi.c_ptr_t + +af.matmul = function(lhs, rhs, lhsOpts, rhsOpts) + local res = c_array_p() + af.clib.af_matmul(res, lhs:get(), rhs:get(), + lhsOpts or af.mat_prop.none, + rhsOpts or af.mat_prop.none) + return init(res[0]) +end + +af.dot = function(lhs, rhs, lhsOpts, rhsOpts) + local res = c_array_p() + af.clib.af_dot(res, lhs:get(), rhs:get(), + lhsOpts or af.mat_prop.none, + rhsOpts or af.mat_prop.none) + return init(res[0]) +end + +af.transpose = function(input, inplace, conjugate) + if inplace then + af.clib.af_transpose_inplace(input:get(), conjugate == nil and false or true) + return input + else + local res = c_array_p() + af.clib.af_transpose(res, input:get(), conjugate == nil and false or true) + return init(res[0]) + end +end + +af.ctranspose = function(input, inplace) + return af.transpose(input, inplace, true) +end + +af.vecdot = function(lhs, rhs, lhsOpts, rhsOpts) + local res = c_ptr_t('double', 2) + af.clib.af_dot_all(res + 0, res + 1, + lhs:get(), rhs:get(), + lhsOpts or af.mat_prop.none, + rhsOpts or af.mat_prop.none) + return (res[1] == 0) and res[0] or {real = res[0], imag = res[1]} +end diff --git a/arrayfire/defines.lua b/arrayfire/defines.lua new file mode 100644 index 0000000..0776bf7 --- /dev/null +++ b/arrayfire/defines.lua @@ -0,0 +1,231 @@ +require('arrayfire.lib') + +af.err = { + none = 0, + + no_mem = 101, + driver = 102, + runtime = 103, + + invalid_array = 201, + arg = 202, + size = 203, + type = 204, + diff_type = 205, + batch = 207, + device = 208, + + not_supported = 301, + not_configured = 302, + nonfree = 303, + + no_dbl = 401, + no_gfx = 402, + + load_lib = 501, + load_sym = 502, + arr_bknd_mismatch = 503, + + internal = 998, + unknown = 999 +} + +af.dtype = { + f32 = 0, + c32 = 1, + f64 = 2, + c64 = 3, + b8 = 4, + s32 = 5, + u32 = 6, + u8 = 7, + s64 = 8, + u64 = 9, + s16 = 10, + u16 = 11 +} + +af.source = { + device = 0, + host = 1, +} + +af.interp_type = { + nearest = 0, + linear = 1, + bilinear = 2, + cubic = 3, + lower = 4, + linear_cosine = 5, + bilinear_cosine = 6, + bicubic = 7, + cubic_spline = 8, + bicubic_spline = 9, +} + +af.border_type = { + zero = 0, + symmetric = 1 +} + +af.connectivity = {} +af.connectivity[4] = 4 +af.connectivity[8] = 8 + +af.conv_mode = { + default = 0, + expand = 1 +} + +af.conv_domain = { + auto = 0, + spatial = 1, + frequency = 2, +} + +af.match_type = { + sad = 0, + zsad = 1, + lsad = 2, + ssd = 3, + zssd = 4, + lssd = 5, + ncc = 6, + zncc = 7, + shd = 8 +} + +af.ycc_std = {} +af.ycc_std[601] = 601 +af.ycc_std[709] = 709 +af.ycc_std[2020] = 2020 + +af.cspace = { + gray = 0, + rgb = 1, + hsv = 2, + ycbcr = 3 +} + +af.mat_prop = { + none = 0, + trans = 1, + ctrans = 2, + conj = 4, + upper = 32, + lower = 64, + diag_unit = 128, + sym = 512, + posdef = 1024, + orthog = 2048, + tri_diag = 4096, + block_diag = 8192 +} + +af.norm_type = { + vector_1 = 0, + vector_inf = 1, + vector_2 = 2, + vector_p = 3, + matrix_1 = 4, + matrix_inf = 5, + matrix_2 = 6, + matrix_l_pq = 7, + euclid = 2 +} + +af.image_format = { + bmp = 0, + ico = 1, + jpeg = 2, + jng = 3, + png = 13, + ppm = 14, + ppmraw = 15, + tiff = 18, + psd = 20, + hdr = 26, + exr = 29, + jp2 = 31, + raw = 34 +} + +af.moment_type = { + m00 = 1, + m01 = 2, + m10 = 4, + m11 = 8, + first_order = 15 +} + +af.homography_type = { + ransac = 0, + lmeds = 1 +} + +af.backend = { + default = 0, + cpu = 1, + cuda = 2, + opencl = 4, +} + +af.binary_op = { + add = 0, + mul = 1, + min = 2, + max = 3 +} + +af.random_engine_type = { + philox_4x32_10 = 100, + threefry_2x32_16 = 200, + mersenne_gp11213 = 300, +} +af.random_engine_type.philox = af.random_engine_type.philox_4x32_10 +af.random_engine_type.threefry = af.random_engine_type.threefry_2x32_16 +af.random_engine_type.mersenne = af.random_engine_type.mersenne_gp11213 +af.random_engine_type.default = af.random_engine_type.philox + +af.colormap = { + default = 0, + spectrum= 1, + colors = 2, + red = 3, + mood = 4, + heat = 5, + blue = 6 +} + +af.marker_type = { + none = 0, + point = 1, + circle = 2, + square = 3, + triangle = 4, + cross = 5, + plus = 6, + star = 7 +} + +af.storage = { + dense = 0, + csr = 1, + csc = 2, + coo = 3, +} + +af.dtype_names = { + 'float', + 'af_cfloat', + 'double', + 'af_cdouble', + 'char', + 'int', + 'unsigned int', + 'unsigned char', + 'unsigned long long', + 'long long', + 'short', + 'unsigned shhort' +} diff --git a/arrayfire/device.lua b/arrayfire/device.lua new file mode 100644 index 0000000..fd291e6 --- /dev/null +++ b/arrayfire/device.lua @@ -0,0 +1,7 @@ +require('arrayfire.lib') +local ffi = require( "ffi" ) +ffi.cdef[[ int af_info(void); ]] + +af.info = function() + af.clib.af_info() +end diff --git a/arrayfire/dim4.lua b/arrayfire/dim4.lua new file mode 100644 index 0000000..9d7bedb --- /dev/null +++ b/arrayfire/dim4.lua @@ -0,0 +1,36 @@ +require('arrayfire.lib') +require('arrayfire.defines') +local ffi = require( "ffi" ) +require 'string' + +local Dim4 = {} +Dim4.__index = Dim4 + +setmetatable( + Dim4, + { + __call = function(cls, ...) + return cls.__init(...) + end + } +) + +Dim4.__init = function(d1, d2, d3, d4) + local self = setmetatable({d1 or 1, d2 or 1, d3 or 1, d4 or 1}, Dim4) + return self +end + +Dim4.__tostring = function(self) + return string.format('[%d, %d, %d, %d]', self[1], self[2], self[3], self[4]) +end + +Dim4.ndims = function(self) + for i = 4,1,-1 do + if self[i] ~= 1 then + return self[i] == 0 and 0 or i + end + end + return self[1] == 0 and 0 or 1 +end + +af.Dim4 =Dim4 diff --git a/arrayfire/lib.lua b/arrayfire/lib.lua new file mode 100644 index 0000000..e26382a --- /dev/null +++ b/arrayfire/lib.lua @@ -0,0 +1,109 @@ +-- Adapted from https://github.com/malkia/ufo/blob/master/ffi/OpenCL.lua +af = {} +local ffi = require( "ffi" ) + +local AF_PATH = os.getenv("AF_PATH") + +if not AF_PATH then + error('AF_PATH not set') +end + +local name, path = "af", AF_PATH .. "/lib/" +local is_32_bit = ffi.abi("32bit") -- used to typedef dim_t + +if ArrayFireMode == "cl" or ArrayFireMode == "cuda" or ArrayFireMode == "cpu" then + name = name .. ArrayFireMode +end + +local lib_path = path .. "libaf" +af.clib = ffi.load(ffi_ArrayFire_lib or lib_path ) + +-- Define some core requirements +if ffi.abi('32bit') then + ffi.cdef[[typedef int dim_t;]] +else + ffi.cdef[[typedef long long dim_t;]] +end + +ffi.cdef[[ +typedef void * af_array; +typedef int af_err; +typedef int af_dtype; +typedef int af_source; +typedef int af_interp_type; +typedef int af_border_type; +typedef int af_connectivity; +typedef int af_match_type; +typedef int af_cspace_t; +typedef int af_mat_prop; +typedef int af_conv_mode; +typedef int af_conv_domain; +typedef int af_mat_prop; +typedef int af_colormap; +typedef int af_norm_type; +typedef int af_ycc_std; +typedef int af_image_format; +typedef int af_backend; +typedef int af_marker_type; +typedef int af_moment_type; +typedef int af_storage; +typedef int af_binary_op; +typedef int af_random_engine_type; + +typedef struct af_cfloat { + float real; + float imag; +} af_cfloat; + +typedef struct af_cdouble { + double real; + double imag; +} af_cdouble; + +af_err af_get_version (int *, int *, int *); +]] + +local major, minor, patch = ffi.new("int[1]"), ffi.new("int[1]"), ffi.new("int[1]") +af.clib.af_get_version(major, minor, patch) + +af.lib = {} +af.lib.version = {major = major[0], minor = minor[0], patch = patch[0]} +af.lib.api = major[0] * 10 + minor[0] + +af.lib.cdef = function(funcs) + for k,v in pairs(funcs) do + if af.lib.api >= k then + ffi.cdef(v) + end + end +end + +af.isnumber = function(val) + return type(val) == "number" +end + +af.istable = function(val) + return type(val) == "table" +end + +af.ffi = {} + +af.ffi.c_void_p = function() + return ffi.new('void *') +end + +af.ffi.c_dim_t = function(number) + return ffi.new('dim_t', number) +end + +af.ffi.c_ptr_t = function(ptr_type, count, values) + return ffi.new(ptr_type .. ' [?]', count or 1, values) +end + +af.ffi.c_uint_t = function(number) + return ffi.new('unsigned int', number) +end + +af.ffi.c_dim4_t = function(dims) + return ffi.new('dim_t[4]', dims or {1, 1, 1, 1}) +end diff --git a/arrayfire/util.lua b/arrayfire/util.lua new file mode 100644 index 0000000..eb29d34 --- /dev/null +++ b/arrayfire/util.lua @@ -0,0 +1,37 @@ +require('arrayfire.lib') +local ffi = require( "ffi" ) + +local funcs = {} + +funcs[30] = [[ + af_err af_print_array(af_array arr); +]] + +funcs[31] = [[ + af_err af_print_array_gen(const char *exp, const af_array arr, const int precision); + af_err af_save_array(int *index, const char* key, const af_array arr, + const char *filename, const bool append); + af_err af_read_array_index(af_array *out, const char *filename, const unsigned index); + af_err af_read_array_key(af_array *out, const char *filename, const char* key); + af_err af_read_array_key_check(int *index, const char *filename, const char* key); + af_err af_array_to_string(char **output, const char *exp, const af_array arr, + const int precision, const bool transpose); +]] + +funcs[33] = [[ + const char *af_get_revision(); +]] + +funcs[34] = [[ + af_err af_get_size_of(size_t *size, af_dtype type); +]] + +af.lib.cdef(funcs) + +af.print = function(arr) + if type(arr) == 'table' and arr.isArray then + af.clib.af_print_array_gen(ffi.cast("char *", "ArrayFire Array"), arr:get(), 4) + else + print(arr) + end +end diff --git a/rocks/arrayfire-scm-1.rockspec b/rocks/arrayfire-scm-1.rockspec new file mode 100644 index 0000000..331be52 --- /dev/null +++ b/rocks/arrayfire-scm-1.rockspec @@ -0,0 +1,30 @@ +package = "arrayfire" +version = "scm-1" +source = { + url = "git://github.com/pavanky/arrayfire-lua", + tag = "devel", + dir = "arrayfire-lua" +} +description = { + summary = "Lua Bindings for ArrayFire", + homepage = "http://github.com/arrayfire", + license = "BSD-3" +} +dependencies = { + "lua >= 5.1, < 5.4", +} +build = { + type = "builtin", + modules = { + arrayfire = "arrayfire.lua", + ["arrayfire.lib"] = "arrayfire/lib.lua", + ["arrayfire.util"] = "arrayfire/util.lua", + ["arrayfire.array"] = "arrayfire/array.lua", + ["arrayfire.defines"] = "arrayfire/defines.lua", + ["arrayfire.device"] = "arrayfire/device.lua", + ["arrayfire.dim4"] = "arrayfire/dim4.lua", + ["arrayfire.arith"] = "arrayfire/arith.lua", + ["arrayfire.algorithm"] = "arrayfire/algorithm.lua", + ["arrayfire.blas"] = "arrayfire/blas.lua", + }, +} diff --git a/wrapper/Lua/CMakeLists.txt b/wrapper/Lua/CMakeLists.txt deleted file mode 100644 index df52d0d..0000000 --- a/wrapper/Lua/CMakeLists.txt +++ /dev/null @@ -1,76 +0,0 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 2.8) -PROJECT(ArrayFire_Lib) - -FIND_PACKAGE(ArrayFire REQUIRED) - -# OS Definitions -IF(UNIX) - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -pthread -Wno-comment") - SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC -pthread -Wno-comment") - ADD_DEFINITIONS(-Wall -std=c++11 -fvisibility=hidden) -ELSE() #Windows - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") - SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /bigobj") - SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /bigobj") -ENDIF() - -FIND_PACKAGE(Lua QUIET) -IF(USE_LOCAL_LUA OR NOT LUA_FOUND) - SET(USE_LOCAL_LUA ON) - INCLUDE(${CMAKE_MODULE_PATH}/build_lua.cmake) -ELSE() - ADD_DEFINITIONS(-DLUA_COMPAT_MODULE) -ENDIF() - -FILE(GLOB src - "*.hpp" - "*.h" - "*.cpp" - ) - -FILE(GLOB funcs_src - "funcs/*.cpp" - ) - -SOURCE_GROUP(funcs FILES ${funcs_src}) - -FILE(GLOB graphics_src - "graphics/*.cpp" - ) - -SOURCE_GROUP(graphics FILES ${graphics_src}) - -FILE(GLOB methods_src - "methods/*.cpp" - ) - -SOURCE_GROUP(methods FILES ${methods_src}) - -FILE(GLOB template_src - "template/*.cpp") - -SOURCE_GROUP(template FILES ${template_src}) - -INCLUDE_DIRECTORIES(${ArrayFire_INCLUDE_DIRS}) -INCLUDE_DIRECTORIES(${LUA_INCLUDE_DIR}) - -ADD_LIBRARY(arrayfire_lib SHARED - ${src} - ${funcs_src} - ${graphics_src} - ${methods_src}) - -TARGET_LINK_LIBRARIES(arrayfire_lib - ${ArrayFire_Unified_LIBRARIES} - ${LUA_LIBRARIES} - ) - -SET_TARGET_PROPERTIES(arrayfire_lib PROPERTIES - PREFIX "") - -######################################## -# Installation -######################################## -INSTALL(TARGETS arrayfire_lib EXPORT ARRAYFIRE_LIB - DESTINATION "./" - COMPONENT libraries) diff --git a/wrapper/Lua/ReadMe.txt b/wrapper/Lua/ReadMe.txt deleted file mode 100644 index b55e772..0000000 --- a/wrapper/Lua/ReadMe.txt +++ /dev/null @@ -1,40 +0,0 @@ -======================================================================== - DYNAMIC LINK LIBRARY : arrayfire Project Overview -======================================================================== - -AppWizard has created this arrayfire DLL for you. - -This file contains a summary of what you will find in each of the files that -make up your arrayfire application. - - -arrayfire.vcxproj - This is the main project file for VC++ projects generated using an Application Wizard. - It contains information about the version of Visual C++ that generated the file, and - information about the platforms, configurations, and project features selected with the - Application Wizard. - -arrayfire.vcxproj.filters - This is the filters file for VC++ projects generated using an Application Wizard. - It contains information about the association between the files in your project - and the filters. This association is used in the IDE to show grouping of files with - similar extensions under a specific node (for e.g. ".cpp" files are associated with the - "Source Files" filter). - -arrayfire.cpp - This is the main DLL source file. - -///////////////////////////////////////////////////////////////////////////// -Other standard files: - -StdAfx.h, StdAfx.cpp - These files are used to build a precompiled header (PCH) file - named arrayfire.pch and a precompiled types file named StdAfx.obj. - -///////////////////////////////////////////////////////////////////////////// -Other notes: - -AppWizard uses "TODO:" comments to indicate parts of the source code you -should add to or customize. - -///////////////////////////////////////////////////////////////////////////// diff --git a/wrapper/Lua/args.cpp b/wrapper/Lua/args.cpp deleted file mode 100644 index 04d8976..0000000 --- a/wrapper/Lua/args.cpp +++ /dev/null @@ -1,80 +0,0 @@ -extern "C" { - #include -} - -#include "template/args.h" -#include "utils.h" - -template<> inline af_array * Out (ARRAY_PROXY & proxy) -{ - return proxy.mUD; -} - -template<> inline af_features * Out (FEATURES_PROXY & proxy) -{ - return proxy.mUD; -} - -template<> inline void Push (lua_State * L, bool b) -{ - lua_pushboolean(L, b); // ..., bool -} - -template<> inline void Push (lua_State * L, float f) -{ - lua_pushnumber(L, f); // ..., float -} - -template<> inline void Push (lua_State * L, double d) -{ - lua_pushnumber(L, d); // ..., double -} - -template<> inline void Push (lua_State * L, const char * s) -{ - lua_pushstring(L, s); // ..., string -} - -template<> inline void Push (lua_State * L, void * ptr) -{ - lua_pushlightuserdata(L, ptr); // ..., ptr -} - -template<> inline void Push (lua_State * L, ARRAY_PROXY) {} -template<> inline void Push (lua_State * L, FEATURES_PROXY) {} - -template<> inline const char * Declare (lua_State * L) -{ - return nullptr; -} - -template<> inline void * Declare (lua_State * L) -{ - return nullptr; -} - -template<> inline ARRAY_PROXY Declare (lua_State * L) -{ - ARRAY_PROXY proxy; - - proxy.mUD = NewArray(L);// ..., arr_ud - - return proxy; -} - -template<> inline FEATURES_PROXY Declare (lua_State * L) -{ - FEATURES_PROXY proxy; - - proxy.mUD = NewFeatures(L); // ..., features_ud - - return proxy; -} - -bool B (lua_State * L, int index) { return Arg(L, index); } -double D (lua_State * L, int index) { return Arg(L, index); } -float F (lua_State * L, int index) { return Arg(L, index); } -int I (lua_State * L, int index) { return Arg(L, index); } -const char * S (lua_State * L, int index) { return Arg(L, index); } -unsigned U (lua_State * L, int index) { return Arg(L, index); } -void * UD (lua_State * L, int index) { return lua_touserdata(L, index); } \ No newline at end of file diff --git a/wrapper/Lua/arrayfire.cpp b/wrapper/Lua/arrayfire.cpp deleted file mode 100644 index ef0cef5..0000000 --- a/wrapper/Lua/arrayfire.cpp +++ /dev/null @@ -1,54 +0,0 @@ -#include "export.h" -#include "funcs.h" -#include "graphics.h" -#include "methods.h" - -void Register (lua_State * L, lua_CFunction func) -{ - int top = lua_gettop(L); - - lua_pushcfunction(L, func); // ..., af, func - lua_pushvalue(L, -2); // ..., af, func, af - - if (lua_pcall(L, 1, 0, 0)) // ...[, err] - { - printf("%s\n", lua_tostring(L, -1)); - - lua_settop(L, top); // ... - } -} - -__EXPORT__ int luaopen_arrayfire_lib (lua_State * L) -{ - lua_createtable(L, 0, 0); // af - - // Library functions - Register(L, &AddEnums); - Register(L, &Backends); - Register(L, &ComputerVision); - Register(L, &ImageProcessing); - Register(L, &Interface); - Register(L, &IO); - Register(L, &LinearAlgebra); - Register(L, &Mathematics); - Register(L, &SignalProcessing); - Register(L, &Statistics); - Register(L, &Util); - Register(L, &Vector); - - // Array methods - Register(L, &AssignIndex); - Register(L, &Create); - Register(L, &Constructor); - Register(L, &Device); - Register(L, &Features); - Register(L, &Helper); - Register(L, &Methods); - Register(L, &MoveReorder); - - // Graphics functions - Register(L, &Draw); - Register(L, &Window); - - return 1; -} diff --git a/wrapper/Lua/export.h b/wrapper/Lua/export.h deleted file mode 100644 index 16746f5..0000000 --- a/wrapper/Lua/export.h +++ /dev/null @@ -1,5 +0,0 @@ -#if defined(_WIN32) || defined(_MSC_VER) -#define __EXPORT__ extern "C" __declspec(dllexport) -#else -#define __EXPORT__ extern "C" __attribute__((visibility("default"))) -#endif diff --git a/wrapper/Lua/funcs.h b/wrapper/Lua/funcs.h deleted file mode 100644 index a89dc82..0000000 --- a/wrapper/Lua/funcs.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef FUNCS_H -#define FUNCS_H - -extern "C" { - #include - #include -} - -#include "lua_compat.h" - -int AddEnums (lua_State * L); -int CreateArrayFuncs (lua_State * L); -int Backends (lua_State * L); -int ComputerVision (lua_State * L); -int ImageProcessing (lua_State * L); -int Interface (lua_State * L); -int IO (lua_State * L); -int LinearAlgebra (lua_State * L); -int Mathematics (lua_State * L); -int SignalProcessing (lua_State * L); -int Statistics (lua_State * L); -int Util (lua_State * L); -int Vector (lua_State * L); - -#endif // FUNCS_H diff --git a/wrapper/Lua/funcs/AddEnums.cpp b/wrapper/Lua/funcs/AddEnums.cpp deleted file mode 100644 index 3f35207..0000000 --- a/wrapper/Lua/funcs/AddEnums.cpp +++ /dev/null @@ -1,150 +0,0 @@ -#include "../funcs.h" -#include "af/defines.h" - -#define ENUM(name) { #name, (int)name } - -struct Enum { - const char * mName; - int mValue; -}; - -static const Enum enums[] = { - ENUM(AF_SUCCESS), - ENUM(AF_ERR_NO_MEM), - ENUM(AF_ERR_DRIVER), - ENUM(AF_ERR_RUNTIME), - ENUM(AF_ERR_INVALID_ARRAY), - ENUM(AF_ERR_ARG), - ENUM(AF_ERR_SIZE), - ENUM(AF_ERR_TYPE), - ENUM(AF_ERR_DIFF_TYPE), - ENUM(AF_ERR_BATCH), - ENUM(AF_ERR_NOT_SUPPORTED), - ENUM(AF_ERR_NOT_CONFIGURED), -#if AF_API_VERSION >= 32 - ENUM(AF_ERR_NONFREE), -#endif - ENUM(AF_ERR_NO_DBL), - ENUM(AF_ERR_NO_GFX), -#if AF_API_VERSION >= 32 - ENUM(AF_ERR_LOAD_LIB), - ENUM(AF_ERR_LOAD_SYM), - ENUM(AF_ERR_ARR_BKND_MISMATCH), -#endif - ENUM(AF_ERR_INTERNAL), - ENUM(AF_ERR_UNKNOWN), - ENUM(f32), - ENUM(c32), - ENUM(f64), - ENUM(c64), - ENUM(b8), - ENUM(s32), - ENUM(u32), - ENUM(u8), - ENUM(s64), - ENUM(u64), -#if AF_API_VERSION >= 32 - ENUM(s16), - ENUM(u16), -#endif - ENUM(afDevice), - ENUM(afHost), - ENUM(AF_INTERP_NEAREST), - ENUM(AF_INTERP_LINEAR), - ENUM(AF_INTERP_BILINEAR), - ENUM(AF_INTERP_CUBIC), - ENUM(AF_INTERP_LOWER), - ENUM(AF_PAD_ZERO), - ENUM(AF_PAD_SYM), - ENUM(AF_CONNECTIVITY_4), - ENUM(AF_CONNECTIVITY_8), - ENUM(AF_CONV_DEFAULT), - ENUM(AF_CONV_EXPAND), - ENUM(AF_CONV_AUTO), - ENUM(AF_CONV_SPATIAL), - ENUM(AF_CONV_FREQ), - ENUM(AF_SAD), - ENUM(AF_ZSAD), - ENUM(AF_LSAD), - ENUM(AF_SSD), - ENUM(AF_ZSSD), - ENUM(AF_LSSD), - ENUM(AF_NCC), - ENUM(AF_ZNCC), - ENUM(AF_SHD), -#if AF_API_VERSION >= 31 - ENUM(AF_YCC_601), - ENUM(AF_YCC_709), - ENUM(AF_YCC_2020), -#endif - ENUM(AF_GRAY), - ENUM(AF_RGB), - ENUM(AF_HSV), -#if AF_API_VERSION >= 31 - ENUM(AF_YCbCr), -#endif - ENUM(AF_MAT_NONE), - ENUM(AF_MAT_TRANS), - ENUM(AF_MAT_CTRANS), - ENUM(AF_MAT_CONJ), - ENUM(AF_MAT_UPPER), - ENUM(AF_MAT_LOWER), - ENUM(AF_MAT_DIAG_UNIT), - ENUM(AF_MAT_SYM), - ENUM(AF_MAT_POSDEF), - ENUM(AF_MAT_ORTHOG), - ENUM(AF_MAT_TRI_DIAG), - ENUM(AF_MAT_BLOCK_DIAG), - ENUM(AF_NORM_VECTOR_1), - ENUM(AF_NORM_VECTOR_INF), - ENUM(AF_NORM_VECTOR_2), - ENUM(AF_NORM_VECTOR_P), - ENUM(AF_NORM_MATRIX_1), - ENUM(AF_NORM_MATRIX_INF), - ENUM(AF_NORM_MATRIX_2), - ENUM(AF_NORM_MATRIX_L_PQ), - ENUM(AF_NORM_EUCLID), - ENUM(AF_COLORMAP_DEFAULT), - ENUM(AF_COLORMAP_SPECTRUM), - ENUM(AF_COLORMAP_COLORS), - ENUM(AF_COLORMAP_RED), - ENUM(AF_COLORMAP_MOOD), - ENUM(AF_COLORMAP_HEAT), - ENUM(AF_COLORMAP_BLUE), -#if AF_API_VERSION >= 31 - ENUM(AF_FIF_BMP), - ENUM(AF_FIF_ICO), - ENUM(AF_FIF_JPEG), - ENUM(AF_FIF_JNG), - ENUM(AF_FIF_PNG), - ENUM(AF_FIF_PPM), - ENUM(AF_FIF_PPMRAW), - ENUM(AF_FIF_TIFF), - ENUM(AF_FIF_PSD), - ENUM(AF_FIF_HDR), - ENUM(AF_FIF_EXR), - ENUM(AF_FIF_JP2), - ENUM(AF_FIF_RAW), -#endif -#if AF_API_VERSION >= 32 - ENUM(AF_HOMOGRAPHY_RANSAC), - ENUM(AF_HOMOGRAPHY_LMEDS), - ENUM(AF_BACKEND_DEFAULT), - ENUM(AF_BACKEND_CPU), - ENUM(AF_BACKEND_CUDA), - ENUM(AF_BACKEND_OPENCL), -#endif -}; - -#undef ENUM - -int AddEnums (lua_State * L) -{ - for (int i = 0; i < sizeof(enums) / sizeof(Enum); ++i) - { - lua_pushinteger(L, enums[i].mValue);// af, enum - lua_setfield(L, -2, enums[i].mName);// af = { name = enum } - } - - return 0; -} \ No newline at end of file diff --git a/wrapper/Lua/funcs/Backends.cpp b/wrapper/Lua/funcs/Backends.cpp deleted file mode 100644 index 7d8cecb..0000000 --- a/wrapper/Lua/funcs/Backends.cpp +++ /dev/null @@ -1,71 +0,0 @@ -#include "../funcs.h" -#include "../utils.h" -#include "../template/args.h" - -static const struct luaL_Reg backend_funcs[] = { -#if AF_API_VERSION >= 32 - { - "af_get_available_backends", [](lua_State * L) - { - lua_settop(L, 0); // (clear) - - int backends = 0; - - af_err err = af_get_available_backends(&backends); - - lua_pushinteger(L, err);// err - lua_pushinteger(L, backends); // err, backends - - return 2; - } - }, { - "af_get_backend_count", [](lua_State * L) - { - lua_settop(L, 0); // (clear) - - unsigned num = 1; - - af_err err = af_get_backend_count(&num); - - lua_pushinteger(L, err);// err - lua_pushinteger(L, num);// err, num - - return 2; - } - }, { - "af_get_backend_id", [](lua_State * L) - { - lua_settop(L, 1); // arr - - af_backend backend = (af_backend)0; - - af_err err = af_get_backend_id(&backend, GetArray(L, 1)); - - lua_pushinteger(L, err);// arr, err - lua_pushinteger(L, backend);// arr, err, backend - - return 2; - } - }, { - "af_set_backend", [](lua_State * L) - { - lua_settop(L, 1); // bknd - - af_err err = af_set_backend(Arg(L, 1)); - - lua_pushinteger(L, err);// bknd, err - - return 1; - } - }, -#endif - - { NULL, NULL } -}; - -int Backends (lua_State * L) -{ - luaL_register(L, NULL, backend_funcs); - - return 0; -} \ No newline at end of file diff --git a/wrapper/Lua/funcs/ComputerVision.cpp b/wrapper/Lua/funcs/ComputerVision.cpp deleted file mode 100644 index 41cd6f4..0000000 --- a/wrapper/Lua/funcs/ComputerVision.cpp +++ /dev/null @@ -1,104 +0,0 @@ -#include "../funcs.h" -#include "../utils.h" -#include "../template/out_in.h" -#include "../template/out_in2.h" -#include "../template/out2_in2.h" - -template int SIFT (lua_State * L) -{ - lua_settop(L, 8); // arr, nlayers, constrast_thr, edge_thr, init_sigma, double_input, intensity_scale, feature_ratio - - af_features * features_ud = NewFeatures(L); // arr, nlayers, constrast_thr, edge_thr, init_sigma, double_input, intensity_scale, feature_ratio, features_ud - af_array * arr_ud = NewArray(L);// arr, nlayers, constrast_thr, edge_thr, init_sigma, double_input, intensity_scale, feature_ratio, features_ud, arr_ud - - af_err err = func(features_ud, arr_ud, GetArray(L, 1), U(L, 2), F(L, 3), F(L, 4), F(L, 5), B(L, 6), F(L, 7), F(L, 8)); - - return PushErr(L, err, 2); // arr, nlayers, constrast_thr, edge_thr, init_sigma, double_input, intensity_scale, feature_ratio, err, features_ud, arr_ud -} - -template int FiveArgs (lua_State * L) -{ - lua_settop(L, 6); // arr, arg1, arg2, arg3, arg4, arg5 - - af_features * features_ud = NewFeatures(L); // arr, arg1, arg2, arg3, arg4, arg5, features_ud - - af_err err = func(features_ud, GetArray(L, 1), Arg(L, 2), Arg(L, 3), Arg(L, 4), Arg(L, 5), Arg(L, 6)); - - return PushErr(L, err); // arr, arg1, arg2, arg3, arg4, arg5, err, features_ud -} - -static const struct luaL_Reg computer_vision_funcs[] = { -#if AF_API_VERSION >= 31 - OUTIN_ARG2(dog, int, int), -#endif - { - "af_fast", FiveArgs - }, - -#if AF_API_VERSION >= 32 - { - "af_gloh", SIFT<&af_gloh> - }, -#endif - { - "af_hamming_matcher", Out2In2_Arg2 - }, -#if AF_API_VERSION >= 31 - { - "af_harris", FiveArgs - }, -#endif -#if AF_API_VERSION >= 32 - { - "af_homography", [](lua_State * L) - { - lua_settop(L, 8); // xsrc, ysrc, xdst, ydst, htype, inlier_thr, iterations, otype - - af_array * arr_ud = NewArray(L);// xsrc, ysrc, xdst, ydst, htype, inlier_thr, iterations, otype, arr_ud - - int inliers; - - af_err err = af_homography(arr_ud, &inliers, GetArray(L, 1), GetArray(L, 2), GetArray(L, 3), GetArray(L, 4), Arg(L, 5), F(L, 6), U(L, 7), Arg(L, 8)); - - lua_pushinteger(L, inliers);// xsrc, ysrc, xdst, ydst, htype, inlier_thr, iterations, otype, arr_ud, inliers - - return PushErr(L, err, 2); // xsrc, ysrc, xdst, ydst, htype, inlier_thr, iterations, otype, err, arr_ud, inliers - } - }, -#endif - { - "af_match_template", OutIn2_Arg - }, -#if AF_API_VERSION >= 31 - OUT2IN2_ARG3(nearest_neighbour, dim_t, unsigned, af_match_type), -#endif - { - "af_orb", [](lua_State * L) - { - lua_settop(L, 6); // arr, fast_thr, max_feat, scl_factor, levels, blur_img - - af_features * features_ud = NewFeatures(L); // arr, fast_thr, max_feat, scl_factor, levels, blur_img, features_ud - af_array * arr_ud = NewArray(L);// arr, fast_thr, max_feat, scl_factor, levels, blur_img, features_ud, arr_ud - - af_err err = af_orb(features_ud, arr_ud, GetArray(L, 1), F(L, 2), U(L, 3), F(L, 4), U(L, 5), B(L, 6)); - - return PushErr(L, err, 2); // arr, fast_thr, max_feat, scl_factor, levels, blur_img, err, features_ud, arr_ud - } - }, { - "af_sift", SIFT<&af_sift> - }, -#if AF_API_VERSION >= 31 - { - "af_susan", FiveArgs - }, -#endif - - { NULL, NULL } -}; - -int ComputerVision (lua_State * L) -{ - luaL_register(L, NULL, computer_vision_funcs); - - return 0; -} \ No newline at end of file diff --git a/wrapper/Lua/funcs/IO.cpp b/wrapper/Lua/funcs/IO.cpp deleted file mode 100644 index dd1e304..0000000 --- a/wrapper/Lua/funcs/IO.cpp +++ /dev/null @@ -1,131 +0,0 @@ -#include "../funcs.h" -#include "../utils.h" -#include "../template/out.h" - -static const struct luaL_Reg io_funcs[] = { -#if AF_API_VERSION >= 31 - { - "af_delete_image_memory", [](lua_State * L) - { - lua_settop(L, 1); // ptr - - af_err err = af_delete_image_memory(GetMemory(L, 1)); - - lua_pushinteger(L, err);// ptr, err - - return 1; - } - }, -#endif - OUT_ARG2(load_image, STRING_PROXY, bool), -#if AF_API_VERSION >= 31 - { - "af_load_image_memory", [](lua_State * L) - { - lua_settop(L, 1); // ptr - - af_array * arr_ud = NewArray(L);// ptr, arr_ud - - af_err err = af_load_image_memory(arr_ud, GetMemory(L, 1)); - - return PushErr(L, err); // ptr, err, arr_ud - } - }, -#endif -#if AF_API_VERSION >= 32 - { - "af_load_image_native", [](lua_State * L) - { - lua_settop(L, 1); // filename - - af_array * arr_ud = NewArray(L);// filename, arr_ud - - af_err err = af_load_image_native(arr_ud, S(L, 1)); - - return PushErr(L, err); // filename, err, arr_ud - } - }, -#endif - OUT_ARG2(read_array_index, STRING_PROXY, unsigned), - OUT_ARG2(read_array_key, STRING_PROXY, STRING_PROXY), - { - "af_read_array_key_check", [](lua_State * L) - { - lua_settop(L, 2); // filename, key - - int index = -1; - - af_err err = af_read_array_key_check(&index, S(L, 1), S(L, 2)); - - lua_pushinteger(L, err);// filename, key, err - lua_pushinteger(L, index); // filename, key, err, index - - return 2; - } - }, { - "af_save_array", [](lua_State * L) - { - lua_settop(L, 4); // key, arr, filename, append - - int index = -1; - - af_err err = af_save_array(&index, S(L, 1), GetArray(L, 2), S(L, 3), B(L, 4)); - - lua_pushinteger(L, err);// key, arr, filename, append, err - lua_pushinteger(L, index); // key, arr, filename, append, err, index - - return 2; - } - }, { - "af_save_image", [](lua_State * L) - { - lua_settop(L, 2); // filename, arr - - af_err err = af_save_image(S(L, 1), GetArray(L, 2)); - - lua_pushinteger(L, err);// filename, arr, err - - return 1; - } - }, -#if AF_API_VERSION >= 31 - { - "af_save_image_memory", [](lua_State * L) - { - lua_settop(L, 2); // arr, format - - void * ptr; - - af_err err = af_save_image_memory(&ptr, GetArray(L, 1), Arg(L, 2)); - - lua_pushinteger(L, err);// arr, format, err - lua_pushlightuserdata(L, ptr); // arr, format, err, ptr - - return 2; - } - }, -#endif -#if AF_API_VERSION >= 32 - { - "af_save_image_native", [](lua_State * L) - { - lua_settop(L, 2); // filename, arr - - af_err err = af_save_image_native(S(L, 1), GetArray(L, 2)); - - lua_pushinteger(L, err);// filename, arr, err - - return 1; - } - }, -#endif - - { NULL, NULL } -}; - -int IO (lua_State * L) -{ - luaL_register(L, NULL, io_funcs); - - return 0; -} \ No newline at end of file diff --git a/wrapper/Lua/funcs/ImageProcessing.cpp b/wrapper/Lua/funcs/ImageProcessing.cpp deleted file mode 100644 index 7203070..0000000 --- a/wrapper/Lua/funcs/ImageProcessing.cpp +++ /dev/null @@ -1,64 +0,0 @@ -#include "../funcs.h" -#include "../template/out_in.h" -#include "../template/out_in2.h" -#include "../template/out2_in.h" -#include "../template/out2_in2.h" - -static const struct luaL_Reg image_processing_funcs[] = { - OUTIN_ARG3(bilateral, float, float, bool), - OUTIN_ARG2(color_space, af_cspace_t, af_cspace_t), - OUTIN2(dilate), - OUTIN2(dilate3), - OUTIN2(erode), - OUTIN2(erode3), - { - "af_gaussian_kernel", [](lua_State * L) - { - lua_settop(L, 4); // row, col, sigma_r, sigma_c - - af_array * arr_ud = NewArray(L);// row, col, sigma_r, sigma_c, arr_ud - - af_err err = af_gaussian_kernel(arr_ud, I(L, 1), I(L, 2), D(L, 3), D(L, 4)); - - return PushErr(L, err); // row, col, sigma_r, sigma_c, err, arr_ud - } - }, - OUTIN_ARG3(gray2rgb, float, float, float), - OUTIN2(hist_equal), - OUTIN_ARG3(histogram, unsigned, double, double), - OUTIN(hsv2rgb), - OUTIN_ARG3(maxfilt, dim_t, dim_t, af_border_type), - OUTIN_ARG4(mean_shift, float, float, unsigned, bool), - OUTIN_ARG3(medfilt, dim_t, dim_t, af_border_type), - OUTIN_ARG3(minfilt, dim_t, dim_t, af_border_type), - OUTIN(rgb2hsv), - OUTIN_ARG2(regions, af_connectivity, af_dtype), - OUTIN_ARG3(resize, dim_t, dim_t, af_interp_type), - OUTIN_ARG3(rgb2gray, float, float, float), -#if AF_API_VERSION >= 31 - OUTIN_ARG(rgb2ycbcr, af_ycc_std), -#endif - OUTIN_ARG3(rotate, float, bool, af_interp_type), -#if AF_API_VERSION >= 31 - OUTIN(sat), -#endif - OUTIN_ARG5(scale, float, float, dim_t, dim_t, af_interp_type), - OUTIN_ARG6(skew, float, float, dim_t, dim_t, af_interp_type, bool), - OUT2IN_ARG(sobel_operator, unsigned), - OUTIN2_ARG4(transform, dim_t, dim_t, af_interp_type, bool), - OUTIN_ARG5(translate, float, float, dim_t, dim_t, af_interp_type), -#if AF_API_VERSION >= 31 - OUTIN_ARG7(unwrap, dim_t, dim_t, dim_t, dim_t, dim_t, dim_t, bool), - OUTIN_ARG9(wrap, dim_t, dim_t, dim_t, dim_t, dim_t, dim_t, dim_t, dim_t, bool), - OUTIN_ARG(ycbcr2rgb, af_ycc_std), -#endif - - { NULL, NULL } -}; - -int ImageProcessing (lua_State * L) -{ - luaL_register(L, NULL, image_processing_funcs); - - return 0; -} \ No newline at end of file diff --git a/wrapper/Lua/funcs/Interface.cpp b/wrapper/Lua/funcs/Interface.cpp deleted file mode 100644 index f71fbd4..0000000 --- a/wrapper/Lua/funcs/Interface.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#include - -#ifdef WANT_CUDA - #include <../cuda.h> -#endif - -#ifdef WANT_OPENCL - #include <../opencl.h> -#endif - -// ^^^ TODO: probably not right! - -#include "../funcs.h" - -static const struct luaL_Reg interface_funcs[] = { -#if AF_API_VERSION >= 32 -#if WANT_OPENCL - { - // af_err afcl_get_context (cl_context * ctx, const bool retain); - }, { - // af_err afcl_get_device_id (cl_device_id * id); - }, -#endif - -#if WANT_CUDA - { - // af_err afcu_get_native_id (int * nativeid, int id); - }, -#endif - -#if WANT_OPENCL - { - // af_err afcl_get_queue (cl_command_queue * queue, const bool retain); - }, -#endif - -#if WANT_CUDA - { - // af_err afcu_get_stream (cudaStream_t * stream, int id); - }, -#endif -#endif - - { NULL, NULL } -}; - -int Interface (lua_State * L) -{ - luaL_register(L, NULL, interface_funcs); - - return 0; -} \ No newline at end of file diff --git a/wrapper/Lua/funcs/LinearAlgebra.cpp b/wrapper/Lua/funcs/LinearAlgebra.cpp deleted file mode 100644 index 444371c..0000000 --- a/wrapper/Lua/funcs/LinearAlgebra.cpp +++ /dev/null @@ -1,112 +0,0 @@ -#include "../funcs.h" -#include "../utils.h" -#include "../template/doubles.h" -#include "../template/in.h" -#include "../template/out_in.h" -#include "../template/out_in2.h" -#include "../template/out_in3.h" - -template int Out3In (lua_State * L) -{ - lua_settop(L, 1); // arr - - af_array * out1 = NewArray(L); // arr, out1 - af_array * out2 = NewArray(L); // arr, out1, out2 - af_array * out3 = NewArray(L); // arr, out1, out2, out3 - - af_err err = func(out1, out2, out3, GetArray(L, 1)); - - return PushErr(L, err, 3); // a, err, out1, out2, out3 -} - -#define OUT3IN(name) { "af_"#name, Out3In<&af_##name> } - -static const struct luaL_Reg linear_algebra_funcs[] = { - { - "af_cholesky", [](lua_State * L) - { - lua_settop(L, 2); // arr, is_upper - - af_array * arr_ud = NewArray(L);// arr, is_upper, arr_ud - - int info = 0; - - af_err err = af_cholesky(arr_ud, &info, GetArray(L, 1), B(L, 2)); - - lua_pushinteger(L, info); // arr, is_upper, arr_ud, info - - return PushErr(L, err, 2); // arr, is_upper, err, arr_ud, info - } - }, { - "af_cholesky_inplace", [](lua_State * L) - { - lua_settop(L, 2); // arr, is_upper - - int info = 0; - - af_err err = af_cholesky_inplace(&info, GetArray(L, 1), B(L, 2)); - - lua_pushinteger(L, err);// arr, is_upper, err - lua_pushinteger(L, info); // arr, is_upper, err, info - - return 2; - } - }, - DDIN(det), - OUTIN2_ARG2(dot, af_mat_prop, af_mat_prop), - OUTIN_ARG(inverse, af_mat_prop), - OUT3IN(lu), - OUTIN_ARG(lu_inplace, bool), - OUTIN2_ARG2(matmul, af_mat_prop, af_mat_prop), - { - "af_norm", [](lua_State * L) - { - lua_settop(L, 4); // arr, type, p, q - - double norm = 0.0; - - af_err err = af_norm(&norm, GetArray(L, 1), Arg(L, 2), D(L, 3), D(L, 4)); - - lua_pushinteger(L, err);// arr, type, p, q, err - lua_pushnumber(L, norm);// arr, type, p, q, err, norm - - return 2; - } - }, - OUT3IN(qr), - OUTIN(qr_inplace), - { - "af_rank", [](lua_State * L) - { - lua_settop(L, 2); // arr, tol - - unsigned rank = 0; - - af_err err = af_rank(&rank, GetArray(L, 1), D(L, 2)); - - lua_pushinteger(L, err);// arr, tol, err - lua_pushinteger(L, rank); // arr, tol, err, rank - - return 2; - } - }, - OUTIN2_ARG(solve, af_mat_prop), - OUTIN3_ARG(solve_lu, af_mat_prop), -#if AF_API_VERSION >= 31 - OUT3IN(svd), - OUT3IN(svd_inplace), -#endif - OUTIN_ARG(transpose, bool), - IN_ARG(transpose_inplace, bool), - - { NULL, NULL } -}; - -#undef OUT3IN - -int LinearAlgebra (lua_State * L) -{ - luaL_register(L, NULL, linear_algebra_funcs); - - return 0; -} \ No newline at end of file diff --git a/wrapper/Lua/funcs/Mathematics.cpp b/wrapper/Lua/funcs/Mathematics.cpp deleted file mode 100644 index 660d799..0000000 --- a/wrapper/Lua/funcs/Mathematics.cpp +++ /dev/null @@ -1,85 +0,0 @@ -#include "../funcs.h" -#include "../template/out_in.h" -#include "../template/out_in2.h" - -#define TWO_ARGS(name) OUTIN2_ARG(name, bool) - -// -static const struct luaL_Reg math_funcs[] = { - OUTIN(abs), - OUTIN(acos), - OUTIN(acosh), - TWO_ARGS(add), - TWO_ARGS(and), - OUTIN(arg), - OUTIN(asin), - OUTIN(asinh), - OUTIN(atan), - OUTIN(atanh), - TWO_ARGS(atan2), - TWO_ARGS(bitand), - TWO_ARGS(bitor), - TWO_ARGS(bitshiftl), - TWO_ARGS(bitshiftr), - TWO_ARGS(bitxor), - OUTIN(cbrt), - OUTIN(ceil), - OUTIN(conjg), - OUTIN(cos), - OUTIN(cosh), - OUTIN(cplx), - TWO_ARGS(cplx2), - TWO_ARGS(div), - TWO_ARGS(eq), - OUTIN(erf), - OUTIN(erfc), - OUTIN(exp), - OUTIN(expm1), - OUTIN(factorial), - OUTIN(floor), - TWO_ARGS(ge), - TWO_ARGS(gt), - TWO_ARGS(hypot), - OUTIN(imag), - TWO_ARGS(le), - OUTIN(lgamma), - OUTIN(log), - OUTIN(log10), - OUTIN(log1p), - TWO_ARGS(lt), - TWO_ARGS(maxof), - TWO_ARGS(minof), - TWO_ARGS(mod), - TWO_ARGS(mul), - TWO_ARGS(neq), - OUTIN(not), - TWO_ARGS(or), - TWO_ARGS(pow), - OUTIN(real), - TWO_ARGS(rem), - TWO_ARGS(root), - OUTIN(round), -#if AF_API_VERSION >= 31 - OUTIN(sigmoid), -#endif - OUTIN(sign), - OUTIN(sin), - OUTIN(sinh), - OUTIN(sqrt), - TWO_ARGS(sub), - OUTIN(tan), - OUTIN(tanh), - OUTIN(trunc), - OUTIN(tgamma), - - { NULL, NULL } -}; - -#undef TWO_ARGS - -int Mathematics (lua_State * L) -{ - luaL_register(L, NULL, math_funcs); - - return 0; -} \ No newline at end of file diff --git a/wrapper/Lua/funcs/SignalProcessing.cpp b/wrapper/Lua/funcs/SignalProcessing.cpp deleted file mode 100644 index 4b397e5..0000000 --- a/wrapper/Lua/funcs/SignalProcessing.cpp +++ /dev/null @@ -1,57 +0,0 @@ -#include "../funcs.h" -#include "../template/in.h" -#include "../template/out_in.h" -#include "../template/out_in2.h" -#include "../template/out_in3.h" - -static const struct luaL_Reg signal_processing_funcs[] = { - OUTIN2_ARG2(approx1, af_interp_type, float), - OUTIN3_ARG2(approx2, af_interp_type, float), - OUTIN2_ARG2(convolve1, af_conv_mode, af_conv_domain), - OUTIN2_ARG2(convolve2, af_conv_mode, af_conv_domain), - OUTIN3_ARG(convolve2_sep, af_conv_mode), - OUTIN2_ARG2(convolve3, af_conv_mode, af_conv_domain), - OUTIN_ARG2(fft, double, dim_t), - OUTIN2_ARG(fft_convolve2, af_conv_mode), - OUTIN2_ARG(fft_convolve3, af_conv_mode), -#if AF_API_VERSION >= 31 - OUTIN_ARG2(fft_c2r, double, bool), - IN_ARG(fft_inplace, double), - OUTIN_ARG2(fft_r2c, double, dim_t), -#endif - OUTIN_ARG3(fft2, double, dim_t, dim_t), -#if AF_API_VERSION >= 31 - OUTIN_ARG2(fft2_c2r, double, bool), - IN_ARG(fft2_inplace, double), - OUTIN_ARG3(fft2_r2c, double, dim_t, dim_t), -#endif - OUTIN_ARG4(fft3, double, dim_t, dim_t, dim_t), -#if AF_API_VERSION >= 31 - OUTIN_ARG2(fft3_c2r, double, bool), - IN_ARG(fft3_inplace, double), - OUTIN_ARG4(fft3_r2c, double, dim_t, dim_t, dim_t), -#endif - OUTIN2(fir), - OUTIN_ARG2(ifft, double, dim_t), -#if AF_API_VERSION >= 31 - IN_ARG(ifft_inplace, double), -#endif - OUTIN_ARG3(ifft2, double, dim_t, dim_t), -#if AF_API_VERSION >= 31 - IN_ARG(ifft2_inplace, double), -#endif - OUTIN_ARG4(ifft3, double, dim_t, dim_t, dim_t), -#if AF_API_VERSION >= 31 - IN_ARG(ifft3_inplace, double), -#endif - OUTIN3(iir), - - { NULL, NULL } -}; - -int SignalProcessing (lua_State * L) -{ - luaL_register(L, NULL, signal_processing_funcs); - - return 0; -} \ No newline at end of file diff --git a/wrapper/Lua/funcs/Statistics.cpp b/wrapper/Lua/funcs/Statistics.cpp deleted file mode 100644 index f68a4d0..0000000 --- a/wrapper/Lua/funcs/Statistics.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#include "../funcs.h" -#include "../template/doubles.h" -#include "../template/out_in.h" -#include "../template/out_in2.h" - -static const struct luaL_Reg statistics_funcs[] = { - DDIN2(corrcoef), - OUTIN2_ARG(cov, bool), - OUTIN_ARG(mean, dim_t), - DDIN(mean_all), - DDIN2(mean_all_weighted), - OUTIN2_ARG(mean_weighted, dim_t), - OUTIN_ARG(median, dim_t), - DDIN(median_all), - OUTIN_ARG(stdev, dim_t), - DDIN(stdev_all), - OUTIN_ARG2(var, bool, dim_t), - DDIN_ARG(var_all, bool), - DDIN2(var_all_weighted), - OUTIN2_ARG(var_weighted, dim_t), - - { NULL, NULL } -}; - -int Statistics (lua_State * L) -{ - luaL_register(L, NULL, statistics_funcs); - - return 0; -} \ No newline at end of file diff --git a/wrapper/Lua/funcs/Util.cpp b/wrapper/Lua/funcs/Util.cpp deleted file mode 100644 index 5ab22fc..0000000 --- a/wrapper/Lua/funcs/Util.cpp +++ /dev/null @@ -1,63 +0,0 @@ -#include "../funcs.h" -#include "../template/in.h" - -static const struct luaL_Reg util_funcs[] = { - IN_NONE(print_array), -#if AF_API_VERSION >= 31 - { - "af_print_array_gen", [](lua_State * L) - { - lua_settop(L, 3); // exp, arr, precision - - af_err err = af_print_array_gen(S(L, 1), GetArray(L, 2), I(L, 3)); - - lua_pushinteger(L, err);// exp, arr, precision, err - - return 1; - } - }, { - "af_array_to_string", [](lua_State * L) - { - lua_settop(L, 4); // exp, arr, precision, transpose - - char * output; - - af_err err = af_array_to_string(&output, S(L, 1), GetArray(L, 2), I(L, 3), B(L, 4)); - - lua_pushinteger(L, err);// exp, arr, precision, transpose, err - lua_pushstring(L, output); // exp, arr, precision, transpose, output - - free(output); - - return 2; - } - }, -#endif - { - "af_get_version", [](lua_State * L) - { - lua_settop(L, 0); // (empty) - - int major, minor, patch; - - af_err err = af_get_version(&major, &minor, &patch); - - lua_pushinteger(L, err);// err - lua_pushinteger(L, major); // err, major - lua_pushinteger(L, minor); // err, major, minor - lua_pushinteger(L, patch); // err, major, minor, patch - - return 4; - } - }, - - { NULL, NULL } -}; - -int Util (lua_State * L) -{ - luaL_register(L, NULL, util_funcs); - - return 0; -} - diff --git a/wrapper/Lua/funcs/Vector.cpp b/wrapper/Lua/funcs/Vector.cpp deleted file mode 100644 index 01a7568..0000000 --- a/wrapper/Lua/funcs/Vector.cpp +++ /dev/null @@ -1,76 +0,0 @@ -#include "../funcs.h" -#include "../template/doubles.h" -#include "../template/out_in.h" -#include "../template/out_in2.h" -#include "../template/out2_in.h" -#include "../template/out2_in2.h" - -template int IAll (lua_State * L) -{ - lua_settop(L, 1); // arr - - double d1, d2; - unsigned value; - - af_err err = func(&d1, &d2, &value, GetArray(L, 1)); - - lua_pushinteger(L, err);// arr, err - lua_pushnumber(L, d1); // arr, err, d1 - lua_pushnumber(L, d2); // arr, err, d1, d2 - lua_pushinteger(L, value); // arr, err, d1, d2, value - - return 4; -} - -#define IALL(name) { "af_"#name, IAll<&af_##name> } - -static const struct luaL_Reg vector_funcs[] = { - OUTIN_ARG(accum, int), - OUTIN_ARG(all_true, int), - DDIN(all_true_all), - OUTIN_ARG(any_true, int), - DDIN(any_true_all), - OUTIN_ARG(count, int), - DDIN(count_all), - OUTIN_ARG(diff1, int), - OUTIN_ARG(diff2, int), - OUT2IN(gradient), - OUT2IN_ARG(imax, int), - IALL(imax_all), - OUT2IN_ARG(imin, int), - IALL(imin_all), - OUTIN_ARG(max, int), - DDIN(max_all), - OUTIN_ARG(min, int), - DDIN(min_all), - OUTIN_ARG(product, int), - DDIN(product_all), -#if AF_API_VERSION >= 31 - OUTIN_ARG2(product_nan, int, double), - DDIN_ARG(product_nan_all, double), -#endif - OUTIN2_ARG(set_intersect, bool), - OUTIN2_ARG(set_union, bool), - OUTIN_ARG(set_unique, bool), - OUTIN_ARG2(sort, unsigned, bool), - OUT2IN2_ARG2(sort_by_key, unsigned, bool), - OUT2IN_ARG2(sort_index, unsigned, bool), - OUTIN_ARG(sum, int), - DDIN(sum_all), -#if AF_API_VERSION >= 31 - OUTIN_ARG2(sum_nan, int, double), - DDIN_ARG(sum_nan_all, double), -#endif - OUTIN(where), - - { NULL, NULL } -}; - -#undef IALL - -int Vector (lua_State * L) -{ - luaL_register(L, NULL, vector_funcs); - - return 0; -} \ No newline at end of file diff --git a/wrapper/Lua/graphics.h b/wrapper/Lua/graphics.h deleted file mode 100644 index 1d4462e..0000000 --- a/wrapper/Lua/graphics.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef GRAPHICS_H -#define GRAPHICS_H - -extern "C" { - #include - #include -} - -#include "lua_compat.h" - -int Draw (lua_State * L); -int Window (lua_State * L); - -#endif // GRAPHICS_H diff --git a/wrapper/Lua/graphics/Draw.cpp b/wrapper/Lua/graphics/Draw.cpp deleted file mode 100644 index 8e39b88..0000000 --- a/wrapper/Lua/graphics/Draw.cpp +++ /dev/null @@ -1,111 +0,0 @@ -#include "../graphics.h" -#include "../utils.h" -#include "../template/args.h" - -class LuaCell { - af_cell mCell; - -public: - af_cell * GetCell (void) { return &mCell; } - - LuaCell (lua_State * L) - { - lua_getfield(L, -1, "row"); // ..., row - lua_getfield(L, -2, "col"); // ..., row, col - lua_getfield(L, -3, "title"); // ..., row, col, title - lua_getfield(L, -4, "cmap");// ..., row, col, title, cmap - - mCell.row = I(L, -4); - mCell.col = I(L, -3); - mCell.title = !lua_isnil(L, -1) ? lua_tostring(L, -2) : nullptr; - mCell.cmap = Arg(L, -1); - - lua_pop(L, 4); // ... - } -}; - -static const struct luaL_Reg draw_funcs[] = { - { - "af_draw_hist", [](lua_State * L) - { - lua_settop(L, 5); // window, arr, min, max, props - - LuaCell cell(L); - - af_err err = af_draw_hist(Arg(L, 1), GetArray(L, 2), D(L, 3), D(L, 4), cell.GetCell()); - - lua_pushinteger(L, err);// window, arr, min, max, props, err - - return 1; - } - }, { - "af_draw_image", [](lua_State * L) - { - lua_settop(L, 3); // window, arr, props - - LuaCell cell(L); - - af_err err = af_draw_image(Arg(L, 1), GetArray(L, 2), cell.GetCell()); - - lua_pushinteger(L, err);// window, arr, props, err - - return 1; - } - }, { - "af_draw_plot", [](lua_State * L) - { - lua_settop(L, 4); // window, x, y, props - - LuaCell cell(L); - - af_err err = af_draw_plot(Arg(L, 1), GetArray(L, 2), GetArray(L, 3), cell.GetCell()); - - lua_pushinteger(L, err);// window, x, y, props, err - - return 1; - } - }, - -#if AF_API_VERSION >= 32 - { - "af_draw_plot3", [](lua_State * L) - { - lua_settop(L, 3); // window, P, props - - LuaCell cell(L); - - af_err err = af_draw_plot3(Arg(L, 1), GetArray(L, 2), cell.GetCell()); - - lua_pushinteger(L, err);// window, x, y, props, err - - return 1; - } - }, -#endif - -#if AF_API_VERSION > 32 || (AF_API_VERSION == 32 && AF_VERSION_PATCH >= 1) - { - "af_draw_surface", [](lua_State * L) - { - lua_settop(L, 5); // window, xvals, yvals, S, props - - LuaCell cell(L); - - af_err err = af_draw_surface(Arg(L, 1), GetArray(L, 2), GetArray(L, 3), GetArray(L, 4), cell.GetCell()); - - lua_pushinteger(L, err);// window, x, y, props, err - - return 1; - } - }, -#endif - - { NULL, NULL } -}; - -int Draw (lua_State * L) -{ - luaL_register(L, NULL, draw_funcs); - - return 0; -} \ No newline at end of file diff --git a/wrapper/Lua/graphics/Window.cpp b/wrapper/Lua/graphics/Window.cpp deleted file mode 100644 index 6e7f1a1..0000000 --- a/wrapper/Lua/graphics/Window.cpp +++ /dev/null @@ -1,98 +0,0 @@ -#include -#include "../graphics.h" -#include "../template/args.h" - -template int TwoT (lua_State * L) -{ - lua_settop(L, 3); // window, u1, u2 - - af_err err = func(Arg(L, 1), Arg(L, 2), Arg(L, 3)); - - lua_pushinteger(L, err);// window, u1, u2, err - - return 1; -} - -static const struct luaL_Reg window_funcs[] = { - { - "af_create_window", [](lua_State * L) - { - lua_settop(L, 3); // width, height, title - - af_window wnd = 0; - - af_err err = af_create_window(&wnd, I(L, 1), I(L, 2), S(L, 3)); - - lua_pushinteger(L, err);// width, height, title, err - lua_pushinteger(L, wnd);// width, height, title, err, wnd - - return 2; - } - }, { - "af_destroy_window", [](lua_State * L) - { - lua_settop(L, 1); // window - - af_err err = af_destroy_window(Arg(L, 1)); - - lua_pushinteger(L, err);// window, err - - return 1; - } - }, { - "af_grid", TwoT - }, { - "af_is_window_closed", [](lua_State * L) - { - lua_settop(L, 1); // window - - bool is_closed; - - af_err err = af_is_window_closed(&is_closed, Arg(L, 1)); - - lua_pushinteger(L, err);// window, err - lua_pushboolean(L, is_closed); // window, err, is_closed - - return 2; - } - }, { - "af_set_position", TwoT - }, -#if AF_API_VERSION >= 31 - { - "af_set_size", TwoT - }, -#endif - { - "af_set_title", [](lua_State * L) - { - lua_settop(L, 2); // window, title - - af_err err = af_set_title(Arg(L, 1), lua_tostring(L, 2)); - - lua_pushinteger(L, err);// window, title, err - - return 1; - } - }, { - "af_show", [](lua_State * L) - { - lua_settop(L, 1); // window - - af_err err = af_show(Arg(L, 1)); - - lua_pushinteger(L, err);// window, err - - return 1; - } - }, - - { NULL, NULL } -}; - -int Window (lua_State * L) -{ - luaL_register(L, NULL, window_funcs); - - return 0; -} \ No newline at end of file diff --git a/wrapper/Lua/lua_compat.h b/wrapper/Lua/lua_compat.h deleted file mode 100644 index 9cc6011..0000000 --- a/wrapper/Lua/lua_compat.h +++ /dev/null @@ -1,8 +0,0 @@ -extern "C" { - #include - #include -} - -#if LUA_VERSION_NUM > 501 -#define lua_objlen(L,i) lua_rawlen(L, (i)) -#endif diff --git a/wrapper/Lua/methods.h b/wrapper/Lua/methods.h deleted file mode 100644 index 852f649..0000000 --- a/wrapper/Lua/methods.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef METHODS_H -#define METHODS_H - -extern "C" { - #include - #include -} - -#include "lua_compat.h" - -int AssignIndex (lua_State * L); -int Create (lua_State * L); -int Constructor (lua_State * L); -int Device (lua_State * L); -int Features (lua_State * L); -int Methods (lua_State * L); -int Helper (lua_State * L); -int MoveReorder (lua_State * L); - -#endif // METHODS_H diff --git a/wrapper/Lua/methods/AssignIndex.cpp b/wrapper/Lua/methods/AssignIndex.cpp deleted file mode 100644 index 1835391..0000000 --- a/wrapper/Lua/methods/AssignIndex.cpp +++ /dev/null @@ -1,172 +0,0 @@ -#include "../methods.h" -#include "../template/out_in2.h" - -template void Load (lua_State * L, T & value) {} - -template<> void Load (lua_State * L, af_seq & seq) -{ - lua_getfield(L, -1, "begin"); // ..., seq, begin - lua_getfield(L, -2, "end"); // ..., seq, begin, end - lua_getfield(L, -3, "step");// ..., seq, begin, end, step - - seq = af_make_seq(D(L, -3), D(L, -2), D(L, -1)); - - lua_pop(L, 3); // ..., seq -} - -template<> void Load (lua_State * L, af_index_t & index) -{ - lua_getfield(L, -1, "isBatch"); // ..., index, isBatch - lua_getfield(L, -2, "isSeq"); // ..., index, isBatch, isSeq - lua_getfield(L, -3, "idx"); // ..., index, isBatch, isSeq, idx - - index.isBatch = B(L, -3); - index.isSeq = B(L, -2); - - if (index.isSeq) Load(L, index.idx.seq); - - else index.idx.arr = GetArray(L, -1); - - lua_pop(L, 3); // ..., index -} - -template void LoadVector (lua_State * L, int index, std::vector & v, unsigned count) -{ - for (unsigned i = 1; i <= count; ++i) - { - lua_rawgeti(L, index, i); // ..., value - - T item; - - Load(L, item); - - v.push_back(item); - - lua_pop(L, 1); // ... - } -} - -template int Assign (lua_State * L) -{ - lua_settop(L, 4); // lhs, ndims, elems, rhs - - af_array * arr_ud = NewArray(L);// lhs, ndims, elems, rhs, arr_ud - - T count = Arg(L, 2); - - std::vector elems(count); - - LoadVector(L, 3, elems, count); - - af_err err = func(arr_ud, GetArray(L, 1), count, &elems.front(), GetArray(L, 4)); - - return PushErr(L, err); // lhs, ndims, elems, rhs, err, arr_ud -} - -template int Index (lua_State * L) -{ - lua_settop(L, 3); // arr, ndims, index - - af_array * arr_ud = NewArray(L);// arr, ndims, index, arr_ud - - T count = Arg(L, 2); - - std::vector elems(count); - - LoadVector(L, 3, elems, count); - - af_err err = func(arr_ud, GetArray(L, 1), count, &elems.front()); - - return PushErr(L, err); // arr, ndims, index, err, arr_ud -} - -#define ASSIGN(name, t, e) { "af_"#name, Assign } -#define INDEX(name, t, e) { "af_"#name, Index } - -static const struct luaL_Reg assign_index_methods[] = { - ASSIGN(assign_gen, dim_t, af_index_t), - ASSIGN(assign_seq, unsigned, af_seq), -#if AF_API_VERSION >= 32 - { - "af_create_indexers", [](lua_State * L) - { - lua_settop(L, 0); // (empty) - - af_index_t ** indexer_ud = NewIndexer(L); // indexer_ud - - af_err err = af_create_indexers(indexer_ud); - - return PushErr(L, err); // err, indexer_ud - } - }, -#endif - INDEX(index, unsigned, af_seq), - INDEX(index_gen, dim_t, af_index_t), - OUTIN2_ARG(lookup, unsigned), -#if AF_API_VERSION >= 32 - { - "af_release_indexers", [](lua_State * L) - { - lua_settop(L, 1); // indexer - - af_err err = af_release_indexers(GetIndexer(L, 1)); - - ClearIndexer(L, 1); - - lua_pushinteger(L, err);// indexer, err - - return 1; - } - }, { - "af_set_array_indexer", [](lua_State * L) - { - lua_settop(L, 3); // indexer, idx, dim - - af_err err = af_set_array_indexer(GetIndexer(L, 1), GetArray(L, 2), Arg(L, 3)); - - lua_pushinteger(L, err);// indexer, idx, dim, err - - return 1; - } - }, { - "af_set_seq_indexer", [](lua_State * L) - { - lua_settop(L, 4); // indexer, idx, dim, is_batch - lua_pushvalue(L, 2);// indexer, idx, dim, is_batch, idx - - af_seq seq; - - Load(L, seq); - - af_err err = af_set_seq_indexer(GetIndexer(L, 1), &seq, Arg(L, 3), B(L, 4)); - - lua_pushinteger(L, err);// indexer, idx, dim, is_batch, idx, err - - return 1; - } - }, { - "af_set_seq_param_indexer", [](lua_State * L) - { - lua_settop(L, 6); // indexer, begin, end, step, dim, is_batch - - af_err err = af_set_seq_param_indexer(GetIndexer(L, 1), D(L, 2), D(L, 3), D(L, 4), Arg(L, 5), B(L, 6)); - - lua_pushinteger(L, err);// indexer, begin, end, step, dim, is_batch, err - - return 1; - } - }, -#endif - - { NULL, NULL } -}; - -#undef ASSIGN -#undef INDEX - -int AssignIndex (lua_State * L) -{ - luaL_register(L, NULL, assign_index_methods); - - return 0; -} \ No newline at end of file diff --git a/wrapper/Lua/methods/Constructor.cpp b/wrapper/Lua/methods/Constructor.cpp deleted file mode 100644 index 705c3fb..0000000 --- a/wrapper/Lua/methods/Constructor.cpp +++ /dev/null @@ -1,125 +0,0 @@ -#include -#include "../funcs.h" -#include "../utils.h" -#include "../template/args.h" -#include "../template/out_in.h" - -template int Long (lua_State * L) -{ - lua_settop(L, 3); // val, ndims, dims - - LuaDims dims(L, 2); - - af_array * arr_ud = NewArray(L);// val, ndims, dims, arr_ud - - af_err err = af_constant_ulong(arr_ud, Arg(L, 1), dims.GetNDims(), dims.GetDims()); - - return PushErr(L, err); // val, ndims, dims, err, arr_ud -} - -#define LONG(name, t) { "af_"#name, Long } - -// -static const struct luaL_Reg constructor_funcs[] = { - { - "af_constant", [](lua_State * L) - { - lua_settop(L, 4); // val, ndims, dims, type - - LuaDims dt(L, 2); - - af_array * arr_ud = NewArray(L);// val, ndims, dims, type, arr_ud - - af_err err = af_constant(arr_ud, D(L, 1), dt.GetNDims(), dt.GetDims(), Arg(L, 4)); - - return PushErr(L, err); // val, ndims, dims, type, err, arr_ud - } - }, { - "af_constant_complex", [](lua_State * L) - { - lua_settop(L, 5); // real, imag, ndims, dims, type - - LuaDims dt(L, 3); - - af_array * arr_ud = NewArray(L);// real, imag, ndims, dims, type, arr_ud - - af_err err = af_constant_complex(arr_ud, D(L, 1), D(L, 2), dt.GetNDims(), dt.GetDims(), Arg(L, 5)); - - return PushErr(L, err); // real, imag, ndims, dims, type, err, arr_ud - } - }, - LONG(constant_long, intl), - LONG(constant_ulong, uintl), - OUTIN_ARG(diag_create, int), - OUTIN_ARG(diag_extract, int), - { - "af_get_seed", [](lua_State * L) - { - lua_settop(L, 0); // (empty) - - uintl seed = 0; - - af_err err = af_get_seed(&seed); - - lua_pushinteger(L, seed); // seed - - return PushErr(L, err); // err, seed - } - }, - DIMS_AND_TYPE(identity), - { - "af_iota", [](lua_State * L) - { - lua_settop(L, 5); // ndims, dims, t_ndims, tdims, type - - LuaDims dims(L, 1); - LuaDims t_dt(L, 3); - - af_array * arr_ud = NewArray(L);// ndims, dims, t_ndims, tdims, type, arr_ud - - af_err err = af_iota(arr_ud, dims.GetNDims(), dims.GetDims(), t_dt.GetNDims(), t_dt.GetDims(), Arg(L, 5)); - - return PushErr(L, err); // ndims, dims, t_ndims, tdims, type, err, arr_ud - } - }, - OUTIN_ARG(lower, bool), - DIMS_AND_TYPE(randn), - DIMS_AND_TYPE(randu), - { - "af_range", [](lua_State * L) - { - lua_settop(L, 4); // ndims, dims, seq_dim, type - - LuaDims dt(L, 1); - - af_array * arr_ud = NewArray(L);// ndims, dims, seq_dim, type, arr_ud - - af_err err = af_range(arr_ud, dt.GetNDims(), dt.GetDims(), I(L, 3), Arg(L, 4)); - - return PushErr(L, err); // ndims, dims, seq_dim, type, err, arr_ud - } - }, { - "af_set_seed", [](lua_State * L) - { - lua_settop(L, 1); // seed - - af_err err = af_set_seed(Arg(L, 1)); - - lua_pushinteger(L, err);// seed, err - - return 1; - } - }, - OUTIN_ARG(upper, bool), - - { NULL, NULL } -}; - -#undef LONG - -int Constructor (lua_State * L) -{ - luaL_register(L, NULL, constructor_funcs); - - return 0; -} \ No newline at end of file diff --git a/wrapper/Lua/methods/Create.cpp b/wrapper/Lua/methods/Create.cpp deleted file mode 100644 index ec1c27b..0000000 --- a/wrapper/Lua/methods/Create.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#include -#include "../funcs.h" -#include "../utils.h" -#include "../template/out_in.h" - -template int Create (lua_State * L) -{ - lua_settop(L, 4); // data, ndims, dims, type - - LuaDims dt(L, 2); - - af_array * arr_ud = NewArray(L);// data, ndims, dims, type, arr_ud - - LuaData arr(L, 1, 4); - - af_err err = func(arr_ud, arr.GetData(), dt.GetNDims(), dt.GetDims(), arr.GetType()); - - return PushErr(L, err); // data, ndims, dims, type, err, arr_ud -} - -#define CREATE(name) { "af_"#name, Create<&af_##name> } - -// -static const struct luaL_Reg create_funcs[] = { - CREATE(create_array), - DIMS_AND_TYPE(create_handle), - CREATE(device_array), - - { NULL, NULL } -}; - -#undef CREATE - -int Create (lua_State * L) -{ - luaL_register(L, NULL, create_funcs); - - return 0; -} \ No newline at end of file diff --git a/wrapper/Lua/methods/Device.cpp b/wrapper/Lua/methods/Device.cpp deleted file mode 100644 index bb3f648..0000000 --- a/wrapper/Lua/methods/Device.cpp +++ /dev/null @@ -1,178 +0,0 @@ -#include "../methods.h" -#include "../utils.h" -#include "../template/in.h" - -template int Alloc (lua_State * L) -{ - lua_settop(L, 1); // bytes - - void * ptr = nullptr; - - af_err err = func(&ptr, Arg(L, 1)); - - lua_pushinteger(L, err);// bytes, err - lua_pushlightuserdata(L, ptr); // bytes, err, ptr - - return 2; -} - -template int Free (lua_State * L) -{ - lua_settop(L, 1); // ptr - - af_err err = func(UD(L, 1)); - - lua_pushinteger(L, err);// ptr, err - - return 1; -} - -template int GetInt (lua_State * L) -{ - lua_settop(L, 0); // (empty) - - T value = 0; - - af_err err = func(&value); - - lua_pushinteger(L, err);// err - lua_pushinteger(L, value); // err, value - - return 2; -} - -template int IntArg (lua_State * L) -{ - lua_settop(L, 1); // arg - - af_err err = func(Arg(L, 1)); - - lua_pushinteger(L, err);// arg, err - - return 1; -} - -template int NoArgs (lua_State * L) -{ - lua_settop(L, 0); // (clear) - - af_err err = func(); - - lua_pushinteger(L, err);// err - - return 1; -} - -static const struct luaL_Reg device_methods[] = { - { - "af_alloc_device", Alloc<&af_alloc_device> - }, { - "af_alloc_pinned", Alloc<&af_alloc_pinned> - }, { - "af_device_gc", NoArgs<&af_device_gc> - }, { - "af_device_info", [](lua_State * L) - { - lua_settop(L, 0); // (empty) - - char name[256], platform[256], toolkit[256], compute[256]; - // ^^ TODO: max size? - - af_err err = af_device_info(name, platform, toolkit, compute); - - lua_pushinteger(L, err);// err - lua_pushstring(L, name);// err, name - lua_pushstring(L, platform);// err, name, platform - lua_pushstring(L, toolkit); // err, name, platform, toolkit - lua_pushstring(L, compute); // err, name, platform, toolkit, compute - - return 5; - } - }, { - "af_device_mem_info", [](lua_State * L) - { - lua_settop(L, 0); // (empty) - - size_t alloc_bytes, alloc_buffers, lock_bytes, lock_buffers; - - af_err err = af_device_mem_info(&alloc_bytes, &alloc_buffers, &lock_bytes, &lock_buffers); - - lua_pushinteger(L, err);// err - lua_pushinteger(L, alloc_bytes);// err, alloc_bytes - lua_pushinteger(L, alloc_buffers); // err, alloc_bytes, alloc_buffers - lua_pushinteger(L, lock_bytes); // err, alloc_bytes, alloc_buffers, lock_bytes - lua_pushinteger(L, lock_buffers); // err, alloc_bytes, alloc_buffers, lock_bytes, lock_buffers - - return 5; - } - }, { - "af_free_device", Free<&af_free_device> - }, { - "af_free_pinned", Free<&af_free_pinned> - }, { - "af_get_device", GetInt - }, { - "af_get_device_count", GetInt - }, { - "af_get_device_ptr", [](lua_State * L) - { - lua_settop(L, 1); // arr - - void * ptr = nullptr; - - af_err err = af_get_device_ptr(&ptr, GetArray(L, 1)); - - lua_pushinteger(L, err);// arr, err - lua_pushlightuserdata(L, ptr); // arr, err, ptr - - return 2; - } - }, { - "af_get_dbl_support", [](lua_State * L) - { - lua_settop(L, 1); // device - - bool is_available; - - af_err err = af_get_dbl_support(&is_available, I(L, 1)); - - lua_pushinteger(L, err);// device, err - lua_pushboolean(L, is_available); // device, err, is_available - - return 2; - } - }, { - "af_get_mem_step_size", GetInt - }, { - "af_info", NoArgs<&af_info> - }, - -#if AF_API_VERSION >= 31 - { - "af_lock_device_ptr", In<&af_lock_device_ptr> - }, -#endif - - { - "af_set_device", IntArg - }, { - "af_set_mem_step_size", IntArg - }, { - "af_sync", IntArg - }, - -#if AF_API_VERSION >= 31 - { - "af_unlock_device_ptr", In<&af_unlock_device_ptr> - }, -#endif - - { NULL, NULL } -}; - -int Device (lua_State * L) -{ - luaL_register(L, NULL, device_methods); - - return 0; -} \ No newline at end of file diff --git a/wrapper/Lua/methods/Features.cpp b/wrapper/Lua/methods/Features.cpp deleted file mode 100644 index 29eb580..0000000 --- a/wrapper/Lua/methods/Features.cpp +++ /dev/null @@ -1,86 +0,0 @@ -#include "../methods.h" -#include "../utils.h" -#include "../template/args.h" - -template int FeaturesProp (lua_State * L) -{ - lua_settop(L, 1); // prop - - af_array * arr_ud = NewArray(L);// prop, arr - - af_err err = func(arr_ud, GetFeatures(L, 1)); - - return PushErr(L, err); // prop, err, arr -} - -#define PROP(name) { "af_get_features_"#name, FeaturesProp<&af_get_features_##name> } - -static const struct luaL_Reg features_methods[] = { - { - "af_create_features", [](lua_State * L) - { - lua_settop(L, 1); // num - - af_features * features_ud = NewFeatures(L); // num, features_ud - - af_err err = af_create_features(features_ud, Arg(L, 1)); - - return PushErr(L, err); // num, err, features_ud - } - }, { - "af_get_features_num", [](lua_State * L) - { - lua_settop(L, 1); // features - - dim_t num; - - af_err err = af_get_features_num(&num, GetFeatures(L, 1)); - - lua_pushinteger(L, err);// features, err - lua_pushinteger(L, num);// features, err, num - - return 2; - } - }, - PROP(orientation), - PROP(score), - PROP(size), - PROP(xpos), - PROP(ypos), - { - "af_release_features", [](lua_State * L) - { - lua_settop(L, 1); // features - - af_err err = af_release_features(GetFeatures(L, 1)); - - ClearFeatures(L, 1); - - lua_pushinteger(L, err);// features, err - - return 1; - } - }, { - "af_retain_features", [](lua_State * L) - { - lua_settop(L, 1); // features - - af_features * features_ud = NewFeatures(L); // features, features_ud - - af_err err = af_retain_features(features_ud, GetFeatures(L, 1)); - - return PushErr(L, err); // features, err, features_ud - } - }, - - { NULL, NULL } -}; - -#undef PROP - -int Features (lua_State * L) -{ - luaL_register(L, NULL, features_methods); - - return 0; -} \ No newline at end of file diff --git a/wrapper/Lua/methods/Helper.cpp b/wrapper/Lua/methods/Helper.cpp deleted file mode 100644 index 60ea2a2..0000000 --- a/wrapper/Lua/methods/Helper.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#include "../methods.h" -#include "../template/out_in.h" - -// -static const struct luaL_Reg helper_methods[] = { - OUTIN_ARG(cast, af_dtype), - OUTIN(isinf), - OUTIN(iszero), - - { NULL, NULL } -}; - -int Helper (lua_State * L) -{ - luaL_register(L, NULL, helper_methods); - - return 0; -} \ No newline at end of file diff --git a/wrapper/Lua/methods/Methods.cpp b/wrapper/Lua/methods/Methods.cpp deleted file mode 100644 index ce5c399..0000000 --- a/wrapper/Lua/methods/Methods.cpp +++ /dev/null @@ -1,101 +0,0 @@ -#include -#include "../methods.h" -#include "../template/from.h" -#include "../template/in.h" -#include "../template/out_in.h" -#include "../utils.h" - -#define PRED_REG(cond) FROM_NONE(is_##cond, bool) - -// -static const struct luaL_Reg array_methods[] = { - OUTIN(copy_array), - IN_NONE(eval), -#if AF_API_VERSION >= 31 - FROM_NONE(get_data_ref_count, int), - { - "af_get_data_ptr", [](lua_State * L) - { - lua_settop(L, 2); // data, arr - - af_err err = af_get_data_ptr(lua_touserdata(L, 1), GetArray(L, 2)); - - lua_pushinteger(L, err);// arr, err - - return 1; - } - }, -#endif - { - "af_get_dims", [](lua_State * L) - { - lua_settop(L, 1); // in - - dim_t d1, d2, d3, d4; - - af_err err = af_get_dims(&d1, &d2, &d3, &d4, GetArray(L, 1)); - - lua_pushinteger(L, err);// in, err - lua_pushinteger(L, d1); // in, err, d1 - lua_pushinteger(L, d2); // in, err, d1, d2 - lua_pushinteger(L, d3); // in, err, d1, d2, d3 - lua_pushinteger(L, d4); // in, err, d1, d2, d3, d4 - - return 5; - } - }, - FROM_NONE(get_elements, dim_t), - FROM_NONE(get_numdims, unsigned), - FROM_NONE(get_type, af_dtype), - PRED_REG(empty), - PRED_REG(scalar), - PRED_REG(vector), - PRED_REG(row), - PRED_REG(column), - PRED_REG(complex), - PRED_REG(real), - PRED_REG(double), - PRED_REG(single), - PRED_REG(realfloating), - PRED_REG(floating), - PRED_REG(integer), - PRED_REG(bool), - { - "af_release_array", [](lua_State * L) - { - lua_settop(L, 1); // arr - - af_err err = af_release_array(GetArray(L, 1)); - - ClearArray(L, 1); - - lua_pushinteger(L, err);// arr, err - - return 1; - } - }, - OUTIN(retain_array), - { - "af_write_array", [](lua_State * L) - { - lua_settop(L, 4); // arr, data, bytes, src - - af_err err = af_write_array(GetArray(L, 1), GetMemory(L, 2), Arg(L, 3), Arg(L, 4)); - - lua_pushinteger(L, err);// arr, data, bytes, src, err - - return 1; - } - }, - - { NULL, NULL } -}; - -#undef PRED_REG - -int Methods (lua_State * L) -{ - luaL_register(L, NULL, array_methods); - - return 0; -} \ No newline at end of file diff --git a/wrapper/Lua/methods/MoveReorder.cpp b/wrapper/Lua/methods/MoveReorder.cpp deleted file mode 100644 index 87ce5cc..0000000 --- a/wrapper/Lua/methods/MoveReorder.cpp +++ /dev/null @@ -1,110 +0,0 @@ -#include "../methods.h" -#include "../utils.h" -#include "../template/out_in.h" -#include "../template/out_in2.h" -#include "../template/out_in3.h" - -static const struct luaL_Reg move_reorder_methods[] = { - OUTIN(flat), - OUTIN_ARG(flip, unsigned), - { - "af_join", [](lua_State * L) - { - lua_settop(L, 3); // dim, first, second - - af_array * arr_ud = NewArray(L);// dim, first, second, arr_ud - - af_err err = af_join(arr_ud, I(L, 1), GetArray(L, 2), GetArray(L, 3)); - - return PushErr(L, err); // dim, first, second, err, arr_ud - } - }, { - "af_join_many", [](lua_State * L) - { - lua_settop(L, 3); // num, narrays, inputs - - af_array * arr_ud = NewArray(L);// num, narrays, inputs, arr_ud - - unsigned count = U(L, 2); - - std::vector arrays; - - for (unsigned i = 1; i <= count; ++i) - { - lua_rawgeti(L, 3, i); // num, narrays, inputs, arr_ud, array - - arrays.push_back(GetArray(L, 5)); - - lua_pop(L, 1); // num, arrays, inputs, arr_ud - } - - af_err err = af_join_many(arr_ud, I(L, 1), count, &arrays.front()); - - return PushErr(L, err); // num, arrays, inputs, err, arr_ud - } - }, { - "af_moddims", [](lua_State * L) - { - lua_settop(L, 3); // arr, ndims, dims - - LuaDims dims(L, 2); - - af_array * arr_ud = NewArray(L);// arr, ndims, dims, arr_ud - - af_err err = af_moddims(arr_ud, GetArray(L, 1), dims.GetNDims(), dims.GetDims()); - - return PushErr(L, err); // arr, ndims, dims, err, arr_ud - } - }, - OUTIN_ARG4(reorder, unsigned, unsigned, unsigned, unsigned), -#if AF_API_VERSION >= 31 - { - "af_replace", [](lua_State * L) - { - lua_settop(L, 3); // a, cond, b - - af_err err = af_replace(GetArray(L, 1), GetArray(L, 2), GetArray(L, 3)); - - lua_pushinteger(L, err);// a, cond, b, err - - return 1; - } - }, { - "af_replace_scalar", [](lua_State * L) - { - lua_settop(L, 3); // a, cond, b - - af_err err = af_replace_scalar(GetArray(L, 1), GetArray(L, 2), D(L, 3)); - - lua_pushinteger(L, err);// a, cond, b, err - - return 1; - } - }, - OUTIN3(select), - OUTIN2_ARG(select_scalar_r, double), - { - "af_select_scalar_l", [](lua_State * L) - { - lua_settop(L, 3); // cond, a, b - - af_array * arr_ud = NewArray(L);// cond, a, b, arr_ud - - af_err err = af_select_scalar_l(arr_ud, GetArray(L, 1), D(L, 2), GetArray(L, 3)); - - return PushErr(L, err); // cond, a, b, err, arr_ud - } - }, -#endif - OUTIN_ARG4(shift, int, int, int, int), - OUTIN_ARG4(tile, unsigned, unsigned, unsigned, unsigned), - - { NULL, NULL } -}; - -int MoveReorder (lua_State * L) -{ - luaL_register(L, NULL, move_reorder_methods); - - return 0; -} \ No newline at end of file diff --git a/wrapper/Lua/template/args.h b/wrapper/Lua/template/args.h deleted file mode 100644 index 86639c4..0000000 --- a/wrapper/Lua/template/args.h +++ /dev/null @@ -1,95 +0,0 @@ -#ifndef ARGS_TEMPLATE_H -#define ARGS_TEMPLATE_H - -extern "C" { - #include - #include -} - -#include - -template -struct get_return { typedef T type; }; - -typedef struct { af_array * mUD; } ARRAY_PROXY; -typedef struct { af_features * mUD; } FEATURES_PROXY; -typedef struct { const char * mStr; } STRING_PROXY; - -template<> struct get_return { typedef af_array type; }; -template<> struct get_return { typedef af_features type; }; -template<> struct get_return { typedef char * type; }; - -template -typename get_return::type Arg (lua_State * L, int index); - -template typename get_return::type Arg (lua_State * L, int index) -{ - return (T)lua_tointeger(L, index); -} - -af_array GetArray (lua_State *, int); -af_features GetFeatures (lua_State *, int); - -template<> inline get_return::type Arg (lua_State * L, int index) -{ - return GetArray(L, index); -} - -template<> inline get_return::type Arg (lua_State * L, int index) -{ - return GetFeatures(L, index); -} - -template<> inline get_return::type Arg (lua_State * L, int index) -{ - return const_cast(lua_tostring(L, index)); -} - -template<> inline get_return::type Arg (lua_State * L, int index) -{ - return lua_toboolean(L, index); -} - -template<> inline get_return::type Arg (lua_State * L, int index) -{ - return lua_tonumber(L, index); -} - -template<> inline get_return::type Arg (lua_State * L, int index) -{ - return lua_tonumber(L, index); -} - -template -struct rtype { using _type = const T; }; - -template -struct rtype { using _type = const T *; }; - -template -using rtype_t = typename rtype::type>::_type; - -template T Declare (lua_State * L) -{ - return T(0); -} - -template R Out (T & value) -{ - return &value; -} - -template void Push (lua_State * L, T value) -{ - lua_pushinteger(L, value); // ..., value -} - -bool B (lua_State * L, int index); -double D (lua_State * L, int index); -float F (lua_State * L, int index); -int I (lua_State * L, int index); -unsigned U (lua_State * L, int index); -const char * S (lua_State * L, int index); -void * UD (lua_State * L, int index); // N.B. Does not use Arg, since these are ambiguous with af_array / af_features - -#endif diff --git a/wrapper/Lua/template/doubles.h b/wrapper/Lua/template/doubles.h deleted file mode 100644 index 425e73c..0000000 --- a/wrapper/Lua/template/doubles.h +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef DOUBLES_TEMPLATE_H -#define DOUBLES_TEMPLATE_H - -#include "../utils.h" -#include "args.h" - -template int TwoDoublesIn (lua_State * L) -{ - lua_settop(L, 1); // arr - - double d1 = 0.0, d2 = 0.0; - - af_err err = func(&d1, &d2, GetArray(L, 1)); - - lua_pushinteger(L, err);// arr, err - lua_pushnumber(L, d1); // arr, err, d1 - lua_pushnumber(L, d2); // arr, err, d1, d2 - - return 3; -} - -template int TwoDoublesInArg (lua_State * L) -{ - lua_settop(L, 2); // arr, arg - - double d1 = 0.0, d2 = 0.0; - - af_err err = func(&d1, &d2, GetArray(L, 1), Arg(L, 2)); - - lua_pushinteger(L, err);// arr, arg, err - lua_pushnumber(L, d1); // arr, arg, err, d1 - lua_pushnumber(L, d2); // arr, arg, err, d1, d2 - - return 3; -} - -template int TwoDoublesIn2 (lua_State * L) -{ - lua_settop(L, 2); // arr1, arr2 - - double d1 = 0.0, d2 = 0.0; - - af_err err = func(&d1, &d2, GetArray(L, 1), GetArray(L, 2)); - - lua_pushinteger(L, err);// arr1, arr2, err - lua_pushnumber(L, d1); // arr1, arr2, err, d1 - lua_pushnumber(L, d2); // arr1, arr2, err, d1, d2 - - return 3; -} - -#define DDIN(name) { "af_"#name, TwoDoublesIn<&af_##name> } -#define DDIN_ARG(name, t) { "af_"#name, TwoDoublesInArg } -#define DDIN2(name) { "af_"#name, TwoDoublesIn2<&af_##name> } - -#endif \ No newline at end of file diff --git a/wrapper/Lua/template/from.h b/wrapper/Lua/template/from.h deleted file mode 100644 index 3823a80..0000000 --- a/wrapper/Lua/template/from.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef FROM_TEMPLATE_H -#define FROM_TEMPLATE_H - -#include "../utils.h" -#include "args.h" - -template int From (lua_State * L) -{ - lua_settop(L, 1); // arr - - O out; // TODO: Declare... - - af_err err = func(&out, GetArray(L, 1)); - - lua_pushinteger(L, err);// arr, err - - Push(L, out); // arr, err, out - - return 2; -} - -#define FROM_NONE(name, t) { "af_"#name, From } - -#endif \ No newline at end of file diff --git a/wrapper/Lua/template/in.h b/wrapper/Lua/template/in.h deleted file mode 100644 index 924e5f9..0000000 --- a/wrapper/Lua/template/in.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef IN_TEMPLATE_H -#define IN_TEMPLATE_H - -#include "../utils.h" -#include "args.h" - -template int In (lua_State * L) -{ - lua_settop(L, 1); // in - - af_err err = func(GetArray(L, 1)); - - lua_pushinteger(L, err);// in, err - - return 1; -} - -template)> int In_Arg (lua_State * L) -{ - lua_settop(L, 2); // in, arg - - af_err err = func(GetArray(L, 1), Arg(L, 2)); - - lua_pushinteger(L, err);// in, err - - return 1; -} - -#define IN_NONE(name) { "af_"#name, In<&af_##name> } -#define IN_ARG(name, t) { "af_"#name, In_Arg } - -#endif \ No newline at end of file diff --git a/wrapper/Lua/template/out.h b/wrapper/Lua/template/out.h deleted file mode 100644 index 8829eff..0000000 --- a/wrapper/Lua/template/out.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef OUT_TEMPLATE_H -#define OUT_TEMPLATE_H - -#include "../utils.h" -#include "args.h" - -template, rtype_t)> int Out_Arg2 (lua_State * L) -{ - lua_settop(L, 2); // arg1, arg2 - - af_array * arr_ud = NewArray(L);// arg1, arg2, arr_ud - - af_err err = func(arr_ud, Arg(L, 1), Arg(L, 2)); - - return PushErr(L, err); // arg1, arg2, err, arr_ud -} - -#define OUT_ARG2(name, t1, t2) { "af_"#name, Out_Arg2 } - -#endif \ No newline at end of file diff --git a/wrapper/Lua/template/out2_in.h b/wrapper/Lua/template/out2_in.h deleted file mode 100644 index 160f84c..0000000 --- a/wrapper/Lua/template/out2_in.h +++ /dev/null @@ -1,55 +0,0 @@ -#ifndef OUT2_IN_TEMPLATE_H -#define OUT2_IN_TEMPLATE_H - -#include "../utils.h" -#include "args.h" - -template -int Out2In (lua_State * L) -{ - lua_settop(L, 1); // a - - af_array * out1 = NewArray(L); // a, out1 - af_array * out2 = NewArray(L); // a, out1, out2 - - af_err err = func(out1, out2, GetArray(L, 1)); - - return PushErr(L, err, 2); // a, err, out1, out2 - -} - -template)> -int Out2In_Arg (lua_State * L) -{ - lua_settop(L, 2); // a, arg - - af_array * out1 = NewArray(L); // a, arg, out1 - af_array * out2 = NewArray(L); // a, arg, out1, out2 - - af_err err = func(out1, out2, GetArray(L, 1), Arg(L, 2)); - - return PushErr(L, err, 2); // a, arg, err, out1, out2 - -} - -template, rtype_t)> -int Out2In_Arg2 (lua_State * L) -{ - lua_settop(L, 3); // a, arg1, arg2 - - af_array * out1 = NewArray(L); // a, arg1, arg2, out1 - af_array * out2 = NewArray(L); // a, arg1, arg2, out1, out2 - - af_err err = func(out1, out2, GetArray(L, 1), Arg(L, 2), Arg(L, 3)); - - return PushErr(L, err, 2); // a, arg1, arg2, err, out1, out2 - -} - -// ^^ TODO: Variadic template? - -#define OUT2IN(name) { "af_"#name, Out2In<&af_##name> } -#define OUT2IN_ARG(name, t) { "af_"#name, Out2In_Arg } -#define OUT2IN_ARG2(name, t1, t2) { "af_"#name, Out2In_Arg2 } - -#endif \ No newline at end of file diff --git a/wrapper/Lua/template/out2_in2.h b/wrapper/Lua/template/out2_in2.h deleted file mode 100644 index 85d757d..0000000 --- a/wrapper/Lua/template/out2_in2.h +++ /dev/null @@ -1,54 +0,0 @@ -#ifndef OUT2_IN2_TEMPLATE_H -#define OUT2_IN2_TEMPLATE_H - -#include "../utils.h" -#include "args.h" - -template)> -int Out2In2_Arg (lua_State * L) -{ - lua_settop(L, 3); // a, b, arg - - af_array * out1 = NewArray(L); // a, b, arg, out1 - af_array * out2 = NewArray(L); // a, b, arg, out1, out2 - - af_err err = func(out1, out2, GetArray(L, 1), GetArray(L, 2), Arg(L, 3)); - - return PushErr(L, err, 2); // a, b, arg, err, out1, out2 - -} - -template, rtype_t)> -int Out2In2_Arg2 (lua_State * L) -{ - lua_settop(L, 4); // a, b, arg1, arg2 - - af_array * out1 = NewArray(L); // a, b, arg1, arg2, out1 - af_array * out2 = NewArray(L); // a, b, arg1, arg2, out1, out2 - - af_err err = func(out1, out2, GetArray(L, 1), GetArray(L, 2), Arg(L, 3), Arg(L, 4)); - - return PushErr(L, err, 2); // a, b, arg1, arg2, err, out1, out2 - -} - -template, rtype_t, rtype_t)> -int Out2In2_Arg3 (lua_State * L) -{ - lua_settop(L, 5); // a, b, arg1, arg2, arg3 - - af_array * out1 = NewArray(L); // a, b, arg1, arg2, arg3, out1 - af_array * out2 = NewArray(L); // a, b, arg1, arg2, arg3, out1, out2 - - af_err err = func(out1, out2, GetArray(L, 1), GetArray(L, 2), Arg(L, 3), Arg(L, 4), Arg(L, 5)); - - return PushErr(L, err, 2); // a, b, arg1, arg2, arg3, err, out1, out2 -} - -// ^^ TODO: Variadic template? - -#define OUT2IN2_ARG(name, t) { "af_"#name, Out2In2_Arg } -#define OUT2IN2_ARG2(name, t1, t2) { "af_"#name, Out2In2_Arg2 } -#define OUT2IN2_ARG3(name, t1, t2, t3) { "af_"#name, Out2In2_Arg3 } - -#endif \ No newline at end of file diff --git a/wrapper/Lua/template/out_in.h b/wrapper/Lua/template/out_in.h deleted file mode 100644 index 9a3b74a..0000000 --- a/wrapper/Lua/template/out_in.h +++ /dev/null @@ -1,155 +0,0 @@ -#ifndef OUT_IN_TEMPLATE_H -#define OUT_IN_TEMPLATE_H - -#include "../utils.h" -#include "args.h" - -template int OutIn (lua_State * L) -{ - lua_settop(L, 1); // in - - af_array * arr_ud = NewArray(L);// in, arr_ud - - af_err err = func(arr_ud, GetArray(L, 1)); - - return PushErr(L, err); // in, err, arr_ud -} - -template)> -int OutIn_Arg (lua_State * L) -{ - lua_settop(L, 2); // a, arg - - af_array * arr_ud = NewArray(L);// a, arg, arr_ud - - af_err err = func(arr_ud, GetArray(L, 1), Arg(L, 2)); - - return PushErr(L, err); // a, arg, err, arr_ud -} - -/* -template -int Out1_In2 (lua_State * L) -{ - lua_settop(L, 2); // arg1, arg2 - - O1 out1 = Declare(L); // arg1, arg2, out1? - - af_err err = func(Out(out1), Arg(L, 1), Arg(L, 2)); - - Push(L, out1); // arg1, arg2, out1 - - return PushErr(L, err); // arg1, arg2, err, out1 -} -*/ - -template, rtype_t)> -int OutIn_Arg2 (lua_State * L) -{ - lua_settop(L, 3); // a, arg1, arg2 - - af_array * arr_ud = NewArray(L);// a, arg1, arg2, arr_ud - - af_err err = func(arr_ud, GetArray(L, 1), Arg(L, 2), Arg(L, 3)); - - return PushErr(L, err); // a, arg1, arg2, err, arr_ud -} - -template, rtype_t, rtype_t)> -int OutIn_Arg3 (lua_State * L) -{ - lua_settop(L, 4); // a, arg1, arg2, arg3 - - af_array * arr_ud = NewArray(L);// a, arg1, arg2, arg3, arr_ud - - af_err err = func(arr_ud, GetArray(L, 1), Arg(L, 2), Arg(L, 3), Arg(L, 4)); - - return PushErr(L, err); // a, arg1, arg2, arg3, err, arr_ud -} - -template, rtype_t, rtype_t, rtype_t)> -int OutIn_Arg4 (lua_State * L) -{ - lua_settop(L, 5); // a, arg1, arg2, arg3, arg4 - - af_array * arr_ud = NewArray(L);// a, arg1, arg2, arg3, arg4, arr_ud - - af_err err = func(arr_ud, GetArray(L, 1), Arg(L, 2), Arg(L, 3), Arg(L, 4), Arg(L, 5)); - - return PushErr(L, err); // a, arg1, arg2, arg3, arg4, err, arr_ud -} - -template, rtype_t, rtype_t, rtype_t, rtype_t)> -int OutIn_Arg5 (lua_State * L) -{ - lua_settop(L, 6); // a, arg1, arg2, arg3, arg4, arg5 - - af_array * arr_ud = NewArray(L);// a, arg1, arg2, arg3, arg4, arg5, arr_ud - - af_err err = func(arr_ud, GetArray(L, 1), Arg(L, 2), Arg(L, 3), Arg(L, 4), Arg(L, 5), Arg(L, 6)); - - return PushErr(L, err); // a, arg1, arg2, arg3, arg4, arg5, err, arr_ud -} - -template, rtype_t, rtype_t, rtype_t, rtype_t, rtype_t)> -int OutIn_Arg6 (lua_State * L) -{ - lua_settop(L, 7); // a, arg1, arg2, arg3, arg4, arg5, arg6 - - af_array * arr_ud = NewArray(L);// a, arg1, arg2, arg3, arg4, arg5, arg6, arr_ud - - af_err err = func(arr_ud, GetArray(L, 1), Arg(L, 2), Arg(L, 3), Arg(L, 4), Arg(L, 5), Arg(L, 6), Arg(L, 7)); - - return PushErr(L, err); // a, arg1, arg2, arg3, arg4, arg5, arg6, err, arr_ud -} - -template, rtype_t, rtype_t, rtype_t, rtype_t, rtype_t, rtype_t)> -int OutIn_Arg7 (lua_State * L) -{ - lua_settop(L, 8); // a, arg1, arg2, arg3, arg4, arg5, arg6, arg7 - - af_array * arr_ud = NewArray(L);// a, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arr_ud - - af_err err = func(arr_ud, GetArray(L, 1), Arg(L, 2), Arg(L, 3), Arg(L, 4), Arg(L, 5), Arg(L, 6), Arg(L, 7), Arg(L, 8)); - - return PushErr(L, err); // a, arg1, arg2, arg3, arg4, arg5, arg6, arg7, err, arr_ud -} - -template, rtype_t, rtype_t, rtype_t, rtype_t, rtype_t, rtype_t, rtype_t)> -int OutIn_Arg8 (lua_State * L) -{ - lua_settop(L, 9); // a, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8 - - af_array * arr_ud = NewArray(L);// a, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arr_ud - - af_err err = func(arr_ud, GetArray(L, 1), Arg(L, 2), Arg(L, 3), Arg(L, 4), Arg(L, 5), Arg(L, 6), Arg(L, 7), Arg(L, 8), Arg(L, 9)); - - return PushErr(L, err); // a, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, err, arr_ud -} - -template, rtype_t, rtype_t, rtype_t, rtype_t, rtype_t, rtype_t, rtype_t, rtype_t)> -int OutIn_Arg9 (lua_State * L) -{ - lua_settop(L, 10); // a, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 - - af_array * arr_ud = NewArray(L);// a, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arr_ud - - af_err err = func(arr_ud, GetArray(L, 1), Arg(L, 2), Arg(L, 3), Arg(L, 4), Arg(L, 5), Arg(L, 6), Arg(L, 7), Arg(L, 8), Arg(L, 9), Arg(L, 10)); - - return PushErr(L, err); // a, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, err, arr_ud -} - -// ^^ TODO: Variadic template? - -#define OUTIN(name) { "af_"#name, OutIn<&af_##name> } -#define OUTIN_ARG(name, t) { "af_"#name, OutIn_Arg } -#define OUTIN_ARG2(name, t1, t2) { "af_"#name, OutIn_Arg2 } -#define OUTIN_ARG3(name, t1, t2, t3) { "af_"#name, OutIn_Arg3 } -#define OUTIN_ARG4(name, t1, t2, t3, t4) { "af_"#name, OutIn_Arg4 } -#define OUTIN_ARG5(name, t1, t2, t3, t4, t5) { "af_"#name, OutIn_Arg5 } -#define OUTIN_ARG6(name, t1, t2, t3, t4, t5, t6) { "af_"#name, OutIn_Arg6 } -#define OUTIN_ARG7(name, t1, t2, t3, t4, t5, t6, t7) { "af_"#name, OutIn_Arg7 } -#define OUTIN_ARG8(name, t1, t2, t3, t4, t5, t6, t7, t8) { "af_"#name, OutIn_Arg8 } -#define OUTIN_ARG9(name, t1, t2, t3, t4, t5, t6, t7, t8, t9) { "af_"#name, OutIn_Arg9 } - -#endif \ No newline at end of file diff --git a/wrapper/Lua/template/out_in2.h b/wrapper/Lua/template/out_in2.h deleted file mode 100644 index c5395fa..0000000 --- a/wrapper/Lua/template/out_in2.h +++ /dev/null @@ -1,74 +0,0 @@ -#ifndef OUT_IN2_TEMPLATE_H -#define OUT_IN2_TEMPLATE_H - -#include "../utils.h" -#include "args.h" - -template int OutIn2 (lua_State * L) -{ - lua_settop(L, 2); // a, b - - af_array * arr_ud = NewArray(L);// a, b, arr_ud - - af_err err = func(arr_ud, GetArray(L, 1), GetArray(L, 2)); - - return PushErr(L, err); // a, b, err, arr_ud -} - -template)> -int OutIn2_Arg (lua_State * L) -{ - lua_settop(L, 3); // a, b, arg - - af_array * arr_ud = NewArray(L);// a, b, arg, arr_ud - - af_err err = func(arr_ud, GetArray(L, 1), GetArray(L, 2), Arg(L, 3)); - - return PushErr(L, err); // a, b, arg, err, arr_ud -} - -template, rtype_t)> -int OutIn2_Arg2 (lua_State * L) -{ - lua_settop(L, 4); // a, b, arg1, arg2 - - af_array * arr_ud = NewArray(L);// a, b, arg1, arg2, arr_ud - - af_err err = func(arr_ud, GetArray(L, 1), GetArray(L, 2), Arg(L, 3), Arg(L, 4)); - - return PushErr(L, err); // a, b, arg1, arg2, err, arr_ud -} - -template, rtype_t, rtype_t)> -int OutIn2_Arg3 (lua_State * L) -{ - lua_settop(L, 5); // a, b, arg1, arg2, arg3 - - af_array * arr_ud = NewArray(L);// a, b, arg1, arg2, arg3, arr_ud - - af_err err = func(arr_ud, GetArray(L, 1), GetArray(L, 2), Arg(L, 3), Arg(L, 4), Arg(L, 5)); - - return PushErr(L, err); // a, b, arg1, arg2, arg3, err, arr_ud -} - -template, rtype_t, rtype_t, rtype_t)> -int OutIn2_Arg4 (lua_State * L) -{ - lua_settop(L, 6); // a, b, arg1, arg2, arg3, arg4 - - af_array * arr_ud = NewArray(L);// a, b, arg1, arg2, arg3, arg4, arr_ud - - af_err err = func(arr_ud, GetArray(L, 1), GetArray(L, 2), Arg(L, 3), Arg(L, 4), Arg(L, 5), Arg(L, 6)); - - return PushErr(L, err); // a, b, arg1, arg2, arg3, arg4, err, arr_ud -} - -// ^^ TODO: Variadic template? - -#define OUTIN2(name) { "af_"#name, OutIn2<&af_##name> } -#define OUTIN2_ARG(name, t) { "af_"#name, OutIn2_Arg } -#define OUTIN2_ARG2(name, t1, t2) { "af_"#name, OutIn2_Arg2 } -#define OUTIN2_ARG3(name, t1, t2, t3) { "af_"#name, OutIn2_Arg3 } -#define OUTIN2_ARG4(name, t1, t2, t3, t4) { "af_"#name, OutIn2_Arg4 } - -#endif \ No newline at end of file diff --git a/wrapper/Lua/template/out_in3.h b/wrapper/Lua/template/out_in3.h deleted file mode 100644 index c6acf26..0000000 --- a/wrapper/Lua/template/out_in3.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef OUT_IN3_TEMPLATE_H -#define OUT_IN3_TEMPLATE_H - -#include "../utils.h" -#include "args.h" - -template int OutIn3 (lua_State * L) -{ - lua_settop(L, 3); // a, b, c - - af_array * arr_ud = NewArray(L);// a, b, c, arr_ud - - af_err err = func(arr_ud, GetArray(L, 1), GetArray(L, 2), GetArray(L, 3)); - - return PushErr(L, err); // a, b, c, err, arr_ud -} - -template)> -int OutIn3_Arg (lua_State * L) -{ - lua_settop(L, 4); // a, b, c, arg - - af_array * arr_ud = NewArray(L);// a, b, c, arg, arr_ud - - af_err err = func(arr_ud, GetArray(L, 1), GetArray(L, 2), GetArray(L, 3), Arg(L, 4)); - - return PushErr(L, err); // a, b, c, arg, err, arr_ud -} - -template, rtype_t)> -int OutIn3_Arg2 (lua_State * L) -{ - lua_settop(L, 5); // a, b, c, arg1, arg2 - - af_array * arr_ud = NewArray(L);// a, b, c, arg1, arg2, arr_ud - - af_err err = func(arr_ud, GetArray(L, 1), GetArray(L, 2), GetArray(L, 3), Arg(L, 4), Arg(L, 5)); - - return PushErr(L, err); // a, b, c, arg1, arg2, err, arr_ud -} - -// ^^ TODO: Variadic template? - -#define OUTIN3(name) { "af_"#name, OutIn3<&af_##name> } -#define OUTIN3_ARG(name, t) { "af_"#name, OutIn3_Arg } -#define OUTIN3_ARG2(name, t1, t2) { "af_"#name, OutIn3_Arg2 } - -#endif \ No newline at end of file diff --git a/wrapper/Lua/utils.cpp b/wrapper/Lua/utils.cpp deleted file mode 100644 index a859a86..0000000 --- a/wrapper/Lua/utils.cpp +++ /dev/null @@ -1,348 +0,0 @@ -#include "utils.h" -#include "lua_compat.h" - -af_dtype GetDataType (lua_State * L, int index) -{ - af_dtype types[] = { - f32, c32, f64, c64, b8, s32, u32, u8, s64, u64, -#if AF_API_VERSION >= 32 - s16, u16 -#endif - }; - - const char * names[] = { - "f32", "c32", "f64", "c64", "b8", "s32", "u32", "u8", "s64", "u64", -#if AF_API_VERSION >= 32 - "s16", "u16" -#endif - }; - - return types[luaL_checkoption(L, index, "f32", names)]; -} - -#define RESULT_CODE(what) case what: \ - lua_pushliteral(L, #what); \ - break; - -void PushResult (lua_State * L, af_err err) -{ - switch (err) - { - RESULT_CODE(AF_SUCCESS) - RESULT_CODE(AF_ERR_NO_MEM) - RESULT_CODE(AF_ERR_DRIVER) - RESULT_CODE(AF_ERR_RUNTIME) - RESULT_CODE(AF_ERR_INVALID_ARRAY) - RESULT_CODE(AF_ERR_ARG) - RESULT_CODE(AF_ERR_SIZE) - RESULT_CODE(AF_ERR_TYPE) - RESULT_CODE(AF_ERR_DIFF_TYPE) - RESULT_CODE(AF_ERR_BATCH) - RESULT_CODE(AF_ERR_NOT_SUPPORTED) - RESULT_CODE(AF_ERR_NOT_CONFIGURED) -#if AF_API_VERSION >= 32 - RESULT_CODE(AF_ERR_NONFREE) -#endif - RESULT_CODE(AF_ERR_NO_DBL) - RESULT_CODE(AF_ERR_NO_GFX) -#if AF_API_VERSION >= 32 - RESULT_CODE(AF_ERR_LOAD_LIB) - RESULT_CODE(AF_ERR_LOAD_SYM) - RESULT_CODE(AF_ERR_ARR_BKND_MISMATCH) -#endif - RESULT_CODE(AF_ERR_INTERNAL) - RESULT_CODE(AF_ERR_UNKNOWN) - } -} - -#undef RESULT_CODE - -int PushErr(lua_State * L, af_err err, int nret) -{ - lua_pushinteger(L, err);// ..., ret1, [ret2, ...], err - lua_insert(L, -(nret + 1)); // ..., err, ret1[, ret2, ...] - - return nret + 1; -} - -void * GetMemory (lua_State * L, int index) -{ - if (lua_type(L, index) == LUA_TSTRING) return (void *)lua_tostring(L, index); - - else return lua_touserdata(L, index); -} - -af_array GetArray (lua_State * L, int index) -{ - af_array * ptr_to = (af_array *)lua_touserdata(L, index); - -#ifndef NDEBUG - // Assert? (error to access after Clear...) -#endif - - return *ptr_to; -} - -af_features GetFeatures (lua_State * L, int index) -{ - af_features * ptr_to = (af_features *)lua_touserdata(L, index); - -#ifndef NDEBUG - // Assert? (ditto) -#endif - - return *ptr_to; -} - -af_index_t * GetIndexer (lua_State * L, int index) -{ - af_index_t ** ptr_to = (af_index_t **)lua_touserdata(L, index); - -#ifndef NDEBUG - // Assert? (error to access after Clear...) -#endif - - return *ptr_to; -} - -static void AddMetatable (lua_State * L, const char * name, lua_CFunction func) -{ - if (luaL_newmetatable(L, name)) // ..., object, mt - { - lua_pushcfunction(L, func); // ..., object, mt, func - lua_setfield(L, -2, "__gc");// ..., object, mt = { __gc = func } - } - - lua_setmetatable(L, -2);// ..., object -} - -af_array * NewArray (lua_State * L) -{ - void * ptr = lua_newuserdata(L, sizeof(af_array)); // ..., array - - AddMetatable(L, "af_array", [](lua_State * L) - { - lua_settop(L, 1); // array - - af_array ptr = GetArray(L, 1); - - if (ptr) af_release_array(ptr); - - ClearArray(L, 1); - - return 0; - }); - - *(af_array*)ptr = nullptr; - - return (af_array *)ptr; -} - -af_features * NewFeatures (lua_State * L) -{ - void * ptr = lua_newuserdata(L, sizeof(af_features)); // ..., features - - AddMetatable(L, "af_features", [](lua_State * L) - { - lua_settop(L, 1); // features - - af_features ptr = GetFeatures(L, 1); - - if (ptr) af_release_features(ptr); - - ClearFeatures(L, 1); - - return 0; - }); - - *(af_features*)ptr = nullptr; - - return (af_features *)ptr; -} - -af_index_t ** NewIndexer (lua_State * L) -{ - void * ptr = lua_newuserdata(L, sizeof(af_index_t *)); // ..., indexer - - AddMetatable(L, "af_index_t", [](lua_State * L) - { - lua_settop(L, 1); // indexer - - af_index_t * ptr = GetIndexer(L, 1); - - if (ptr) af_release_indexers(ptr); - - ClearIndexer(L, 1); - - return 0; - }); - - *(af_index_t **)ptr = nullptr; - - return (af_index_t **)ptr; -} - -void ClearArray (lua_State * L, int index) -{ - *(af_array *)lua_touserdata(L, index) = nullptr; -} - -void ClearFeatures (lua_State * L, int index) -{ - *(af_features *)lua_touserdata(L, index) = nullptr; -} - -void ClearIndexer (lua_State * L, int index) -{ - *(af_index_t **)lua_touserdata(L, index) = nullptr; -} - -LuaDims::LuaDims (lua_State * L, int first) -{ - luaL_checktype(L, first + 1, LUA_TTABLE); - - int n = (int)luaL_checkinteger(L, first); - - for (int i = 0; i < n; ++i) - { - lua_rawgeti(L, first + 1, i + 1); // ..., n, t, [type,] ..., dim - - mDims.push_back(lua_tointeger(L, -1)); - - lua_pop(L, 1); // ..., n, t, [type,] ... - } -} - -template void AddToVector (std::vector & arr, T value) -{ - const char * bytes = (const char *)&value; - - for (size_t i = 0; i < sizeof(T); ++i) arr.push_back(*bytes++); -} - -template void AddFloat (std::vector & arr, lua_State * L, int index, int pos) -{ - lua_rawgeti(L, index, pos + 1); // ..., arr, ..., float - - AddToVector(arr, Arg(L, -1)); - - lua_pop(L, 1); // ..., arr, ... -} - -template void AddInt (std::vector & arr, lua_State * L, int index, int pos) -{ - lua_rawgeti(L, index, pos + 1); // ..., arr, ..., int - - AddToVector(arr, Arg(L, -1)); - - lua_pop(L, 1); // ..., arr, ... -} - -template void AddComplex (std::vector & arr, lua_State * L, int index, int pos) -{ - lua_rawgeti(L, index, pos + 1); // ..., arr, ... complex - lua_rawgeti(L, -1, 1); // ..., arr, ..., complex, real - lua_rawgeti(L, -2, 2); // ..., arr, ..., complex, real, imag - - C comp(Arg(L, -2), Arg(L, -1)); - - AddToVector(arr, comp); - - lua_pop(L, 3); // ..., arr, ... -} - -LuaData::LuaData (lua_State * L, int index, int type_index, bool copy) : mDataPtr(0) -{ - mType = Arg(L, type_index); - - // Non-string: build up from Lua array. - if (!lua_isstring(L, index)) - { - int count = lua_objlen(L, index); - - switch (mType) - { - case b8: - case u8: - mData.reserve(count); - break; -#if AF_API_VERSION >= 32 - case s16: - case u16: - mData.reserve(count * 2); - break; -#endif - case f32: - case s32: - case u32: - mData.reserve(count * 4); - break; - case c32: - case f64: - case s64: - case u64: - mData.reserve(count * 8); - break; - case c64: - mData.reserve(count * 16); - break; - } - - for (int i = 0; i < count; ++i) - { - switch (mType) - { - case f32: - AddFloat(mData, L, index, i); - break; - case c32: - AddComplex(mData, L, index, i); - break; - case f64: - AddFloat(mData, L, index, i); - break; - case c64: - AddComplex(mData, L, index, i); - break; - case b8: - AddInt(mData, L, index, i); - break; -#if AF_API_VERSION >= 32 - case s16: - AddInt(mData, L, index, i); - break; - case u16: - AddInt(mData, L, index, i); - break; -#endif - case s32: - AddInt(mData, L, index, i); - break; - case u32: - AddInt(mData, L, index, i); - break; - case u8: - AddInt(mData, L, index, i); - break; - case s64: - AddInt(mData, L, index, i); - break; - case u64: - AddInt(mData, L, index, i); - break; - } - } - } - - // Already a Lua string: make a copy or simply point to it. - else - { - const char * str = lua_tostring(L, index); - - if (copy) mData.assign(str, str + lua_objlen(L, index)); - - else mDataPtr = str; - } - - if (!mDataPtr) mDataPtr = &mData.front(); -} diff --git a/wrapper/Lua/utils.h b/wrapper/Lua/utils.h deleted file mode 100644 index 609a7c5..0000000 --- a/wrapper/Lua/utils.h +++ /dev/null @@ -1,70 +0,0 @@ -#ifndef UTILS_H -#define UTILS_H - -#include "template/args.h" -#include -#include - -extern "C" { - #include - #include -} - -af_dtype GetDataType (lua_State * L, int index); - -void PushResult (lua_State * L, af_err err); - -int PushErr (lua_State * L, af_err err, int nret = 1); - -void * GetMemory (lua_State * L, int index); - -af_array GetArray (lua_State * L, int index); -af_features GetFeatures (lua_State * L, int index); -af_index_t * GetIndexer (lua_State * L, int index); - -af_array * NewArray (lua_State * L); -af_features * NewFeatures (lua_State * L); -af_index_t ** NewIndexer (lua_State * L); - -void ClearArray (lua_State * L, int index); -void ClearFeatures (lua_State * L, int index); -void ClearIndexer (lua_State * L, int index); - -class LuaDims { - std::vector mDims; - -public: - LuaDims (lua_State * L, int first); - - int GetNDims (void) const { return mDims.size(); } - const dim_t * GetDims (void) const { return &mDims.front(); } -}; - -class LuaData { - af_dtype mType; - std::vector mData; - const char * mDataPtr; - -public: - LuaData (lua_State * L, int index, int type_index, bool copy = false); - - const char * GetData (void) const { return mDataPtr; } - af_dtype GetType (void) const { return mType; } -}; - -template int DimsAndType(lua_State * L) -{ - lua_settop(L, 3); // ndims, dims, type - - LuaDims dt(L, 1); - - af_array * arr_ud = NewArray(L);// ndims, dims, type, arr_ud - - af_err err = func(arr_ud, dt.GetNDims(), dt.GetDims(), Arg(L, 3)); - - return PushErr(L, err); // ndims, dims, type, err, arr_ud -} - -#define DIMS_AND_TYPE(name) { "af_"#name, DimsAndType<&af_##name> } - -#endif diff --git a/wrapper/LuaJIT/ArrayFire.lua b/wrapper/LuaJIT/ArrayFire.lua deleted file mode 100644 index efbb806..0000000 --- a/wrapper/LuaJIT/ArrayFire.lua +++ /dev/null @@ -1,850 +0,0 @@ --- Adapted from https://github.com/malkia/ufo/blob/master/ffi/OpenCL.lua - -local ffi = require( "ffi" ) - -local name, path = "af", os.getenv("AF_PATH") .. "/" -local is_32_bit = ffi.abi("32bit") -- used to typedef dim_t - -if ArrayFireMode == "cl" or ArrayFireMode == "cuda" or ArrayFireMode == "cpu" then - name = name .. ArrayFireMode -end - -local libs = ffi_ArrayFireLibs or { - -- OSX = { x86 = path .. name, x64 = path .. name }, - Windows = { x86 = path .. name, x64 = path .. name }, - -- Linux = { x86 = path .. "lib" .. name, x64 = path .. "lib" .. name, arm = "bin/Linux/arm/lib" .. name } -} - -local lib = ffi_ArrayFire_lib or libs[ ffi.os ][ ffi.arch ] -local af = ffi.load( lib ) - -ffi.cdef[[ af_err af_get_version (int *, int *, int *); ]] - -local major, minor, patch = ffi.new("int[1]"), ffi.new("int[1]"), ffi.new("int[1]") - -af.af_get_version(major, minor, patch) - -local Version, Patch = major[0] * 10 + minor[0], patch[0] -local UsesCUDA = name == "af" or name == "afcuda" -local UsesOpenCL = name == "af" or name == "afcl" - -local def = ([[ - typedef enum { - /// - /// The function returned successfully - /// - AF_SUCCESS = 0, - - // 100-199 Errors in environment - - /// - /// The system or device ran out of memory - /// - AF_ERR_NO_MEM = 101, - - /// - /// There was an error in the device driver - /// - AF_ERR_DRIVER = 102, - - /// - /// There was an error with the runtime environment - /// - AF_ERR_RUNTIME = 103, - - // 200-299 Errors in input parameters - - /// - /// The input array is not a valid af_array object - /// - AF_ERR_INVALID_ARRAY = 201, - - /// - /// One of the function arguments is incorrect - /// - AF_ERR_ARG = 202, - - /// - /// The size is incorrect - /// - AF_ERR_SIZE = 203, - - /// - /// The type is not suppported by this function - /// - AF_ERR_TYPE = 204, - - /// - /// The type of the input arrays are not compatible - /// - AF_ERR_DIFF_TYPE = 205, - - /// - /// Function does not support GFOR / batch mode - /// - AF_ERR_BATCH = 207, - - - // 300-399 Errors for missing software features - - /// - /// The option is not supported - /// - AF_ERR_NOT_SUPPORTED = 301, - - /// - /// This build of ArrayFire does not support this feature - /// - AF_ERR_NOT_CONFIGURED = 302, - -$MIN_VERSION(32)$ - /// - /// This build of ArrayFire is not compiled with "nonfree" algorithms - /// - AF_ERR_NONFREE = 303, -$END_MIN$ - - // 400-499 Errors for missing hardware features - - /// - /// This device does not support double - /// - AF_ERR_NO_DBL = 401, - - /// - /// This build of ArrayFire was not built with graphics or this device does - /// not support graphics - /// - AF_ERR_NO_GFX = 402, - - // 500-599 Errors specific to heterogenous API - -$MIN_VERSION(32)$ - /// - /// There was an error when loading the libraries - /// - AF_ERR_LOAD_LIB = 501, - - /// - /// There was an error when loading the symbols - /// - AF_ERR_LOAD_SYM = 502, - - /// - /// There was a mismatch between the input array and the active backend - /// - AF_ERR_ARR_BKND_MISMATCH = 503, -$END_MIN$ - - // 900-999 Errors from upstream libraries and runtimes - - /// - /// There was an internal error either in ArrayFire or in a project - /// upstream - /// - AF_ERR_INTERNAL = 998, - - /// - /// Unknown Error - /// - AF_ERR_UNKNOWN = 999 - } af_err; - - typedef enum { - f32, ///< 32-bit floating point values - c32, ///< 32-bit complex floating point values - f64, ///< 64-bit complex floating point values - c64, ///< 64-bit complex floating point values - b8, ///< 8-bit boolean values - s32, ///< 32-bit signed integral values - u32, ///< 32-bit unsigned integral values - u8, ///< 8-bit unsigned integral values - s64, ///< 64-bit signed integral values - u64, ///< 64-bit unsigned integral values -$MIN_VERSION(32)$ - s16, ///< 16-bit signed integral values - u16, ///< 16-bit unsigned integral values -$END_MIN$ - } af_dtype; - - typedef enum { - afDevice, ///< Device pointer - afHost, ///< Host pointer - } af_source; - - // A handle for an internal array object - typedef void * af_array; - - typedef enum { - AF_INTERP_NEAREST, ///< Nearest Interpolation - AF_INTERP_LINEAR, ///< Linear Interpolation - AF_INTERP_BILINEAR, ///< Bilinear Interpolation - AF_INTERP_CUBIC, ///< Cubic Interpolation - AF_INTERP_LOWER ///< Floor Indexed - } af_interp_type; - - typedef enum { - /// - /// Out of bound values are 0 - /// - AF_PAD_ZERO = 0, - - /// - /// Out of bound values are symmetric over the edge - /// - AF_PAD_SYM - } af_border_type; - - typedef enum { - /// - /// Connectivity includes neighbors, North, East, South and West of current pixel - /// - AF_CONNECTIVITY_4 = 4, - - /// - /// Connectivity includes 4-connectivity neigbors and also those on Northeast, Northwest, Southeast and Southwest - /// - AF_CONNECTIVITY_8 = 8 - } af_connectivity; - - typedef enum { - - /// - /// Output of the convolution is the same size as input - /// - AF_CONV_DEFAULT, - - /// - /// Output of the convolution is signal_len + filter_len - 1 - /// - AF_CONV_EXPAND, - } af_conv_mode; - - typedef enum { - AF_CONV_AUTO, ///< ArrayFire automatically picks the right convolution algorithm - AF_CONV_SPATIAL, ///< Perform convolution in spatial domain - AF_CONV_FREQ, ///< Perform convolution in frequency domain - } af_conv_domain; - - typedef enum { - AF_SAD = 0, ///< Match based on Sum of Absolute Differences (SAD) - AF_ZSAD, ///< Match based on Zero mean SAD - AF_LSAD, ///< Match based on Locally scaled SAD - AF_SSD, ///< Match based on Sum of Squared Differences (SSD) - AF_ZSSD, ///< Match based on Zero mean SSD - AF_LSSD, ///< Match based on Locally scaled SSD - AF_NCC, ///< Match based on Normalized Cross Correlation (NCC) - AF_ZNCC, ///< Match based on Zero mean NCC - AF_SHD ///< Match based on Sum of Hamming Distances (SHD) - } af_match_type; - -$MIN_VERSION(31)$ - typedef enum { - AF_YCC_601 = 601, ///< ITU-R BT.601 (formerly CCIR 601) standard - AF_YCC_709 = 709, ///< ITU-R BT.709 standard - AF_YCC_2020 = 2020 ///< ITU-R BT.2020 standard - } af_ycc_std; -$END_MIN$ - - typedef enum { - AF_GRAY = 0, ///< Grayscale - AF_RGB, ///< 3-channel RGB - AF_HSV, ///< 3-channel HSV -$MIN_VERSION(31)$ - AF_YCbCr ///< 3-channel YCbCr -$END_MIN$ - } af_cspace_t; - - typedef enum { - AF_MAT_NONE = 0, ///< Default - AF_MAT_TRANS = 1, ///< Data needs to be transposed - AF_MAT_CTRANS = 2, ///< Data needs to be conjugate tansposed - AF_MAT_CONJ = 4, ///< Data needs to be conjugate - AF_MAT_UPPER = 32, ///< Matrix is upper triangular - AF_MAT_LOWER = 64, ///< Matrix is lower triangular - AF_MAT_DIAG_UNIT = 128, ///< Matrix diagonal contains unitary values - AF_MAT_SYM = 512, ///< Matrix is symmetric - AF_MAT_POSDEF = 1024, ///< Matrix is positive definite - AF_MAT_ORTHOG = 2048, ///< Matrix is orthogonal - AF_MAT_TRI_DIAG = 4096, ///< Matrix is tri diagonal - AF_MAT_BLOCK_DIAG = 8192 ///< Matrix is block diagonal - } af_mat_prop; - - typedef enum { - AF_NORM_VECTOR_1, ///< treats the input as a vector and returns the sum of absolute values - AF_NORM_VECTOR_INF, ///< treats the input as a vector and returns the max of absolute values - AF_NORM_VECTOR_2, ///< treats the input as a vector and returns euclidean norm - AF_NORM_VECTOR_P, ///< treats the input as a vector and returns the p-norm - AF_NORM_MATRIX_1, ///< return the max of column sums - AF_NORM_MATRIX_INF, ///< return the max of row sums - AF_NORM_MATRIX_2, ///< returns the max singular value). Currently NOT SUPPORTED - AF_NORM_MATRIX_L_PQ, ///< returns Lpq-norm - - AF_NORM_EUCLID = AF_NORM_VECTOR_2, ///< The default. Same as AF_NORM_VECTOR_2 - } af_norm_type; - - typedef enum { - AF_COLORMAP_DEFAULT = 0, ///< Default grayscale map - AF_COLORMAP_SPECTRUM= 1, ///< Spectrum map - AF_COLORMAP_COLORS = 2, ///< Colors - AF_COLORMAP_RED = 3, ///< Red hue map - AF_COLORMAP_MOOD = 4, ///< Mood map - AF_COLORMAP_HEAT = 5, ///< Heat map - AF_COLORMAP_BLUE = 6 ///< Blue hue map - } af_colormap; - -$MIN_VERSION(31)$ - typedef enum { - AF_FIF_BMP = 0, ///< FreeImage Enum for Bitmap File - AF_FIF_ICO = 1, ///< FreeImage Enum for Windows Icon File - AF_FIF_JPEG = 2, ///< FreeImage Enum for JPEG File - AF_FIF_JNG = 3, ///< FreeImage Enum for JPEG Network Graphics File - AF_FIF_PNG = 13, ///< FreeImage Enum for Portable Network Graphics File - AF_FIF_PPM = 14, ///< FreeImage Enum for Portable Pixelmap (ASCII) File - AF_FIF_PPMRAW = 15, ///< FreeImage Enum for Portable Pixelmap (Binary) File - AF_FIF_TIFF = 18, ///< FreeImage Enum for Tagged Image File Format File - AF_FIF_PSD = 20, ///< FreeImage Enum for Adobe Photoshop File - AF_FIF_HDR = 26, ///< FreeImage Enum for High Dynamic Range File - AF_FIF_EXR = 29, ///< FreeImage Enum for ILM OpenEXR File - AF_FIF_JP2 = 31, ///< FreeImage Enum for JPEG-2000 File - AF_FIF_RAW = 34 ///< FreeImage Enum for RAW Camera Image File - } af_image_format; -$END_MIN$ - -$MIN_VERSION(32)$ - typedef enum { - AF_HOMOGRAPHY_RANSAC = 0, ///< Computes homography using RANSAC - AF_HOMOGRAPHY_LMEDS = 1 ///< Computes homography using Least Median of Squares - } af_homography_type; - - // These enums should be 2^x - typedef enum { - AF_BACKEND_DEFAULT = 0, ///< Default backend order: OpenCL -> CUDA -> CPU - AF_BACKEND_CPU = 1, ///< CPU a.k.a sequential algorithms - AF_BACKEND_CUDA = 2, ///< CUDA Compute Backend - AF_BACKEND_OPENCL = 4, ///< OpenCL Compute Backend - } af_backend; -$END_MIN$ - - // Below enum is purely added for example purposes - // it doesn't and shoudn't be used anywhere in the - // code. No Guarantee's provided if it is used. - typedef enum { - AF_ID = 0 - } af_someenum_t; - - typedef ]] .. (is_32_bit and "int" or "long long") .. [[ dim_t; - - typedef long long intl; - typedef unsigned long long uintl; - - typedef void * af_features; - - typedef struct af_cfloat { - float real; - float imag; - } af_cfloat; - - typedef struct af_cdouble { - double real; - double imag; - } af_cdouble; - - typedef struct af_seq { - double begin, end; - double step; - } af_seq; - - typedef struct af_index_t{ - union { - af_array arr; ///< The af_array used for indexing - af_seq seq; ///< The af_seq used for indexing - } idx; - - bool isSeq; ///< If true the idx value represents a seq - bool isBatch; ///< If true the seq object is a batch parameter - } af_index_t; - - typedef struct { - int row; - int col; - const char* title; - af_colormap cmap; - } af_cell; - - typedef unsigned long long af_window; - -$USES_CUDA$ - typedef struct CUstream_st* cudaStream_t; -$END_USES_CUDA$ - -$USES_OPENCL$ - typedef struct _cl_device_id * cl_device_id; - typedef struct _cl_context * cl_context; - typedef struct _cl_command_queue * cl_command_queue; -$END_USES_OPENCL$ - - /* Constructors */ - af_err af_create_array (af_array *, const void * const, const unsigned, const dim_t * const, const af_dtype); - af_err af_create_handle (af_array *, const unsigned, const dim_t * const, const af_dtype); - af_err af_device_array (af_array *, const void *, const unsigned, const dim_t * const, const af_dtype) - - /* Create Array */ - af_err af_constant (af_array *, const double val, const unsigned, const dim_t * const, const af_dtype); - af_err af_constant_complex (af_array *, const double, const double, const unsigned, const dim_t * const, const af_dtype); - af_err af_constant_long (af_array *, const intl, const unsigned, const dim_t * const); - af_err af_constant_ulong (af_array *, const uintl, const unsigned, const dim_t * const); - af_err af_diag_create (af_array *, const af_array, const int); - af_err af_diag_extract (af_array *, const af_array, const int); - af_err af_get_seed (uintl *); - af_err af_identity (af_array *, const unsigned, const dim_t * const, const af_dtype); - af_err af_iota (af_array *, const unsigned, const dim_t * const, const unsigned, const dim_t * const, const af_dtype); - af_err af_lower (af_array *, const af_array, bool); - af_err af_randn (af_array *, const unsigned, const dim_t * const, const af_dtype); - af_err af_randu (af_array *, const unsigned, const dim_t * const, const af_dtype); - af_err af_range (af_array *, const unsigned, const dim_t * const, const int, const af_dtype); - af_err af_set_seed (const uintl); - af_err af_upper (af_array *, const af_array, bool); - - /* Backends */ -$MIN_VERSION(32)$ - af_err af_get_available_backends (int *); - af_err af_get_backend_count (unsigned *); - af_err af_get_backend_id (af_backend *, const af_array); - af_err af_set_backend (const af_backend); -$END_MIN$ - - /* Computer Vision */ -$MIN_VERSION(31)$ - af_err af_dog (af_array *, const af_array, const int, const int); -$END_MIN$ - af_err af_fast (af_features *, const af_array, const float, const unsigned, const bool, const float, const unsigned); -$MIN_VERSION(32)$ - af_err af_gloh (af_features *, af_array *, const af_array, const unsigned, const float, const float, const float, const bool, const float, const float); -$END_MIN$ - af_err af_hamming_matcher (af_array *, af_array *, const af_array, const af_array, const dim_t, const unsigned); -$MIN_VERSION(31)$ - af_err af_harris (af_features *, const af_array, const unsigned, const float, const float, const unsigned, const float); -$END_MIN$ -$MIN_VERSION(32)$ - af_err af_homography (af_array *, int *, const af_array, const af_array, const af_array, const af_array, const af_homography_type, const float, const unsigned, const af_dtype); -$END_MIN$ - af_err af_match_template (af_array *, const af_array, const af_array, const af_match_type); - af_err af_orb (af_features *, af_array *, const af_array, const float, const unsigned, const float, const unsigned, const bool); -$MIN_VERSION(31)$ - af_err af_nearest_neighbour (af_array *, af_array *, const af_array, const af_array, const dim_t, const unsigned, const af_match_type); - af_err af_sift (af_features *, af_array *, const af_array, const unsigned, const float, const float, const float, const bool, const float, const float); - af_err af_susan (af_features *, const af_array, const unsigned, const float, const float, const float, const unsigned); -$END_MIN$ - - /* Features */ - af_err af_create_features (af_features *, dim_t); - af_err af_get_features_num (dim_t *, const af_features); - af_err af_get_features_orientation (af_array *, const af_features); - af_err af_get_features_score (af_array *, const af_features); - af_err af_get_features_size (af_array *, const af_features); - af_err af_get_features_xpos (af_array *, const af_features); - af_err af_get_features_ypos (af_array *, const af_features); - af_err af_release_features (af_features); - af_err af_retain_features (af_features *, const af_features); - - /* Image Processing */ - af_err af_bilateral (af_array *, const af_array, const float, const float, const bool); - af_err af_color_space (af_array *, const af_array, const af_cspace_t, const af_cspace_t); - af_err af_dilate (af_array *, const af_array, const af_array); - af_err af_dilate3 (af_array *, const af_array, const af_array); - af_err af_erode (af_array *, const af_array, const af_array); - af_err af_erode3 (af_array *, const af_array, const af_array); - af_err af_gaussian_kernel (af_array *, const int, const int, const double, const double); - af_err af_gray2rgb (af_array *, const af_array, const float, const float, const float); - af_err af_hist_equal (af_array *, const af_array, const af_array); - af_err af_histogram (af_array *, const af_array, const unsigned, const double, const double); - af_err af_hsv2rgb (af_array *, const af_array); - af_err af_maxfilt (af_array *, const af_array, const dim_t, const dim_t, const af_border_type); - af_err af_mean_shift (af_array *, const af_array, const float, const float, const unsigned, const bool); - af_err af_medfilt (af_array *, const af_array, const dim_t, const dim_t, const af_border_type); - af_err af_minfilt (af_array *, const af_array, const dim_t, const dim_t, const af_border_type); - af_err af_regions (af_array *, const af_array, const af_connectivity, const af_dtype); - af_err af_resize (af_array *, const af_array, const dim_t, const dim_t, const af_interp_type); - af_err af_rgb2gray (af_array *, const af_array, const float, const float, const float); - af_err af_rgb2hsv (af_array *, const af_array); -$MIN_VERSION(31)$ - af_err af_rgb2ycbcr (af_array *, const af_array, const af_ycc_std); -$END_MIN$ - af_err af_rotate (af_array *, const af_array, const float, const bool, const af_interp_type); -$MIN_VERSION(31)$ - af_err af_sat (af_array *, const af_array); -$END_MIN$ - af_err af_scale (af_array *, const af_array, const float, const float, const dim_t, const dim_t, const af_interp_type); - af_err af_skew (af_array *, const af_array, const float, const float, const dim_t, const dim_t, const af_interp_type, const bool); - af_err af_sobel_operator (af_array *, af_array *, const af_array, const unsigned); - af_err af_transform (af_array *, const af_array, const af_array, const dim_t, const dim_t, const af_interp_type, const bool); - af_err af_translate (af_array *, const af_array, const float, const float, const dim_t, const dim_t, const af_interp_type); -$MIN_VERSION(31)$ - af_err af_unwrap (af_array *, const af_array, const dim_t, const dim_t, const dim_t, const dim_t, const dim_t, const dim_t, const bool); - af_err af_wrap (af_array *, const af_array, const dim_t, const dim_t, const dim_t, const dim_t, const dim_t, const dim_t, const dim_t, const dim_t, const bool); - af_err af_ycbcr2rgb (af_array *, const af_array, const af_ycc_std); -$END_MIN$ - - /* Interface */ -$MIN_VERSION(32)$ -$USES_OPENCL$ - af_err afcl_get_context (cl_context *, const bool); - af_err afcl_get_device_id (cl_device_id *); - af_err afcl_get_queue (cl_command_queue *, const bool); -$END_USES_OPENCL$ - -$USES_CUDA$ - af_err afcu_get_native_id (int *, int); - af_err afcu_get_stream (cudaStream_t *, int); -$END_USES_CUDA$ -$END_MIN$ - - /* IO */ -$MIN_VERSION(31)$ - af_err af_delete_image_memory (void *); -$END_MIN$ - af_err af_load_image (af_array *, const char *, const bool); -$MIN_VERSION(31)$ - af_err af_load_image_memory (af_array *, const void *); -$END_MIN$ -$MIN_VERSION(32)$ - af_err af_load_image_native (af_array *, const char *); -$END_MIN$ - af_err af_read_array_index (af_array *, const char *, const unsigned); - af_err af_read_array_key (af_array *, const char *, const char *); - af_err af_read_array_key_check (int *, const char *, const char *); - af_err af_save_array (int *, const char *, const af_array, const char *, const bool); - af_err af_save_image (const char *, const af_array); -$MIN_VERSION(31)$ - af_err af_save_image_memory (void **, const af_array, const af_image_format); -$END_MIN$ -$MIN_VERSION(32)$ - af_err af_save_image_native (const char *, const af_array); -$END_MIN$ - - /* Linear Algebra */ - af_err af_cholesky (af_array *, int *, const af_array, const bool); - af_err af_cholesky_inplace (int *, const af_array, const bool); - af_err af_det (double *, double *, const af_array); - af_err af_dot (af_array *, const af_array, const af_array, const af_mat_prop, const af_mat_prop); - af_err af_inverse (af_array *, const af_array, const af_mat_prop); - af_err af_lu (af_array *, af_array *, af_array *, const af_array); - af_err af_lu_inplace (af_array *, af_array, const bool); - af_err af_matmul (af_array *, const af_array, const af_array, const af_mat_prop, const af_mat_prop); - af_err af_norm (double *, const af_array, const af_norm_type, const double, const double); - af_err af_qr (af_array *, af_array *, af_array *, const af_array); - af_err af_qr_inplace (af_array *, af_array); - af_err af_rank (unsigned *, const af_array, const double); - af_err af_solve (af_array *, const af_array, const af_array, const af_mat_prop); - af_err af_solve_lu (af_array *, const af_array, const af_array, const af_array, const af_mat_prop); -$MIN_VERSION(31)$ - af_err af_svd (af_array *, af_array *, af_array *, const af_array); - af_err af_svd_inplace (af_array *, af_array *, af_array *, const af_array); -$END_MIN$ - af_err af_transpose (af_array *, af_array, const bool); - af_err af_transpose_inplace (af_array, const bool); - - /* Mathematics */ - af_err af_abs (af_array *, const af_array); - af_err af_acos (af_array *, const af_array); - af_err af_acosh (af_array *, const af_array); - af_err af_add (af_array *, const af_array, const af_array, const bool); - af_err af_and (af_array *, const af_array, const af_array, const bool); - af_err af_arg (af_array *, const af_array); - af_err af_asin (af_array *, const af_array); - af_err af_asinh (af_array *, const af_array); - af_err af_atan (af_array *, const af_array); - af_err af_atanh (af_array *, const af_array); - af_err af_atan2 (af_array *, const af_array, const af_array, const bool); - af_err af_bitand (af_array *, const af_array, const af_array, const bool); - af_err af_bitor (af_array *, const af_array, const af_array, const bool); - af_err af_bitshiftl (af_array *, const af_array, const af_array, const bool); - af_err af_bitshiftr (af_array *, const af_array, const af_array, const bool); - af_err af_bitxor (af_array *, const af_array, const af_array, const bool); - af_err af_cbrt (af_array *, const af_array); - af_err af_ceil (af_array *, const af_array); - af_err af_conjg (af_array *, const af_array); - af_err af_cos (af_array *, const af_array); - af_err af_cosh (af_array *, const af_array); - af_err af_cplx (af_array *, const af_array); - af_err af_cplx2 (af_array *, const af_array, const af_array, const bool); - af_err af_div (af_array *, const af_array, const af_array, const bool); - af_err af_eq (af_array *, const af_array, const af_array, const bool); - af_err af_erf (af_array *, const af_array); - af_err af_erfc (af_array *, const af_array); - af_err af_exp (af_array *, const af_array); - af_err af_expm1 (af_array *, const af_array); - af_err af_factorial (af_array *, const af_array); - af_err af_floor (af_array *, const af_array); - af_err af_ge (af_array *, const af_array, const af_array, const bool); - af_err af_gt (af_array *, const af_array, const af_array, const bool); - af_err af_hypot (af_array *, const af_array, const af_array, const bool); - af_err af_imag (af_array *, const af_array); - af_err af_le (af_array *, const af_array, const af_array, const bool); - af_err af_lgamma (af_array *, const af_array); - af_err af_lt (af_array *, const af_array, const af_array, const bool); - af_err af_log (af_array *, const af_array); - af_err af_log10 (af_array *, const af_array); - af_err af_log1p (af_array *, const af_array); - af_err af_maxof (af_array *, const af_array, const af_array, const bool); - af_err af_minof (af_array *, const af_array, const af_array, const bool); - af_err af_mod (af_array *, const af_array, const af_array, const bool); - af_err af_mul (af_array *, const af_array, const af_array, const bool); - af_err af_neq (af_array *, const af_array, const af_array, const bool); - af_err af_not (af_array *, const af_array); - af_err af_or (af_array *, const af_array, const af_array, const bool); - af_err af_pow (af_array *, const af_array, const af_array, const bool); - af_err af_real (af_array *, const af_array); - af_err af_rem (af_array *, const af_array, const af_array, const bool); - af_err af_root (af_array *, const af_array, const af_array, const bool); - af_err af_round (af_array *, const af_array); -$MIN_VERSION(31)$ - AFAPI af_err af_sigmoid (af_array *, const af_array); -$END_MIN$ - af_err af_sign (af_array *, const af_array); - af_err af_sin (af_array *, const af_array); - af_err af_sinh (af_array *, const af_array); - af_err af_sub (af_array *, const af_array, const af_array, const bool); - af_err af_sqrt (af_array *, const af_array); - af_err af_tan (af_array *, const af_array); - af_err af_tanh (af_array *, const af_array); - af_err af_trunc (af_array *, const af_array); - af_err af_tgamma (af_array *, const af_array); - - /* Signal Processing */ - af_err af_approx1 (af_array *, const af_array, const af_array, const af_interp_type, const float); - af_err af_approx2 (af_array *, const af_array, const af_array, const af_array, const af_interp_type, const float); - af_err af_convolve1 (af_array *, const af_array, const af_array, const af_conv_mode, af_conv_domain); - af_err af_convolve2 (af_array *, const af_array, const af_array, const af_conv_mode, af_conv_domain); - af_err af_convolve2_sep (af_array *, const af_array, const af_array, const af_array, const af_conv_mode); - af_err af_convolve3 (af_array *, const af_array, const af_array, const af_conv_mode, af_conv_domain); - af_err af_fft (af_array *, const af_array, const double, const dim_t); - af_err af_fft_convolve2 (af_array *, const af_array, const af_array, const af_conv_mode); - af_err af_fft_convolve3 (af_array *, const af_array, const af_array, const af_conv_mode); -$MIN_VERSION(31)$ - af_err af_fft_c2r (af_array *, const af_array, const double, const bool); - af_err af_fft_inplace (af_array, const double); - af_err af_fft_r2c (af_array *, const af_array, const double, const dim_t); -$END_MIN$ - af_err af_fft2 (af_array *, const af_array, const double, const dim_t, const dim_t); -$MINVER(31)$ - af_err af_fft2_c2r (af_array *, const af_array, const double, const bool); - af_err af_fft2_inplace (af_array, const double); - af_err af_fft2_r2c (af_array *, const af_array, const double, const dim_t, const dim_t); -$/MINVER$ - af_err af_fft3 (af_array *, const af_array, const double, const dim_t, const dim_t, const dim_t); -$MIN_VERSION(31)$ - af_err af_fft3_c2r (af_array *, const af_array, const double, const bool); - af_err af_fft3_inplace (af_array, const double); - af_err af_fft3_r2c (af_array *, const af_array, const double, const dim_t, const dim_t, const dim_t); -$END_MIN$ - af_err af_fir (af_array *, const af_array, const af_array); - af_err af_ifft (af_array *, const af_array, const double, const dim_t); -$MIN_VERSION(31)$ - af_err af_ifft_inplace (af_array, const double); -$END_MIN - af_err af_ifft2 (af_array *, const af_array, const double, const dim_t, const dim_t); -$MIN_VERSION(31)$ - af_err af_ifft2_inplace (af_array, const double); -$END_MIN$ - af_err af_ifft3 (af_array *, const af_array, const double, const dim_t, const dim_t, const dim_t); -$MIN_VERSION(31)$ - af_err af_ifft3_inplace (af_array, const double); -$END_MIN$ - af_err af_iir (af_array *, const af_array, const af_array, const af_array); - - /* Statistics */ - af_err af_corrcoef (double *, double *, const af_array, const af_array); - af_err af_cov ( af_array *, const af_array, const af_array, const bool); - af_err af_mean (af_array *, const af_array, const dim_t); - af_err af_mean_all (double *, double *, const af_array); - af_err af_mean_all_weighted (double *, double *, const af_array, const af_array); - af_err af_mean_weighted (af_array *, const af_array, const af_array, const dim_t); - af_err af_median (af_array *, const af_array, const dim_t); - af_err af_median_all (double *, double *, const af_array); - af_err af_stdev (af_array *, const af_array, const dim_t); - af_err af_stdev_all (double *, double *, const af_array); - af_err af_var (af_array *, const af_array, const bool, const dim_t); - af_err af_var_all (double *, double *, const af_array, const bool); - af_err af_var_all_weighted (double *, double *, const af_array, const af_array); - af_err af_var_weighted (af_array *, const af_array, const af_array, const dim_t); - - /* Util */ - af_err af_print_array (af_array arr); -$MIN_VERSION(31)$ - af_err af_print_array_gen (const char *, const af_array, const int); - af_err af_array_to_string (char **, const char *, const af_array, const int, const bool); -$END_MIN$ - - /* Vector */ - af_err af_accum (af_array *, const af_array, const int); - af_err af_all_true (af_array *, const af_array, const int); - af_err af_all_true_all (double *, double *, const af_array); - af_err af_any_true (af_array *, const af_array, const int); - af_err af_any_true_all (double *, double *, const af_array); - af_err af_count (af_array *, const af_array, const int); - af_err af_count_all (double *, double *, const af_array); - af_err af_diff1 (af_array *, const af_array, const int); - af_err af_diff2 (af_array *, const af_array, const int); - af_err af_gradient (af_array *, af_array *, const af_array); - af_err af_imax (af_array *, af_array *, const af_array, const int); - af_err af_imax_all (double *, double *, unsigned *, const af_array); - af_err af_imin (af_array *, af_array *, const af_array, const int); - af_err af_imin_all (double *, double *, unsigned *, const af_array); - af_err af_max (af_array *, const af_array, const int); - af_err af_max_all (double *, double *, const af_array); - af_err af_min (af_array *, const af_array, const int); - af_err af_min_all (double *, double *, const af_array); - af_err af_product (af_array *, const af_array, const int); - af_err af_product_all (double *, double *, const af_array); -$MIN_VERSION(31)$ - af_err af_product_nan (af_array *, const af_array, const int, const double); - af_err af_product_nan_all (double *, double *, const af_array, const double); -$END_MIN$ - af_err af_set_intersect (af_array *, const af_array, const af_array, const bool); - af_err af_set_union (af_array *, const af_array, const af_array, const bool); - af_err af_set_unique (af_array *, const af_array, const bool); - af_err af_sort (af_array *, const af_array, const unsigned, const bool); - af_err af_sort_by_key (af_array *, af_array *, const af_array, const af_array, const unsigned, const bool); - af_err af_sort_index (af_array *, af_array *, const af_array, const unsigned, const bool); - af_err af_sum (af_array *, const af_array, const int); - af_err af_sum_all (double *, double *, const af_array); -$MIN_VERSION(31)$ - af_err af_sum_nan (af_array *, const af_array, const int, const double); - af_err af_sum_nan_all (double *, double *, const af_array, const double); -$END_MIN$ - af_err af_where (af_array *, const af_array); - - /* Array Methods */ - af_err af_copy_array (af_array *, const af_array); - af_err af_eval (af_array); -$MIN_VERSION(31)$ - af_err af_get_data_ref_count (int *, const af_array); -$END_MIN$ - af_err af_get_dims (dim_t *, dim_t *, dim_t *, dim_t *, const af_array); - af_err af_get_elements (dim_t *, const af_array); - af_err af_get_data_ptr (void *, const af_array); - af_err af_get_numdims (unsigned *, const af_array); - af_err af_get_type (af_dtype *, const af_array); - af_err af_is_bool (bool *, const af_array); - af_err af_is_column (bool *, const af_array); - af_err af_is_complex (bool *, const af_array); - af_err af_is_double (bool *, const af_array); - af_err af_is_empty (bool *, const af_array); - af_err af_is_floating (bool *, const af_array); - af_err af_is_integer (bool *, const af_array); - af_err af_is_real (bool *, const af_array); - af_err af_is_realfloating (bool *, const af_array); - af_err af_is_row (bool *, const af_array); - af_err af_is_scalar (bool *, const af_array); - af_err af_is_single (bool *, const af_array); - af_err af_is_vector (bool *, const af_array); - af_err af_release_array (af_array); - af_err af_retain_array (af_array *, const af_array); - af_err af_write_array (af_array, const void *, const size_t, af_source); - - /* Assign / Index */ - af_err af_assign_gen (af_array *, const af_array, const dim_t, const af_index_t *, const af_array); - af_err af_assign_seq (af_array *, const af_array, const unsigned, const af_seq * const, const af_array); -$MIN_VERSION(32)$ - af_err af_create_indexers (af_index_t **); -$END_MIN$ - af_err af_index (af_array *, const af_array, const unsigned, const af_seq * const); - af_err af_index_gen (af_array *, const af_array, const dim_t, const af_index_t *); - af_err af_lookup (af_array *, const af_array, const af_array, const unsigned); -$MIN_VERSION(32)$ - af_err af_release_indexers (af_index_t *); - af_err af_set_array_indexer (af_index_t *, const af_array, const dim_t); - af_err af_set_seq_indexer (af_index_t *, const af_seq *, const dim_t, const bool); - af_err af_set_seq_param_indexer (af_index_t *, const double, const double, const double, const dim_t, const bool); -$END_MIN$ - af_seq af_make_seq (double, double, double); - - static const af_seq af_span = {1, 1, 0}; - - /* Device */ - af_err af_alloc_device (void **, const dim_t); - af_err af_alloc_pinned (void **, const dim_t); - af_err af_device_gc (); - af_err af_device_info (char *, char *, char *, char *); - af_err af_device_mem_info (size_t *, size_t *, size_t *, size_t *); - af_err af_free_device (void *); - af_err af_free_pinned (void *); - af_err af_get_device (int *); - af_err af_get_device_count (int *); - af_err af_get_device_ptr (void **, const af_array); - af_err af_get_dbl_support (bool *, const int); - af_err af_get_mem_step_size (size_t *); - af_err af_info (); -$MIN_VERSION(31)$ - af_err af_lock_device_ptr (const af_array); -$END_MIN$ - af_err af_set_device (const int); - af_err af_set_mem_step_size (const size_t); - af_err af_sync (const int); -$MIN_VERSION(31)$ - af_err af_unlock_device_ptr (const af_array); -$END_MIN$ - - /* Helper */ - af_err af_cast (af_array *, const af_array, const af_dtype); - af_err af_isinf (af_array *, const af_array); - af_err af_iszero (af_array *, const af_array); - - /* Move / Reorder */ - af_err af_flat (af_array *, const af_array); - af_err af_flip (af_array *, const af_array, const unsigned); - af_err af_join (af_array *, const int, const af_array, const af_array); - af_err af_join_many (af_array *, const int, const unsigned, const af_array *); - af_err af_moddims (af_array *, const af_array, const unsigned, const dim_t *); - af_err af_reorder (af_array *, const af_array, const unsigned, const unsigned, const unsigned, const unsigned); -$MIN_VERSION(31)$ - af_err af_replace (af_array, const af_array, const af_array); - af_err af_replace_scalar (af_array, const af_array, const double); - af_err af_select (af_array *, const af_array, const af_array, const af_array); - af_err af_select_scalar_r (af_array *, const af_array, const af_array, const double); - af_err af_select_scalar_l (af_array *, const af_array, const double, const af_array); -$END_MIN$ - af_err af_shift (af_array *, const af_array, const int, const int, const int, const int); - af_err af_tile (af_array *, const af_array, const unsigned, const unsigned, const unsigned, const unsigned); - - /* Draw */ - af_err af_draw_hist (const af_window, const af_array, const double, const double, const af_cell *); - af_err af_draw_image (const af_window, const af_array, const af_cell *); - af_err af_draw_plot (const af_window, const af_array, const af_array, const af_cell *); -$MIN_VERSION(32)$ - af_err af_draw_plot3 (const af_window, const af_array, const af_cell *); -$END_MIN$ -$MIN_VERSION(32.1)$ - af_err af_draw_surface (const af_window, const af_array, const af_array, const af_array, const af_cell *); -$END_MIN$ - - /* Window */ - af_err af_create_window (af_window *, const int, const int, const char * const); - af_err af_destroy_window (const af_window); - af_err af_grid (const af_window, const int, const int); - af_err af_is_window_closed (bool *, const af_window); - af_err af_set_position (const af_window, const unsigned, const unsigned); -$MIN_VERSION(31)$ - af_err af_set_size (const af_window, const unsigned, const unsigned); -$END_MIN$ - af_err af_set_title (const af_window, const char * const); - af_err af_show (const af_window); -]]):gsub("%$MIN_VERSION%((%d+)%.?(%d*)%)%$(.-)%$END_MIN%$", function (version, patch_id, code) - version, patch_id = tonumber(version), tonumber(patch_id) or -1 - - if Version >= version and (Version > version or Patch >= patch_id) then - return code - else - return "" - end -end):gsub("%$USES_CUDA%$(.-)%END_USES_CUDA%$", function (code) -- strip CUDA if not supported - return UsesCUDA and code or "" -end):gsub("%$USES_OPENCL%$(.-)%$END_USES_OPENCL%$", function (code) -- strip OpenCL if not supported - return UsesOpenCL and code or "" -end) - -ffi.cdef(def) - -return af \ No newline at end of file diff --git a/wrapper/arrayfire/arrayfire.lua b/wrapper/arrayfire/arrayfire.lua deleted file mode 100644 index e8c5b5e..0000000 --- a/wrapper/arrayfire/arrayfire.lua +++ /dev/null @@ -1,33 +0,0 @@ ---- Library entry point. - --- Modules -- -require("impl.array") - --- Exports -- -local M = {} - --- -for _, v in ipairs{ - "funcs.image", - "funcs.io", - "funcs.linear_algebra", - "funcs.mathematics", - "funcs.signal_processing", - "funcs.static", - "funcs.statistics", - "funcs.util", - "funcs.vector", - "funcs.gfor", - "graphics.window", - "methods.constructors", - "methods.device", - "methods.move_reorder", - "misc.env_loop", - "misc.program", - "misc.imports" -} do - require(v).Add(M) -end - --- Export the module. -return M \ No newline at end of file diff --git a/wrapper/arrayfire/funcs/gfor.lua b/wrapper/arrayfire/funcs/gfor.lua deleted file mode 100644 index a366a51..0000000 --- a/wrapper/arrayfire/funcs/gfor.lua +++ /dev/null @@ -1,68 +0,0 @@ ---- gfor() mechanism. - --- Standard library imports -- -local assert = assert - --- Modules -- -local array = require("impl.array") - --- Imports -- -local GetLib = array.GetLib - --- Exports -- -local M = {} - ---- See also: https://github.com/arrayfire/arrayfire/blob/devel/include/af/gfor.h --- https://github.com/arrayfire/arrayfire/blob/devel/src/api/cpp/gfor.cpp - --- -- -local Status = false - --- -local function AuxGfor (seq) - Status = not Status - - if Status then - return seq - end -end - --- -function M.Add (into) - for k, v in pairs{ - -- - batchFunc = function(lhs, rhs, func) - assert(not Status, "batchFunc can not be used inside GFOR") -- TODO: AF_ERR_ARG - - Status = true - - local res = func(lhs, rhs) - - Status = false - - return res - end, - - -- - gfor = function(...) - local lib = GetLib() - - return AuxGfor, lib.seq(lib.seq(...), true) - end, - - -- - gforGet = function() - return Status - end, - - -- - gforSet = function(val) - Status = not not val - end - } do - into[k] = v - end -end - --- Export the module. -return M \ No newline at end of file diff --git a/wrapper/arrayfire/funcs/image.lua b/wrapper/arrayfire/funcs/image.lua deleted file mode 100644 index 390d3e0..0000000 --- a/wrapper/arrayfire/funcs/image.lua +++ /dev/null @@ -1,41 +0,0 @@ ---- Image-related functions. - --- Modules -- -local array = require("impl.array") - --- Imports -- -local CallWrap = array.CallWrap - --- Exports -- -local M = {} - --- See also: https://github.com/arrayfire/arrayfire/blob/devel/src/api/cpp/histogram.cpp - --- -local function HistEqual (in_arr, hist) - return CallWrap("af_hist_equal", in_arr:get(), hist:get()) -end - --- -function M.Add (into) - for k, v in pairs{ - -- - histEqual = HistEqual, histequal = HistEqual, - - -- - histogram = function(in_arr, nbins, minval, maxval) - if not minval then - local lib = into -- possibly delayed load - - minval, maxval = lib.min("f64", in_arr), lib.max("f64", in_arr) - end - - return CallWrap("af_histogram", in_arr:get(), nbins, minval, maxval) - end - } do - into[k] = v - end -end - --- Export the module. -return M \ No newline at end of file diff --git a/wrapper/arrayfire/funcs/io.lua b/wrapper/arrayfire/funcs/io.lua deleted file mode 100644 index d289a84..0000000 --- a/wrapper/arrayfire/funcs/io.lua +++ /dev/null @@ -1,62 +0,0 @@ ---- IO functions. - --- Modules -- -local af = require("arrayfire_lib") -local array = require("impl.array") - --- Imports -- -local Call = array.Call -local CallWrap = array.CallWrap - --- Exports -- -local M = {} - --- See also: https://github.com/arrayfire/arrayfire/blob/devel/src/api/cpp/imageio.cpp - -local function LoadImage (filename, is_color) - return CallWrap("af_load_image", filename, is_color) -end - --- -local function SaveImage (filename, in_arr) - Call("af_save_image", filename, in_arr:get()) -end - --- -function M.Add (into) - for k, v in pairs{ - deleteImageMem = function(ptr) - Call("af_delete_image_memory", ptr) - end, - - -- - loadImage = LoadImage, loadimage = LoadImage, - - -- - loadImageMem = function(ptr) - return CallWrap("af_load_image_memory", ptr) - end, - - loadImageNative = function(filename) - return CallWrap("af_load_image_native", filename) - end, - - -- - saveImage = SaveImage, saveimage = SaveImage, - - -- - saveImageMem = function(in_arr, format) - return Call("af_save_image_memory", in_arr:get(), af[format or "AF_FIF_PNG"]) - end, - - -- - saveImageNative = function(filename, in_arr) - Call("af_save_image_native", filename, in_arr:get()) - end - } do - into[k] = v - end -end - --- Export the module. -return M \ No newline at end of file diff --git a/wrapper/arrayfire/funcs/linear_algebra.lua b/wrapper/arrayfire/funcs/linear_algebra.lua deleted file mode 100644 index 2119de6..0000000 --- a/wrapper/arrayfire/funcs/linear_algebra.lua +++ /dev/null @@ -1,215 +0,0 @@ ---- Linear algebra functions. - --- Modules -- -local af = require("arrayfire_lib") -local array = require("impl.array") - --- Imports -- -local Call = array.Call -local CallWrap = array.CallWrap -local IsArray = array.IsArray -local ToType = array.ToType - --- Exports -- -local M = {} - --- See also: https://github.com/arrayfire/arrayfire/blob/devel/src/api/cpp/blas.cpp --- https://github.com/arrayfire/arrayfire/blob/devel/src/api/cpp/lapack.cpp --- https://github.com/arrayfire/arrayfire/blob/devel/src/api/cpp/transpose.cpp - --- -local function MatMul2 (a, b, opt_lhs, opt_rhs) - opt_lhs, opt_rhs = opt_lhs or "AF_MAT_NONE", opt_rhs or "AF_MAT_NONE" - - return CallWrap("af_matmul", a:get(), b:get(), af[opt_lhs], af[opt_rhs]) -end - --- -local function MatMul3 (a, b, c) - local tmp1 = a:dims(0) * b:dims(1) - local tmp2 = b:dims(0) * c:dims(1) - - if tmp1 < tmp2 then - return MatMul2(MatMul2(a, b), c) - else - return MatMul2(a, MatMul2(b, c)) - end -end - --- -local function MatMul4 (a, b, c, d) - local tmp1 = a:dims(0) * c:dims(1) - local tmp2 = b:dims(0) * d:dims(1) - - if tmp1 < tmp2 then - return MatMul2(MatMul3(a, b, c), d) - else - return MatMul2(a, MatMul3(b, c, d)) - end -end - --- -local function SVD (func) - return function(u, s, vt, in_arr) - local ul, sl, vtl = Call(func, in_arr:get()) - - s:set(sl) - u:set(ul) - vt:set(vtl) - end -end - --- -function M.Add (into) - for k, v in pairs{ - -- - cholesky = function(out, in_arr, is_upper) - if is_upper == nil then - is_upper = true - end - - local res, info = Call("af_cholesky", in_arr:get(), is_upper) - - out:set(res) - - return info - end, - - -- - choleskyInPlace = function(in_arr, is_upper) - if is_upper == nil then - is_upper = true - end - - return Call("af_cholesky_inplace", in_arr:get(), is_upper) - end, - - -- - det = function(rtype, arr) - return ToType(rtype, Call("af_det", arr:get())) - end, - - -- - dot = function(a, b, opt_lhs, opt_rhs) - return CallWrap("af_dot", a:get(), b:get(), af[opt_lhs or "AF_MAT_NONE"], af[opt_rhs or "AF_MAT_NONE"]) - end, - - -- - inverse = function(arr, options) - return CallWrap("af_inverse", arr:get(), af[options or "AF_MAT_NONE"]) - end, - - -- - lu = function(a, b, c, d) - if IsArray(d) then -- a: lower, b: upper, c: pivot, d: in - local l, u, p = Call("af_lu", d:get()) - - a:set(l) - b:set(u) - c:set(p) - else -- a: out, b: pivot, c: in, d: is_lapack_piv - if d == nil then - d = true - end - - a:set(Call("af_copy_array", c:get())) - b:set(Call("af_lu_inplace", a:get(), d)) - end - end, - - -- - luInPlace = function(pivot, in_arr, is_lapack_piv) - if is_lapack_piv == nil then - is_lapack_piv = true - end - - pivot:set(Call("af_lu_inplace", in_arr:get(), is_lapack_piv)) - end, - - -- - matmul = function(a, b, c, d) - if IsArray(d) then -- four arrays - return MatMul4(a, b, c, d) - elseif IsArray(c) then -- three arrays - return MatMul3(a, b, c) - else -- two arrays - return MatMul2(a, b, c, d) - end - end, - - -- - matmulNT = function(a, b) - return MatMul2(a, b, "AF_MAT_NONE", "AF_MAT_TRANS") - end, - - -- - matmulTN = function(a, b) - return MatMul2(a, b, "AF_MAT_TRANS", "AF_MAT_NONE") - end, - - -- - matmulTT = function(a, b) - return MatMul2(a, b, "AF_MAT_TRANS", "AF_MAT_TRANS") - end, - - -- - norm = function(arr, norm_type, p, q) - return Call("af_norm", arr:get(), af[norm_type or "AF_NORM_EUCLID"], p or 1, q or 1) - end, - - -- - qr = function(a, b, c, d) - if IsArray(d) then -- a: q, b: r, c: tau, d: in - local q, r, t = Call("af_qr", d:get()) - - a:set(q) - b:set(r) - c:set(t) - else -- a: out, b: tau, c: in - a:set(Call("af_copy_array", c:get())) - b:set(Call("af_qr_inplace", a:get())) - end - end, - - -- - qrInPlace = function(tau, in_arr) - tau:set(Call("af_qr_inplace", in_arr:get())) - end, - - -- - rank = function(arr, tol) - return Call("af_rank", arr:get(), tol or 1e-5) - end, - - -- - solve = function(a, b, options) - return CallWrap("af_solve", a:get(), b:get(), af[options or "AF_MAT_NONE"]) - end, - - -- - solveLU = function(a, piv, b, options) - return CallWrap("af_solve_lu", a:get(), piv:get(), b:get(), af[options or "AF_MAT_NONE"]) - end, - - -- - svd = SVD("af_svd"), - - -- - svdInPlace = SVD("af_svd_inplace"), - - -- - transpose = function(arr, conjugate) - return CallWrap("af_transpose", arr:get(), conjugate) - end, - - -- - transposeInPlace = function(arr, conjugate) - return Call("af_transpose_inplace", arr:get(), conjugate) - end - } do - into[k] = v - end -end - --- Export the module. -return M \ No newline at end of file diff --git a/wrapper/arrayfire/funcs/mathematics.lua b/wrapper/arrayfire/funcs/mathematics.lua deleted file mode 100644 index 787152a..0000000 --- a/wrapper/arrayfire/funcs/mathematics.lua +++ /dev/null @@ -1,116 +0,0 @@ ---- Mathematics functions. - --- Modules -- -local af = require("arrayfire_lib") -local array = require("impl.array") - --- Imports -- -local CallWrap = array.CallWrap -local GetLib = array.GetLib -local IsArray = array.IsArray -local TwoArrays = array.TwoArrays - --- Exports -- -local M = {} - --- See also: https://github.com/arrayfire/arrayfire/blob/devel/src/api/cpp/binary.cpp - --- -local function Binary (name) - return function(a, b) - return TwoArrays(name, a, b, IsArray(a) and IsArray(b) and GetLib().gforGet()) - end -end - --- -local function Unary (name) - return function(in_arr) - return CallWrap(name, in_arr:get()) - end -end - -local function LoadFuncs (into, funcs, op) - for _, v in ipairs(funcs) do - local name = "af_" .. v - - into[v] = af[name] and op(name) -- ignore conditionally unavailable functions - end -end - --- -function M.Add (into) - LoadFuncs(into, { - "abs", - "acos", - "acosh", - "arg", - "asin", - "asinh", - "atan", - "atanh", - "cbrt", - "ceil", - "conjg", - "cos", - "cosh", - "cplx", - "erf", - "erfc", - "exp", - "expm1", - "factorial", - "floor", - "imag", - "lgamma", - "log", - "log10", - "log1p", - "not", - "real", - "round", - "sigmoid", - "sign", - "sin", - "sinh", - "sqrt", - "tan", - "tanh", - "trunc", - "tgamma" - }, Unary) - - LoadFuncs(into, { - "add", - "and", - "atan2", - "bitand", - "bitor", - "bitshiftl", - "bitshiftr", - "bitxor", - "cplx2", - "div", - "eq", - "ge", - "gt", - "hypot", - "le", - "lt", - "maxof", - "minof", - "mod", - "mul", - "neq", - "or", - "pow", - "rem", - "root", - "sub" - }, Binary) - - -- Use C++ name. (TODO: maxof, minof... re. vector) - into.complex, into.cplx2 = into.cplx2 -end - --- Export the module. -return M \ No newline at end of file diff --git a/wrapper/arrayfire/funcs/signal_processing.lua b/wrapper/arrayfire/funcs/signal_processing.lua deleted file mode 100644 index ec8c287..0000000 --- a/wrapper/arrayfire/funcs/signal_processing.lua +++ /dev/null @@ -1,97 +0,0 @@ ---- Signal processing functions. - --- Standard library imports -- -local min = math.min - --- Modules -- -local af = require("arrayfire_lib") -local array = require("impl.array") - --- Imports -- -local CallWrap = array.CallWrap -local IsArray = array.IsArray - --- Forward declarations -- -local Convolve1 -local Convolve2 -local Convolve3 - --- Exports -- -local M = {} - --- See also: https://github.com/arrayfire/arrayfire/blob/devel/src/api/cpp/convolve.cpp --- https://github.com/arrayfire/arrayfire/blob/devel/src/api/cpp/fft.cpp - --- -local function Convolve (dim) - local name = "af_convolve" .. dim - - return function(signal, filter, mode, domain) - return CallWrap(name, signal:get(), filter:get(), af[mode or "AF_CONV_DEFAULT"], af[domain or "AF_CONV_AUTO"]) - end -end - --- -function M.Add (into) - for k, v in pairs{ - -- - convolve = function(a, b, c, d) - if IsArray(c) then -- a: col_filter, b: row_filter, c: signal, d: mode - return CallWrap("af_convolve2_sep", a:get(), b:get(), c:get(), af[mode or "AF_CONV_DEFAULT"]) - else -- a: signal, b: filter, c: mode, d: domain - local n, func = min(a:numdims(), b:numdims()) - - if n == 1 then - func = Convolve1 - elseif n == 2 then - func = Convolve2 - else - func = Convolve3 - end - - return func(a, b, c, d) - end - end, - - -- - convolve1 = Convolve("1"), - - -- - convolve2 = Convolve("2"), - - -- - convolve3 = Convolve("3"), - - -- - fft = function(in_arr, dim0) - return CallWrap("af_fft", in_arr:get(), 1, dim0 or 0) - end, - - -- - fft2 = function(in_arr, dim0, dim1) - return CallWrap("af_fft2", in_arr:get(), 1, dim0 or 0, dim1 or 0) - end, - - -- - fft3 = function(in_arr, dim0, dim1, dim2) - return CallWrap("af_fft3", in_arr:get(), 1, dim0 or 0, dim1 or 0, dim2 or 0) - end - } do - into[k] = v - end - - -- Alias (TODO: deprecated) - local filter_alias = into.convolve - - function into.filter (signal, filter) - return filter_alias(signal, filter) - end - - -- - Convolve1 = into.convolve1 - Convolve2 = into.convolve2 - Convolve3 = into.convolve3 -end - --- Export the module. -return M \ No newline at end of file diff --git a/wrapper/arrayfire/funcs/static.lua b/wrapper/arrayfire/funcs/static.lua deleted file mode 100644 index 50320fa..0000000 --- a/wrapper/arrayfire/funcs/static.lua +++ /dev/null @@ -1,63 +0,0 @@ ---- Static companions of array methods. - --- Modules -- -local array = require("impl.array") - --- Imports -- -local Call = array.Call -local IsArray = array.IsArray - --- Exports -- -local M = {} - --- -local function Eval1 (a, b, c, d, e, f) - a:eval() - - if b then - return Eval1(b, c, d, e, f) - end -end - --- -function M.Add (into) - for k, v in pairs{ - -- - eval = function(a, b, c, d, e, f) - if IsArray(f) then - Eval1(a, b, c, d, e, f) - elseif IsArray(e) then - Eval1(a, b, c, d, e) - elseif IsArray(d) then - Eval1(a, b, c, d) - elseif IsArray(c) then - Eval1(a, b, c) - elseif IsArray(b) then - Eval1(a, b) - else - a:eval() - - return a - end - end, - - -- - getDims = function(arr, out) - out = out or {} - - out[1], out[2], out[3], out[4] = Call("af_get_dims", arr:get()) - - return out - end, - - -- - numDims = function(arr) - return Call("af_get_numdims", arr:get()) - end, - } do - into[k] = v - end -end - --- Export the module. -return M \ No newline at end of file diff --git a/wrapper/arrayfire/funcs/statistics.lua b/wrapper/arrayfire/funcs/statistics.lua deleted file mode 100644 index 8b7ca6b..0000000 --- a/wrapper/arrayfire/funcs/statistics.lua +++ /dev/null @@ -1,46 +0,0 @@ ---- Statistics functions. - --- Standard library imports -- -local type = type - --- Modules -- -local array = require("impl.array") - --- Imports -- -local Call = array.Call -local CallWrap = array.CallWrap -local GetFNSD = array.GetFNSD -local HandleDim = array.HandleDim -local IsArray = array.IsArray -local ToType = array.ToType - --- Exports -- -local M = {} - --- See also: https://github.com/arrayfire/arrayfire/blob/devel/src/api/cpp/mean.cpp - -local function Mean (a, b, c) - if type(a) == "string" then -- a: type, b: in_arr, c: weights - if IsArray(c) then - return ToType(a, Call("af_mean_all_weighted", b:get(), c:get())) - else - return ToType(a, Call("af_mean_all", b:get())) - end - elseif IsArray(b) then -- a: arr, b: weights, c: dim - return CallWrap("mean_weighted", a:get(), b, GetFNSD(c)) - else -- a: arr, b: dim - return HandleDim("af_mean", a, b) - end -end - --- -function M.Add (into) - for k, v in pairs{ - mean = Mean - } do - into[k] = v - end -end - --- Export the module. -return M \ No newline at end of file diff --git a/wrapper/arrayfire/funcs/util.lua b/wrapper/arrayfire/funcs/util.lua deleted file mode 100644 index 761018b..0000000 --- a/wrapper/arrayfire/funcs/util.lua +++ /dev/null @@ -1,33 +0,0 @@ ---- Utility functions. - --- Standard library imports -- -local print = print - --- Modules -- -local array = require("impl.array") - --- Imports -- -local Call = array.Call - --- Exports -- -local M = {} - --- -function M.Add (into) - for k, v in pairs{ - -- - print = function(exp, arr, precision) - Call("af_print_array_gen", exp, arr:get(), precision or 4) -- https://github.com/arrayfire/arrayfire/blob/devel/src/api/cpp/util.cpp - end, - - -- - printf = function(s, ...) - print(s:format(...)) - end - } do - into[k] = v - end -end - --- Export the module. -return M \ No newline at end of file diff --git a/wrapper/arrayfire/funcs/vector.lua b/wrapper/arrayfire/funcs/vector.lua deleted file mode 100644 index 384fdf7..0000000 --- a/wrapper/arrayfire/funcs/vector.lua +++ /dev/null @@ -1,191 +0,0 @@ ---- Vector functions. - --- Standard library imports -- -local assert = assert -local min = math.min -local select = select -local type = type - --- Modules -- -local array = require("impl.array") - --- Imports -- -local Call = array.Call -local CallWrap = array.CallWrap -local GetLib = array.GetLib -local HandleDim = array.HandleDim -local IsArray = array.IsArray -local ToType = array.ToType - --- Exports -- -local M = {} - --- See also: https://github.com/arrayfire/arrayfire/blob/devel/src/api/cpp/reduce.cpp --- https://github.com/arrayfire/arrayfire/blob/devel/src/api/cpp/where.cpp - --- -local function Bool (value) - if value ~= nil then - return not not value - else - return true - end -end - --- -local function Funcs (name, prefix) - name = (prefix or "af_") .. name - - return name, name .. "_all" -end - --- -local function Reduce (name) - local func, func_all = Funcs(name) - - return function(in_arr, dim) - local rtype - - if type(in_arr) == "string" then - rtype, in_arr = in_arr, dim - end - - if rtype then - local r, i = Call(func_all, in_arr:get()) - - return ToType(rtype, r, i) - else - return HandleDim(func, in_arr, dim) - end - end -end - --- -local function ReduceMaxMin (name) - local func, func_all = Funcs(name) - local ifunc, ifunc_all = Funcs(name, "af_i") - local arith = name .. "of" - - return function(a, b, c, d) - if type(a) == "string" then -- a: type, b: in_arr[, c: "get_index"] - if c == "get_index" then -- TODO: This is ugly and doesn't resemble the C++ interface... maybe a table as first argument, as compromise? - local r, i, index = Call(ifunc_all, b:get()) - - return ToType(a, r, i), index - else - return ToType(a, Call(func_all, b:get())) - end - elseif IsArray(c) then -- a: val, b: idx, c: arr, d: dim - local out, idx = HandleDim(ifunc, c, d, "no_wrap") - - a:set(out) - b:set(idx) - elseif not b or c == "dim" then -- a: arr, b: dim[, c: "dim"] (TODO: Again, ugly but no obvious alternative... IsConstant()?) - return HandleDim(func, a, b) - else -- a: lhs, b: rhs - return GetLib()[arith](a, b) - end - end -end - --- -local function ReduceNaN (name) - local func, func_all = Funcs(name) - local func_nan, func_nan_all = Funcs(name .. "_nan") - - return function(in_arr, dim, nanval) - local rtype - - if type(in_arr) == "string" then - rtype, in_arr = in_arr, dim - end - - if rtype then - local r, i - - if nanval then - r, i = Call(func_nan_all, in_arr:get(), nanval) - else - r, i = Call(func_all, in_arr:get()) - end - - return ToType(rtype, r, i) - else - if nanval then - return CallWrap(func_nan, in_arr:get(), dim, nanval) - else - return HandleDim(func, in_arr, dim) - end - end - end -end - --- TODO: lost in macroland :P (probably missing some stuff) - --- -local AllTrue, AnyTrue = Reduce("all_true"), Reduce("any_true") - --- -function M.Add (into) - for k, v in pairs{ - -- - alltrue = AllTrue, allTrue = AllTrue, - - -- - anytrue = AnyTrue, anyTrue = AnyTrue, - - -- - count = Reduce("count"), - - -- - diff1 = function(in_arr, dim) - return CallWrap("af_diff1", in_arr:get(), dim) - end, - - -- - diff2 = function(in_arr, dim) - return CallWrap("af_diff2", in_arr:get(), dim) - end, - - -- - max = ReduceMaxMin("max"), - - -- - min = ReduceMaxMin("min"), - - -- - product = ReduceNaN("product"), - - -- - sort = function(a, b, c, d, e, f) - if IsArray(d) then -- four arrays - local keys, values = Call("af_sort_by_key", c:get(), d:get(), e or 0, Bool(f)) - - a:set(keys) - b:set(values) - elseif IsArray(c) then -- three arrays - local arr, indices = Call("af_sort_index", c:get(), d or 0, Bool(e)) - - a:set(arr) - b:set(indices) - else -- one array - return CallWrap("af_sort", a:get(), b or 0, Bool(c)) - end - end, - - -- - sum = ReduceNaN("sum"), - - -- - where = function(in_arr) - assert(not GetLib().gforGet(), "WHERE can not be used inside GFOR") -- TODO: AF_ERR_RUNTIME); - - return CallWrap("af_where", in_arr:get()) - end - } do - into[k] = v - end -end - --- Export the module. -return M \ No newline at end of file diff --git a/wrapper/arrayfire/graphics/window.lua b/wrapper/arrayfire/graphics/window.lua deleted file mode 100644 index 675b9c4..0000000 --- a/wrapper/arrayfire/graphics/window.lua +++ /dev/null @@ -1,192 +0,0 @@ ---- Windows and their methods. - --- Standard library imports -- -local getmetatable = getmetatable -local rawequal = rawequal -local type = type - --- Modules -- -local af = require("arrayfire_lib") -local array = require("impl.array") - --- Imports -- -local Call = array.Call -local IsArray = array.IsArray -local GetLib = array.GetLib - --- Exports -- -local M = {} - --- See also: https://github.com/arrayfire/arrayfire/blob/devel/src/api/cpp/graphics.cpp - --- -local TempCell = {} - --- -local function Temp (window, title, how) - TempCell.row, TempCell.col = window._r, window._c - TempCell.title = title - TempCell.cmap = how == "use_cmap" and window._cmap or af.AF_COLORMAP_DEFAULT - - return TempCell -end - --- -- -local Window = {} - -local MetaValue = {} - --- -Window.__index = Window -Window.__metatable = MetaValue - ---- DOCME -function Window:__call (r, c) - self._r, self._c = r, c - - return self -end - --- __gc = AF_THROW(af_destroy_window(wnd)); - --- -local function Get (window) --- TODO: Use a proxy to gc the window... - return window.wnd -end - ---- DOCME -function Window:close () - return Call("af_is_window_closed", Get(self)) -end - ---- DOCME -function Window:destroy () - if not self:close() then - Call("af_destroy_window", Get(self)) - end -end - ---- DOCME -function Window:grid (rows, cols) - Call("af_grid", Get(self), rows, cols) -end - ---- DOCME -function Window:hist (X, minval, maxval, title) - Call("af_draw_hist", Get(self), X:get(), minval, maxval, Temp(self, title)) -end - ---- DOCME -function Window:image (in_arr, title) - Call("af_draw_image", Get(self), in_arr:get(), Temp(self, title, "use_cmap")) -end - ---- DOCME -function Window:plot (X, Y, title) - Call("af_draw_plot", Get(self), X:get(), Y:get(), Temp(self, title)) -end - -function Window:plot3 (P, title) - P:eval() - - Call("af_draw_plot3", Get(self), P:get(), Temp(self, title)) -end - ---[[ -3.3 -void Window::scatter(const array& X, const array& Y, af::markerType marker, const char* const title) -{ - af_cell temp{_r, _c, title, AF_COLORMAP_DEFAULT}; - AF_THROW(af_draw_scatter(get(), X.get(), Y.get(), marker, &temp)); -} - -void Window::scatter3(const array& P, af::markerType marker, const char* const title) -{ - af_cell temp{_r, _c, title, AF_COLORMAP_DEFAULT}; - AF_THROW(af_draw_scatter3(get(), P.get(), marker, &temp)); -} -]] - ---- DOCME -function Window:setPos (x, y) - Call("af_set_position", Get(self), x, y) -end - ---- DOCME -function Window:setTitle (title) - Call("af_set_title", Get(self), title) -end - ---- DOCME -function Window:setSize (w, h) - Call("af_set_size", Get(self), w, h) -end - ---- DOCME -function Window:setColorMap (cmap) - self._cmap = af[cmap] -end - ---- DOCME -function Window:show () - Call("af_show", Get(self)) - - self._r, self._c = -1, -1 -end - -function Window:surface (a, b, c, d) - local xVals, yVals, title - - if IsArray(b) then -- a: xVals, b: yVals, c: S, d: title - xVals, yVals, title = a, b, d - else -- a: S, b: title - local lib = GetLib() - - xVals = lib.array(lib.seq(0, c:dims(0) - 1)) - yVals = lib.array(lib.seq(0, c:dims(0) - 1)) - title = b - end - - Call("af_draw_surface", Get(self), xVals:get(), yVals:get(), S:get(), Temp(self, title)) -end - --- -local function Set (window, handle) - window.wnd = handle -- TODO: note about proxy... -end - --- -local function InitWindow (window, w, h, title) - Set(window, Call("af_create_window", w, h, title or "ArrayFire")) -end - --- -function M.Add (into) - for k, v in pairs{ - -- - IsWindow = function(item) - return rawequal(getmetatable(item), MetaValue) - end, - - -- - Window = function(a, b, c) - local window = { cnd = 0, _r = -1, _c = -1, _cmap = af.AF_COLORMAP_DEFAULT } - - if a == nil or type(a) == "string" then -- a: title - InitWindow(window, 1280, 720, a) - elseif b then -- a: width, b: height, c: title - InitWindow(window, a, b, c) - else -- a: window - Set(window, a) - end - - return setmetatable(window, Window) - end - } do - into[k] = v - end -end - --- Export the module. -return M \ No newline at end of file diff --git a/wrapper/arrayfire/impl/array.lua b/wrapper/arrayfire/impl/array.lua deleted file mode 100644 index 24b53ea..0000000 --- a/wrapper/arrayfire/impl/array.lua +++ /dev/null @@ -1,343 +0,0 @@ ---- Core array module. - --- Standard library imports -- -local error = error -local getmetatable = getmetatable -local rawequal = rawequal -local setmetatable = setmetatable -local tostring = tostring -local traceback = debug and debug.traceback -local type = type - --- Modules -- -local af = require("arrayfire_lib") - --- Cached module references -- -local _AddToCurrentEnvironment_ -local _Call_ -local _CallWrap_ -local _CheckError_ -local _GetConstant_ -local _GetFNSD_ -local _IsArray_ -local _IsConstant_ -local _ToArray_ -local _WrapArray_ - --- Exports -- -local M = {} - --- -- -local ArrayMethodsAndMetatable = {} - -local MetaValue = {} - -local Constants = setmetatable({}, { __mode = "k" }) - --- -local function ErrorOut (what) - if traceback then - print(traceback()) - end - - error(what) -end - --- -local function CallFromName_Checked (name, ...) - local func = af[name] - - if type(func) ~= "function" then - if type(name) ~= "string" then - ErrorOut("Expected string name, got: " .. tostring(name)) - else - ErrorOut(name .. " is not a function") - end - end - - Name = name - - return _CheckError_(func(...)) -end - --- -local function CallFromName_Unchecked (name, ...) - Name = name - - return _CheckError_(af[name](...)) -end - --- -- -local CallFromName - ---- DOCME --- @string name --- @param ... Arguments to function. --- @return Any non-error return values. -function M.Call (name, ...) - return CallFromName(name, ...) -end - --- -local function WrapAndReturn (arr, ...) - return _WrapArray_(arr), ... -end - ---- DOCME --- @string name --- @param ... Arguments to function. --- @treturn LuaArray X --- @return Any additional return values. -function M.CallWrap (name, ...) - return WrapAndReturn(CallFromName(name, ...)) -end - --- -- -local SUCCESS = af.AF_SUCCESS - ---- DOCME --- @tparam af_err err --- @param ... --- @return ... -function M.CheckError (err, ...) - if err ~= SUCCESS then - local name = Name or "" - - Name = nil - - error(("%s: %i"):format(name, err)) - end - - return ... -end - ---- DOCME -function M.CheckNames (check) - CallFromName = check and CallFromName_Checked or CallFromName_Unchecked -end - --- -- -local Dim = {} - ---- DOCME --- @tparam af_array ha --- @int dim --- @treturn int FNSD -function M.GetFNSD (ha, dim) - if dim < 0 then - local ndims = _Call_("af_get_numdims", ha) - - Dim[1], Dim[2], Dim[3], Dim[4] = _Call_("af_get_dims", ha) - - for i = 1, 4 do - if Dim[i] > 1 then - return i - 1 - end - end - - return 0 - else - return dim - end -end - ---- DOCME --- @tparam Constant k --- @return R -function M.GetConstant (k) - return Constants[k] and k[1] -end - ---- DOCME --- @tparam LuaArray arr --- @treturn ?|af_array|nil X -function M.GetHandle (arr) --- TODO: If proxy, add reference? - return arr.m_handle -end - --- -- -local Lib - ---- DOCME -function M.GetLib () - Lib = Lib or require("arrayfire") - return Lib -end - ---- DOCME --- @tparam function func --- @tparam LuaArray arr --- @number[opt=-1] dim --- @string[opt] how --- @return Results of _func_. -function M.HandleDim (func, arr, dim, how) - local harr = arr:get() - - return (how ~= "no_wrap" and _CallWrap_ or _Call_)(func, harr, _GetFNSD_(harr, dim or -1)) -end - ---- DOCME --- @param item --- @treturn boolean B -function M.IsArray (item) - return rawequal(getmetatable(item), MetaValue) and not Constants[item] -end - ---- DOCME --- @param item --- @treturn boolean B -function M.IsConstant (item) - return not not Constants[item] -- metatable redundant; coerce to false if missing -end - --- TODO: IsProxy(), MakeProxy()... - ---- DOCME --- @tparam LuaArray arr --- @tparam ?|af_array|nil handle -function M.SetHandle (arr, handle) --- TODO: disable for proxies - local cur = arr.m_handle - - if cur ~= nil then - _Call_("af_release_array", cur) - end - - arr.m_handle = handle -end - --- -- -local Args = {} - ---- DOCME --- @param value --- @tparam LuaArray other --- @treturn LuaArray A -function M.ToArray (value, other) - if _IsConstant_(value) then - value = _GetConstant_(value) - end - - local btype, hother = type(value), other:get() - local ndims = _Call_("af_get_numdims", hother) - - Args[1], Args[2], Args[3], Args[4] = _Call_("af_get_dims", hother) - - if btype == "table" then - -- Complex... - elseif btype == "number" then - -- Argh... detect range, integer-ness, etc? - - return _Call_("af_constant", value, ndims, Args, af.f32) - end -end - ---- DOCME --- @string ret_type --- @param real --- @param imag --- @treturn RetType RT -function M.ToType (ret_type, real, imag) - if rtype == "c32" or rtype == "c64" then - return { real = real, imag = imag } - else - return real -- TODO: Improve this! - end -end - ---- DOCME --- @string name --- @param a --- @param b --- @param ... --- @treturn LuaArray X -function M.TwoArrays (name, a, b, ...) - local atemp, btemp, ha, hb - - if not _IsArray_(a) then - hb, ha, atemp = b:get(), _ToArray_(a, b), true - elseif not _IsArray_(b) then - ha, hb, btemp = a:get(), _ToArray_(b, a), true - else - ha, hb = a:get(), b:get() - end - - -- - local err, arr = af[name](ha, hb, ...) - - if atemp or btemp then - _Call_("af_release_array", atemp and ha or hb) - end - - Name = name - - _CheckError_(err) - - return _WrapArray_(arr) -end - ---- DOCME --- @tparam af_array arr --- @treturn LuaArray X -function M.WrapArray (arr) - local wrapped = setmetatable({ m_handle = arr }, ArrayMethodsAndMetatable) - - _AddToCurrentEnvironment_("array", wrapped) - - return wrapped -end - ---- DOCME --- @param k constant --- @treturn Constant Y -function M.WrapConstant (k) - k = { k } - - Constants[k] = true - - return setmetatable(k, ArrayMethodsAndMetatable) -- allow comparison operators -end - --- -for _, v in ipairs{ - "impl.ephemeral", - "impl.operators", - "impl.seq", -- depends on ephemeral - "impl.index", -- depends on ephemeral, seq - "methods.methods" -} do - require(v).Add(M, ArrayMethodsAndMetatable) -end - -ArrayMethodsAndMetatable.__index = ArrayMethodsAndMetatable -ArrayMethodsAndMetatable.__metatable = MetaValue - --- Register array environment type. -M.RegisterEnvironmentCleanup("array", function(arr) - local ha = arr:get() - - arr.m_handle = nil -- set() can error out - - return not ha or af.af_release_array(ha) == SUCCESS - -- TODO: pooling? -end, "Errors releasing %i arrays") --- TODO: Register "array_proxy"? - --- By default, check valid names. -M.CheckNames(true) - --- Cache module members. -_AddToCurrentEnvironment_ = M.AddToCurrentEnvironment -_Call_ = M.Call -_CallWrap_ = M.CallWrap -_CheckError_ = M.CheckError -_GetConstant_ = M.GetConstant -_GetFNSD_ = M.GetFNSD -_IsArray_ = M.IsArray -_IsConstant_ = M.IsConstant -_ToArray_ = M.ToArray -_WrapArray_ = M.WrapArray - --- Export the module. -return M diff --git a/wrapper/arrayfire/impl/ephemeral.lua b/wrapper/arrayfire/impl/ephemeral.lua deleted file mode 100644 index 31d8b79..0000000 --- a/wrapper/arrayfire/impl/ephemeral.lua +++ /dev/null @@ -1,185 +0,0 @@ ---- Ephemeral array environments. - --- Standard library imports -- -local assert = assert -local concat = table.concat -local collectgarbage = collectgarbage -local error = error -local pairs = pairs -local pcall = pcall -local rawequal = rawequal -local remove = table.remove - --- Cookies -- -local _command = {} - --- Exports -- -local M = {} - --- -- -local ID = 0 - --- -- -local Stack = {} - --- -- -local Top = 0 - --- -local function Remove (lists, elem) - for elem_type, list in pairs(lists) do - if list[elem] then - list[elem] = nil - - return elem_type - end - end -end - --- -- -local Types = {} - --- -local function NewEnv () - local id, lists, mode, step = ID, {} - - ID = ID + 1 - - for elem_type in pairs(Types) do - lists[elem_type] = {} - end - - return function(a, b, c) - if rawequal(a, _command) then -- a: _command, b: what, c: arg - if b == "set_mode" then - mode = c - elseif b == "get_id" then - return id - elseif b == "get_lists" then - return lists - elseif b == "set_step" then - step = c - end - elseif a == "get_step" then -- a: "get_step" - return step - else -- a: element? - local env = Stack[Top] - - assert(env and env(_command, "get_id") == id, "Environment not active") -- is self? - - local elem_type = Remove(lists, a) - - if elem_type then - local lower_env = (mode == "parent" or mode == "parent_gc") and Stack[Top - 1] --- TODO: pingpong, pingpong_gc - if lower_env then - lower_env(_command, "get_lists")[elem_type][a] = true - end - - return a - end - end - end -end - --- -local function Purge (lists) - local errs - - for elem_type, type_info in pairs(Types) do - local elem_list, cleanup, nerrs = lists[elem_type], type_info.cleanup, 0 - - -- - for elem in pairs(elem_list) do - if not cleanup(elem) then - nerrs = nerrs + 1 - end - - elem_list[elem] = nil - end - - -- - if nerrs > 0 then - errs = errs or {} - - errs[#errs + 1] = type_info.message:format(nerrs) - end - end - - return errs and concat(errs, "\n") -end - --- -- -local Cache = {} - --- -local function GetResults (env, ok, a, ...) - local mode = env(_command, "get_mode") - - env(_command, "set_mode", nil) - - local errs = Purge(env(_command, "get_lists")) --- Pingpong or normal? (How to end?) - Cache[#Cache + 1] = env - Top, Stack[Top] = Top - 1 - - if mode == "normal_gc" or mode == "parent_gc" then - collectgarbage() - end --- TODO: pingpong_gc - if ok and not errs then - return a, ... - else --- Clean up if pingpong - error(not ok and a or errs) - end -end - --- -function M.Add (array_module) - -- - function array_module.AddToCurrentEnvironment (elem_type, arr) - local env = Top > 0 and Stack[Top] - - if env then - env(_command, "get_lists")[elem_type][arr] = true - end - end --- AddOneEnv --- AddEnvs - -- - function array_module.CallWithEnvironment (func, ...) - local env = remove(Cache) or NewEnv() --- AddOneEnv() - Top = Top + 1 - - Stack[Top] = env - - return GetResults(env, pcall(func, env, ...)) - end - - -- - function array_module.CallWithEnvironment_Args (func, args, ...) - local env = remove(Cache) or NewEnv() - - Top = Top + 1 --- if pingpong - -- AddEnvs - env(_command, "set_mode", args.mode) - env(_command, "set_step", args.step) - - Stack[Top] = env - - return GetResults(env, pcall(func, env, ...)) - end - - -- - function array_module.RegisterEnvironmentCleanup (elem_type, cleanup, message) - assert(Top == 0 and #Cache == 0, "Attempt to register new environment type after launch") - - Types[elem_type] = { cleanup = cleanup, message = message } - end -end - --- Export the module. -return M \ No newline at end of file diff --git a/wrapper/arrayfire/impl/index.lua b/wrapper/arrayfire/impl/index.lua deleted file mode 100644 index 43b6c1a..0000000 --- a/wrapper/arrayfire/impl/index.lua +++ /dev/null @@ -1,218 +0,0 @@ ---- Core index module. - --- Modules -- -local af = require("arrayfire_lib") - --- Forward declarations -- - --- Exports -- -local M = {} - --- See also: https://github.com/arrayfire/arrayfire/blob/devel/src/api/cpp/index.cpp - --- -function M.Add (array_module) - -- Import these here since the array module is not yet registered. ---[[ -/// -/// \brief Wrapper for af_index. -/// -/// This class is a wrapper for the af_index struct in the C interface. It -/// allows implicit type conversion from valid indexing types like int, -/// \ref af::seq, \ref af_seq, and \ref af::array. -/// -/// \note This is a helper class and does not necessarily need to be created -/// explicitly. It is used in the operator() overloads to simplify the API. -/// -class AFAPI index { - - af_index_t impl; - public: - /// - /// \brief Default constructor. Equivalent to \ref af::span - /// - index(); - ~index(); - - /// - /// \brief Implicit int converter - /// - /// Indexes the af::array at index \p idx - /// - /// \param[in] idx is the id of the index - /// - /// \sa indexing - /// - index(const int idx); - - /// - /// \brief Implicit seq converter - /// - /// Indexes the af::array using an \ref af::seq object - /// - /// \param[in] s0 is the set of indices to parse - /// - /// \sa indexing - /// - index(const af::seq& s0); - - /// - /// \brief Implicit seq converter - /// - /// Indexes the af::array using an \ref af_seq object - /// - /// \param[in] s0 is the set of indices to parse - /// - /// \sa indexing - /// - index(const af_seq& s0); - - /// - /// \brief Implicit int converter - /// - /// Indexes the af::array using an \ref af::array object - /// - /// \param[in] idx0 is the set of indices to parse - /// - /// \sa indexing - /// - index(const af::array& idx0); - -#if AF_API_VERSION >= 31 - /// - /// \brief Copy constructor - /// - /// \param[in] idx0 is index to copy. - /// - /// \sa indexing - /// - index(const index& idx0); -#endif - - /// - /// \brief Returns true if the \ref af::index represents a af::span object - /// - /// \returns true if the af::index is an af::span - /// - bool isspan() const; - - /// - /// \brief Gets the underlying af_index_t object - /// - /// \returns the af_index_t represented by this object - /// - const af_index_t& get() const; -]] - ---[[ -array lookup(const array &in, const array &idx, const int dim) -{ - af_array out = 0; - AF_THROW(af_lookup(&out, in.get(), idx.get(), getFNSD(dim, in.dims()))); - return array(out); -} - -void copy(array &dst, const array &src, - const index &idx0, - const index &idx1, - const index &idx2, - const index &idx3) -{ - unsigned nd = dst.numdims(); - - af_index_t indices[] = {idx0.get(), - idx1.get(), - idx2.get(), - idx3.get()}; - - af_array lhs = dst.get(); - const af_array rhs = src.get(); - AF_THROW(af_assign_gen(&lhs, lhs, nd, indices, rhs)); -} - -index::index() { - impl.idx.seq = af_span; - impl.isSeq = true; - impl.isBatch = false; -} - -index::index(const int idx) { - impl.idx.seq = af_make_seq(idx, idx, 1); - impl.isSeq = true; - impl.isBatch = false; -} - -index::index(const af::seq& s0) { - impl.idx.seq = s0.s; - impl.isSeq = true; - impl.isBatch = s0.m_gfor; -} - -index::index(const af_seq& s0) { - impl.idx.seq = s0; - impl.isSeq = true; - impl.isBatch = false; -} - -index::index(const af::array& idx0) { - array idx = idx0.isbool() ? where(idx0) : idx0; - af_array arr = 0; - AF_THROW(af_retain_array(&arr, idx.get())); - impl.idx.arr = arr; - - impl.isSeq = false; - impl.isBatch = false; -} - -index::index(const af::index& idx0) { - *this = idx0; -} - -index::~index() { - if (!impl.isSeq) - af_release_array(impl.idx.arr); -} - -index & index::operator=(const index& idx0) { - impl = idx0.get(); - if(impl.isSeq == false){ - // increment reference count to avoid double free - // when/if idx0 is destroyed - AF_THROW(af_retain_array(&impl.idx.arr, impl.idx.arr)); - } - return *this; -} - -#if __cplusplus > 199711L -index::index(index &&idx0) { - impl = idx0.impl; -} - -index& index::operator=(index &&idx0) { - impl = idx0.impl; - return *this; -} -#endif - - -static bool operator==(const af_seq& lhs, const af_seq& rhs) { - return lhs.begin == rhs.begin && lhs.end == rhs.end && lhs.step == rhs.step; -} - -bool index::isspan() const -{ - return impl.isSeq == true && impl.idx.seq == af_span; -} - -const af_index_t& index::get() const -{ - return impl; -} -]] - -end - --- TODO: Add "index" environment type? - --- Export the module. -return M \ No newline at end of file diff --git a/wrapper/arrayfire/impl/operators.lua b/wrapper/arrayfire/impl/operators.lua deleted file mode 100644 index 169524a..0000000 --- a/wrapper/arrayfire/impl/operators.lua +++ /dev/null @@ -1,89 +0,0 @@ ---- Operator overloads. - --- Modules -- -local af = require("arrayfire_lib") - --- Forward declarations -- -local CallWrap -local GetLib -local TwoArrays - --- Exports -- -local M = {} - --- -- -local Result - --- -local function Binary (name, cmp) - name = "af_" .. name - - return function(a, b) --- TODO: disable for proxies? - Result = nil - - local arr = TwoArrays(name, a, b, GetLib().gforGet()) - - if cmp then - Result = arr - else - return arr - end - end -end - --- -function M.Add (array_module, meta) - -- Import these here since the array module is not yet registered. - GetLib = array_module.GetLib - CallWrap = array_module.CallWrap - TwoArrays = array_module.TwoArrays - - -- - function array_module.CompareResult () -- to be called as CompareResult(a < b), etc. - local result = Result - - Result = nil - - return result - end - - -- - for k, v in pairs{ - __add = Binary("add"), - __band = Binary("bitand"), - __bnot = function(a) - return CallWrap("af_not", a:get()) - end, - __bor = Binary("bitor"), - __bxor = Binary("bitxor"), - __call = function(a, ...) - -- operator()... ugh (proxy types, __index and __newindex shenanigans) - end, - __div = Binary("div"), - __eq = Binary("eq", true), - __lt = Binary("lt", true), - __le = Binary("le", true), - __mod = Binary("rem"), - __mul = Binary("mul"), - __newindex = function(a, k, v) - -- TODO: disable for non-proxies? - - if k == "_" then - -- lvalue assign of v - end - end, - __pow = Binary("pow"), - __shl = Binary("bitshiftl"), - __shr = Binary("bitshiftr"), - __sub = Binary("sub"), - __unm = function(a) - return 0 - a - end - } do - meta[k] = v - end -end - --- Export the module. -return M \ No newline at end of file diff --git a/wrapper/arrayfire/impl/seq.lua b/wrapper/arrayfire/impl/seq.lua deleted file mode 100644 index 8829fca..0000000 --- a/wrapper/arrayfire/impl/seq.lua +++ /dev/null @@ -1,170 +0,0 @@ ---- Core seq module. - --- Standard library imports -- -local abs = math.abs -local assert = assert -local getmetatable = getmetatable -local rawequal = rawequal -local setmetatable = setmetatable -local type = type - --- Cached module references -- -local _IsSeq_ -local _MakeSeq_ - --- Exports -- -local M = {} - --- See also: https://github.com/arrayfire/arrayfire/blob/devel/src/api/cpp/seq.cpp - --- -- -local SeqMT = {} - --- -- -local MetaValue = {} - --- -local function IsSeqA (a, b) - local is_a, is_b = _IsSeq_(a), _IsSeq_(b) - - assert(is_a ~= is_b, "Arithmetic not defined on two seq arguments") - - return is_a -end - --- -local function SwapIfB (a, b) - if IsSeqA(a, b) then - return a, b - else - return b, a - end -end - --- -function SeqMT.__add (a, b) - a, b = SwapIfB(a, b) - - return _MakeSeq_(a.begin + b, a["end"] + b, a.step) -end - --- -function SeqMT.__mul (a, b) - a, b = SwapIfB(a, b) - - return _MakeSeq_(a.begin * b, a["end"] * b, a.step * b) -end - --- -function SeqMT.__sub (a, b) - if IsSeqA(a) then - return _MakeSeq_(a.begin - b, a["end"] - b, a.step) - else - return _MakeSeq_(a - b.begin, a - b["end"], -b.step) -- TODO: double-check step - end -end - --- -function SeqMT:__unm () - return _MakeSeq_(-self.begin, -self["end"], -self.step) -end - ---[[ -int end = -1; -seq span(af_span); -]] - --- -function M.Add (array_module) - -- Import these here since the array module is not yet registered. - local CallWithEnvironment = array_module.CallWithEnvironment - local GetLib = array_module.GetLib - - --- DOCME - function array_module.IsSeq (item) - return rawequal(getmetatable(item), MetaValue) - end - - -- DOCME - function array_module.MakeSeq (sbegin, send, step) - if type(sbegin) == "table" then - local s = sbegin - - sbegin, send, step = s.begin, s["end"], s.step - end - - local seq = {} - - seq.begin, seq["end"], seq.step = sbegin, send, step - - if step ~= 0 then -- not span - seq.size = abs((send - sbegin) / step) + 1 - else - seq.size = 0 - end - - return setmetatable(seq, SeqMT) - end - - -- - local function SignBit (x) - return x < 0 and -1 or 0 - end - - --- DOCME - function array_module.NewSeq (a, b, c) - if _IsSeq_(a) then -- a: seq, b: gfor - local copy = _MakeSeq_(a) - - copy.m_gfor = not not b - - return copy - elseif b == "seq" then -- a: seq (table), "seq" - return _MakeSeq_(a) - elseif b then -- a: begin, b: end, c: step - c = c or 1 - - if c == 0 then - assert(a ~= b, "Invalid step size") -- AF_ERR_ARG - end - - assert(not(b >= 0 and a >= 0 and SignBit(b - a) ~= SignBit(c)), "Sequence is invalid") -- AF_ERR_ARG - - return _MakeSeq_(a, b, c) - else -- a: length - if a and a < 0 then - return _MakeSeq_(0, a, 1) - else - return _MakeSeq_(0, (a or 0) - 1, 1) - end - end - end - - -- - local function AuxToArray (env, seq) - local diff = seq["end"] - seq.begin - local len = (diff + abs(seq.step) * (SignBit(diff) == 0 and 1 or -1)) / seq.step - local range = GetLib().range - local tmp = seq.m_gfor and range(1, 1, 1, len, 3) or range(len) - - return env(seq.begin + seq.step * tmp) - end - - --- DOCME - function array_module.SeqToArray (seq) - return CallWithEnvironment(AuxToArray, seq) - end - - -- Cache module members. - _IsSeq_ = array_module.IsSeq - _MakeSeq_ = array_module.MakeSeq -end - --- -SeqMT.__index = SeqMT -SeqMT.__metatable = MetaValue - --- TODO: Add "seq" environment type? - --- Export the module. -return M \ No newline at end of file diff --git a/wrapper/arrayfire/methods/constructors.lua b/wrapper/arrayfire/methods/constructors.lua deleted file mode 100644 index 984fea5..0000000 --- a/wrapper/arrayfire/methods/constructors.lua +++ /dev/null @@ -1,242 +0,0 @@ ---- Array constructors. - --- Standard library imports -- -local assert = assert -local error = error -local select = select -local type = type -local unpack = unpack - --- Modules -- -local af = require("arrayfire_lib") -local array = require("impl.array") - --- Imports -- -local CallWrap = array.CallWrap -local IsArray = array.IsArray -local IsSeq = array.IsSeq -local SeqToArray = array.SeqToArray -local ToType = array.ToType -local WrapArray = array.WrapArray - --- Exports -- -local M = {} - --- See also: https://github.com/arrayfire/arrayfire/blob/devel/src/api/cpp/array.cpp --- https://github.com/arrayfire/arrayfire/blob/devel/src/api/cpp/data.cpp - --- TODO: put these somewhere better... might need to fix up some things? - --- -local function GetElements (dims) - return dims[1] * dims[2] * dims[3] * dims[4] -end - --- -local function GetNDims (dims) - local num = GetElements(dims) - - if num < 2 then - return num - else - for i = 4, 2, -1 do - if dims[i] ~= 1 then - return i - end - end - end - - return 1 -end - --- -- -local DimsAndType = {} - -local function GetDimsAndType (...) - -- - DimsAndType[1], DimsAndType[2], DimsAndType[3], DimsAndType[4], DimsAndType[5] = ... - - -- - local n = 0 - - while type(DimsAndType[n + 1]) == "number" do - n = n + 1 - end - - local last, dtype = DimsAndType[n + 1] - local last_type = n > 0 and type(last) - - if last_type == "string" or last_type == "table" then - if last_type == "table" then - dtype, DimsAndType[n + 1] = last -- remove table ref - else - dtype = af[last] - end - end - - -- - local dims = DimsAndType - - if type(DimsAndType[1]) == "table" then - dims, n, DimsAndType[1] = DimsAndType[1], 4 -- remove table ref - end - - return n, dims, dtype -end - --- -local function DimsAndTypeFunc (func) - return function(...) - local n, dims, dtype = GetDimsAndType(...) - - return CallWrap(func, n, dims, dtype or af.f32) - end -end - --- -- -local Dims = DimsAndType - --- -local function PrepDims (d0, d1, d2, d3) - Dims[1], Dims[2], Dims[3], Dims[4] = d0, d1 or 1, d2 or 1, d3 or 1 - - return Dims -end - --- -local function InitEmptyArray (dtype, d0, d1, d2, d3) - return CallWrap("af_create_handle", 4, PrepDims(d0, d1, d2, d3), dtype) -end - --- -local function InitDataArray (dtype, ptr, src, d0, d1, d2, d3) - local func - - if src == "afHost" then - func = "af_create_array" - elseif src == "afDevice" then - func = "af_device_array" - else - error("Can not create array from the requested source pointer") -- TODO: AF_ERR_ARG? - end - - return CallWrap(func, ptr, 4, PrepDims(d0, d1, d2, d3), af[dtype]) -end - --- -function M.Add (into) - for k, v in pairs{ - -- - array = function(a, b, c, d, e, f) - if b == "handle" then -- a: handle, b: "handle" - return WrapArray(a) - elseif IsArray(a) then - if type(b) == "table" then -- a: input, b: dims - return CallWrap("af_moddims", a:get(), 4, b) - elseif b then -- a: input, b...e: dims - return CallWrap("af_moddims", a:get(), 4, PrepDims(b, c, d, e)) - else -- a: input - return CallWrap("af_retain_array", a:get()) - end - elseif IsSeq(a) then -- a: seq - return SeqToArray(a) - elseif type(a) == "table" then - if type(b) == "table" then -- a: dims, b: ptr, c: src - return InitDataArray("f32", b, c or "afHost", a[1], a[2], a[3], a[4]) - else -- a: dims, b: type - return InitEmptyArray(af[b or "f32"], a[1], a[2], a[3], a[4]) - end - elseif a then - local n, dims, dtype = GetDimsAndType(a, b, c, d, e) - - if type(dtype) == "table" then -- a...: dims, second-to-last: ptr, last?: source - return InitDataArray("f32", dtype, select(n + 2, a, b, c, d, e, f) or "afHost", unpack(dims, 1, n)) - else -- a...: dims, last?: type - return InitEmptyArray(dtype or af.f32, unpack(dims, 1, n)) - end - else - return InitEmptyArray(af.f32, 0, 0, 0, 0) - end - end, - - -- - constant = function(value, ...) - local n, dims, dtype = GetDimsAndType(...) - - if type(value) == "table" then - if dtype == "c32" or dtype == "c64" then - return CallWrap("af_constant_complex", value.real, value.imag, n, dims, dtype) - else - value = value.real -- TODO: syntax? (ditto above) - end - end - - if dtype == "s64" or dtype == "u64" then - local name = dtype == "s64" and "af_constant_long" or "af_constant_ulong" - - return CallWrap(name, value, n, dims) - else - return CallWrap("af_constant", value, n, dims, dtype or af.f32) - end - end, - - -- - diag = function(in_arr, num, extract) - if extract == nil then - extract = true - end - - return CallWrap(extract and "af_diag_extract" or "af_diag_create", in_arr:get(), num or 0) - end, - - -- - flat = function(in_arr) - return CallWrap("af_flat", in_arr:get()) - end, - - -- - identity = DimsAndTypeFunc("af_identity"), - - -- - moddims = function(in_arr, a, b, c, d) - local ndims, dims - - if type(a) == "table" then -- a: dims - ndims, dims = GetNDims(a), a - elseif type(b) == "table" then -- a: ndims, b: dims - ndims, dims = a, b - else -- a: d0, b: d1, c: d2, d: d3 - ndims, dims = 4, PrepDims(a, b, c, d) - end - - return CallWrap("af_moddims", in_arr:get(), ndims, dims) - end, - - -- - randn = DimsAndTypeFunc("af_randn"), - - -- - randu = DimsAndTypeFunc("af_randu"), - - -- - range = function(a, b, c, d, e, f) - local dims, seq_dim, dtype - - if type(a) == "table" then -- a: dims, b: seq_dim, c: type - dims, seq_dim, dtype = a, b, c - else -- a: dim0, b: dim1, c: dim2, d: dim3, e: seq_dim, f: type - dims, seq_dim, dtype = PrepDims(a, b, c, d), e, f - end - - return CallWrap("af_range", GetNDims(dims), dims, seq_dim or -1, af[dtype or "f32"]) - end, - - -- - seq = array.NewSeq - } do - into[k] = v - end -end - --- Export the module. -return M \ No newline at end of file diff --git a/wrapper/arrayfire/methods/device.lua b/wrapper/arrayfire/methods/device.lua deleted file mode 100644 index 6424125..0000000 --- a/wrapper/arrayfire/methods/device.lua +++ /dev/null @@ -1,37 +0,0 @@ ---- Device functions. - --- Modules -- -local af = require("arrayfire_lib") -local array = require("impl.array") - --- Imports -- -local Call = array.Call - --- Exports -- -local M = {} - --- -function M.Add (into) - -- - for k, v in pairs{ - -- - info = function() - Call("af_info") - end, - - -- - setDevice = function(device) - Call("af_set_device", device) - end, - - -- - sync = function(device) - Call("af_sync", device or -1) - end - } do - into[k] = v - end -end - --- Export the module. -return M \ No newline at end of file diff --git a/wrapper/arrayfire/methods/methods.lua b/wrapper/arrayfire/methods/methods.lua deleted file mode 100644 index 7bb0f1a..0000000 --- a/wrapper/arrayfire/methods/methods.lua +++ /dev/null @@ -1,141 +0,0 @@ ---- Array methods. - --- Modules -- -local af = require("arrayfire_lib") - --- Exports -- -local M = {} - --- See also: https://github.com/arrayfire/arrayfire/blob/devel/src/api/cpp/array.cpp - --- -- -local Dims = {} - --- -function M.Add (array_module, meta) - local Call = array_module.Call - local CallWrap = array_module.CallWrap - local GetLib = array_module.GetLib - - -- - local function Get (name) - name = "af_" .. name - - return function(arr) - return Call(name, arr:get()) - end - end - - -- -- - local SizeOf = {} - - for prefix, size in ("f32 f64 s32 u32 s64 u64 u8 b8 c32 c64 s16 u16"):gmatch "(%a)(%d+)" do - local k = af[prefix .. size] - - if k then -- account for earlier versions - SizeOf[k] = tonumber(size) / (prefix == "c" and 4 or 8) -- 8 bits to a byte; double complex types - end - end - - -- - for k, v in pairs{ - -- - as = function(arr, atype) - return CallWrap("af_cast", arr:get(), af[atype]) - end, - - -- - bytes = function(arr) - local ha = arr:get() - local n, dtype = Call("af_get_elements", ha), Call("af_get_type", ha) - - return n * (SizeOf[dtype] or 4) - end, - - -- - copy = function(arr) - return CallWrap("af_copy_array", arr:get()) - end, - - -- - dims = function(arr, i) - if i then - return GetLib().getDims(arr, Dims)[i + 1] - else - return GetLib().getDims(arr) - end - end, - - -- - elements = Get("get_elements"), - - -- - eval = function(arr) - Call("af_eval", arr:get()) - end, - - -- - get = array_module.GetHandle, - - -- - isbool = Get("is_bool"), - - -- - iscolumn = Get("is_column"), - - -- - iscomplex = Get("is_complex"), - - -- - isdouble = Get("is_double"), - - -- - isempty = Get("is_empty"), - - -- - isfloating = Get("is_floating"), - - -- - isinteger = Get("is_integer"), - - -- - isrealfloating = Get("is_real_floating"), - - -- - isrow = Get("is_row"), - - -- - isscalar = Get("is_scalar"), - - -- - issingle = Get("is_single"), - - -- - isvector = Get("is_vector"), - - -- - H = function(arr) - return GetLib().transpose(arr, true) - end, - - -- - numdims = function(arr) - return GetLib().numDims(arr) - end, - - -- - set = array_module.SetHandle, - - -- - T = function(arr) - return GetLib().transpose(arr) - end, - - type = Get("get_type") - } do - meta[k] = v - end -end - --- Export the module. -return M \ No newline at end of file diff --git a/wrapper/arrayfire/methods/move_reorder.lua b/wrapper/arrayfire/methods/move_reorder.lua deleted file mode 100644 index 94661c1..0000000 --- a/wrapper/arrayfire/methods/move_reorder.lua +++ /dev/null @@ -1,69 +0,0 @@ ---- Move and reorder operations. - --- Standard library imports -- -local type = type - --- Modules -- -local af = require("arrayfire_lib") -local array = require("impl.array") - --- Imports -- -local CallWrap = array.CallWrap -local CheckError = array.CheckError -local IsArray = array.IsArray -local WrapArray = array.WrapArray - --- Exports -- -local M = {} - --- See also: https://github.com/arrayfire/arrayfire/blob/devel/src/api/cpp/data.cpp - --- -- -local Arrays = {} - --- -function M.Add (into) - for k, v in pairs{ - -- - flip = function(in_arr, dim) - return CallWrap("af_flip", in_arr:get(), dim) - end, - - -- - join = function(dim, a1, a2, a3, a4) - if IsArray(a3) then -- three or four arrays - Arrays[1], Arrays[2], Arrays[3] = a1:get(), a2:get(), a3:get() - - if IsArray(a4) then -- four arrays - Arrays[4] = a4:get() - end - - local err, arr = af.af_join_many(dim, Arrays[4] and 4 or 3, Arrays) - - Arrays[1], Arrays[2], Arrays[3], Arrays[4] = nil - - CheckError(err) -- do after wiping Arrays - - return WrapArray(arr) - else -- two arrays - return CallWrap("af_join", dim, a1:get(), a2:get()) - end - end, - - -- - tile = function(in_arr, a, b, c, d) - if type(a) == "table" then -- a: dims - a, b, c, d = a[1], a[2], a[3], a[4] - else -- a: x, b: y, c: z, d: w - b, c, d = b or 1, c or 1, d or 1 - end - - return CallWrap("af_tile", in_arr:get(), a, b, c, d) - end - } do - into[k] = v - end -end - --- Export the module. -return M \ No newline at end of file diff --git a/wrapper/arrayfire/misc/env_loop.lua b/wrapper/arrayfire/misc/env_loop.lua deleted file mode 100644 index 8d5b658..0000000 --- a/wrapper/arrayfire/misc/env_loop.lua +++ /dev/null @@ -1,150 +0,0 @@ ---- Ephemeral environment-based loops. - --- Standard library imports -- -local remove = table.remove - --- Modules -- -local array = require("impl.array") - --- Imports -- -local CallWithEnvironment = array.CallWithEnvironment -local CallWithEnvironment_Args = array.CallWithEnvironment_Args - --- Exports -- -local M = {} - --- -- -local EnvArgsStack = {} - --- -local function GetEnvArgs (mode) - local env_args = remove(EnvArgsStack) or {} - - env_args.mode, env_args.step = mode - - return env_args -end - --- -local function AuxEnvIter (env_args) - local inc, i1, ok = env_args.inc, env_args.step - - if env_args.stop_loop then - env_args.stop_loop = nil - else - i1 = i1 + inc - - if inc > 0 then - ok = i1 <= env_args.i2 - else - ok = i2 >= env_args.i2 - end - end - - if ok then - env_args.step = i1 - - return env_args - else - EnvArgsStack[#EnvArgsStack + 1] = env_args - end -end - --- -local function EnvIter (mode, i1, i2, inc) - inc = inc or 1 - - local env_args = GetEnvArgs(mode) - - env_args.inc, env_args.step, env_args.i2 = inc, i1 - inc, i2 - - return AuxEnvIter, env_args -end - --- -function M.Add (into) - for k, v in pairs{ - -- - EnvLoopFromTo = function(i1, i2, func, ...) - for args in EnvIter(nil, i1, i2) do - args.stop_loop = CallWithEnvironment_Args(func, args, ...) == "stop_loop" - end - end, - - -- - EnvLoopFromTo_Mode = function(i1, i2, mode, func, ...) - for args in EnvIter(mode, i1, i2) do - args.stop_loop = CallWithEnvironment_Args(func, args, ...) == "stop_loop" - end - end, - - -- - EnvLoopFromToStep = function(i1, i2, step, func, ...) - for args in EnvIter(nil, i1, i2, step) do - args.stop_loop = CallWithEnvironment_Args(func, args, ...) == "stop_loop" - end - end, - - -- - EnvLoopFromToStep_Mode = function(i1, i2, step, mode, func, ...) - for args in EnvIter(mode, i1, i2, step) do - args.stop_loop = CallWithEnvironment_Args(func, args, ...) == "stop_loop" - end - end, - - -- - EnvLoopN = function(n, func, ...) - for args in EnvIter(nil, 1, n) do - args.stop_loop = CallWithEnvironment_Args(func, args, ...) == "stop_loop" - end - end, - - -- - EnvLoopN_Mode = function(n, func, mode, ...) - for args in EnvIter(mode, 1, n) do - args.stop_loop = CallWithEnvironment_Args(func, args, ...) == "stop_loop" - end - end, - - -- - EnvLoopUntil = function(func, pred, ...) - repeat - CallWithEnvironment(func, ...) - until pred(...) - end, - - -- - EnvLoopUntil_Mode = function(func, pred, mode, ...) - local args = GetEnvArgs(mode) - - repeat - CallWithEnvironment_Args(func, args, ...) - until pred(...) - - EnvArgsStack[#EnvArgsStack + 1] = args - end, - - -- - EnvLoopWhile = function(func, pred, ...) - while pred(...) do - CallWithEnvironment(func, ...) - end - end, - - -- - EnvLoopWhile_Mode = function(func, pred, mode, ...) - local args = GetEnvArgs(mode) - - while pred(...) do - CallWithEnvironment_Args(func, args, ...) - end - - EnvArgsStack[#EnvArgsStack + 1] = args - end - } do - into[k] = v - end -end - --- Export the module. -return M \ No newline at end of file diff --git a/wrapper/arrayfire/misc/imports.lua b/wrapper/arrayfire/misc/imports.lua deleted file mode 100644 index 459bd7c..0000000 --- a/wrapper/arrayfire/misc/imports.lua +++ /dev/null @@ -1,22 +0,0 @@ ---- Public imports from implementation functions. - --- Modules -- -local array = require("impl.array") - --- Exports -- -local M = {} - --- -function M.Add (into) - for k, v in pairs{ - CallWithEnvironment = array.CallWithEnvironment, - CallWithEnvironment_Args = array.CallWithEnvironment_Args, - CompareResult = array.CompareResult, - WrapConstant = array.WrapConstant - } do - into[k] = v - end -end - --- Export the module. -return M \ No newline at end of file diff --git a/wrapper/arrayfire/misc/program.lua b/wrapper/arrayfire/misc/program.lua deleted file mode 100644 index 1f766f1..0000000 --- a/wrapper/arrayfire/misc/program.lua +++ /dev/null @@ -1,252 +0,0 @@ ---- Program-related functions. - --- Standard library imports -- -local clock = os.clock -local error = error -local getenv = os.getenv -local max = math.max -local pcall = pcall -local print = print -local select = select -local tonumber = tonumber - --- Modules -- -local array = require("impl.array") - --- Imports -- -local GetLib = array.GetLib - --- Exports -- -local M = {} - --- -- -local IterPrev = 0 -local TimePrev = 0 -local MaxRate = 0 - --- -- -local T0 - --- -function M.Add (into) - for k, v in pairs{ - -- - assets = function() - return getenv("AF_PATH") .. "/assets" - end, - ---[[ -union Data -{ - unsigned dim; - char bytes[4]; -}; - -unsigned char reverse_char(unsigned char b) -{ - b = (b & 0xF0) >> 4 | (b & 0x0F) << 4; - b = (b & 0xCC) >> 2 | (b & 0x33) << 2; - b = (b & 0xAA) >> 1 | (b & 0x55) << 1; - return b; -} - -// http://stackoverflow.com/a/9144870/2192361 -unsigned reverse(unsigned x) -{ - x = ((x >> 1) & 0x55555555u) | ((x & 0x55555555u) << 1); - x = ((x >> 2) & 0x33333333u) | ((x & 0x33333333u) << 2); - x = ((x >> 4) & 0x0f0f0f0fu) | ((x & 0x0f0f0f0fu) << 4); - x = ((x >> 8) & 0x00ff00ffu) | ((x & 0x00ff00ffu) << 8); - x = ((x >> 16) & 0xffffu) | ((x & 0xffffu) << 16); - return x; -} - -template -void read_idx(std::vector &dims, std::vector &data, const char *name) -{ - std::ifstream f(name, std::ios::in | std::ios::binary); - if (!f.is_open()) throw std::runtime_error("Unable to open file"); - - Data d; - f.read(d.bytes, sizeof(d.bytes)); - - if (d.bytes[2] != 8) { - throw std::runtime_error("Unsupported data type"); - } - - unsigned numdims = d.bytes[3]; - unsigned elemsize = 1; - - // Read the dimensions - size_t elem = 1; - dims = std::vector(numdims); - for (unsigned i = 0; i < numdims; i++) { - f.read(d.bytes, sizeof(d.bytes)); - - // Big endian to little endian - for (int j = 0; j < 4; j++) d.bytes[j] = reverse_char(d.bytes[j]); - unsigned dim = reverse(d.dim); - - elem *= dim; - dims[i] = (dim_t)dim; - } - - // Read the data - std::vector cdata(elem); - f.read(&cdata[0], elem * elemsize); - std::vector ucdata(cdata.begin(), cdata.end()); - - data = std::vector(ucdata.begin(), ucdata.end()); - - f.close(); - return; -} -]] - - -- - main = function(func, ...) - local argc, argv = select("#", ...), { ... } - - for i = 1, argc do -- Mimic C array - argv[i - 1] = argv[i] - end - - argv[argc] = nil - - local ok, err = pcall(function() - local device = argc > 1 and tonumber(argv[1]) or 0 - local Lib = GetLib() - - -- Select a device and display arrayfire info - Lib.setDevice(device) - Lib.info() - - func(argc, argv) - - if getenv("windir") ~= nil then -- pause in Windows - if not (arc == 2 and argv[1]:sub(1, 1) == "-") then - print("hit [enter]...") - io.output():flush() - -- getchar() io.input():read()? - end - end - end) - - if not ok then - print(err) -- TODO: more informative - error("aborting") - end - end, - - -- ^^^ TODO: setfenv() / _ENV variant? - -- Also, rearrange for exit stuff? - -- Are the windows redirecting IO? - - -- - progress = function(iter_curr, t, time_total) - local Lib = GetLib() - - Lib.sync() - - local time_curr = Lib.timer_stop(t) - - if time_curr - TimePrev < 1 then - return true - end - - local rate = (iter_curr - IterPrev) / (time_curr - TimePrev) - - Lib.printf(" iterations per second: %.0f (progress %.0f%%)", rate, 100.0 * time_curr / time_total) - - MaxRate = max(MaxRate, rate) - - IterPrev = iter_curr - TimePrev = time_curr - - if time_curr < time_total then - return true - end - - Lib.printf(" ### %f iterations per second (max)", MaxRate) - return false - end, - - -- - timeit = function(func) - local t0 = clock() - - func() - - return clock() - t0 - end, - - -- - timer_start = function() - T0 = clock() - end, - - -- - timer_stop = function(since) - return clock() - (since or T0) - end, - - -- - wait_for_windows = function(how, w1, w2, w3) - -- - return function() - local is_open - - if w3 and w3:close() then - is_open = false - elseif w2 and w2:close() then - is_open = false - else - is_open = not w1:close() - end - - if how == "until" then - return not is_open - else - return is_open - end - end - end, - - -- - wait_for_windows_close = function(how, w1, w2, w3) - local going = GetLib().wait_for_windows(how, w1, w2, w3) - - return function() - local is_going = going() - local is_open = is_going - - if how == "until" then - is_open = not is_open - end - - if not is_open then - if not w1:close() then - w1:destroy() -- TODO: Do this right... how? - end - - if w2 and not w2:close() then - w2:destroy() - end - - if w3 and not w3:close() then - w3:destroy() - end - end - - return is_going - end - -- - end - -- ^^^ TODO: Better stuff? (resolution, instantiable?) - } do - into[k] = v - end -end - --- Export the module. -return M \ No newline at end of file