aboutsummaryrefslogtreecommitdiffstats
path: root/src/lua
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-10-15 12:24:01 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-10-15 13:34:42 +0100
commit50ed1e6c5a60ca71fdfcf528f634ecc8cd266777 (patch)
tree6d436ac01a76b772d04e15b8ef70aa49f785f516 /src/lua
parent5b116694ef770ece14acf20c04a6d5b24aa52f01 (diff)
downloadrspamd-50ed1e6c5a60ca71fdfcf528f634ecc8cd266777.tar.gz
rspamd-50ed1e6c5a60ca71fdfcf528f634ecc8cd266777.zip
[Minor] Add function to get neural net layers
Diffstat (limited to 'src/lua')
-rw-r--r--src/lua/lua_fann.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/lua/lua_fann.c b/src/lua/lua_fann.c
index d6dd921e7..39bcb146f 100644
--- a/src/lua/lua_fann.c
+++ b/src/lua/lua_fann.c
@@ -45,6 +45,7 @@ LUA_FUNCTION_DEF (fann, save);
LUA_FUNCTION_DEF (fann, data);
LUA_FUNCTION_DEF (fann, get_inputs);
LUA_FUNCTION_DEF (fann, get_outputs);
+LUA_FUNCTION_DEF (fann, get_layers);
LUA_FUNCTION_DEF (fann, get_mse);
LUA_FUNCTION_DEF (fann, dtor);
@@ -64,6 +65,7 @@ static const struct luaL_reg fannlib_m[] = {
LUA_INTERFACE_DEF (fann, data),
LUA_INTERFACE_DEF (fann, get_inputs),
LUA_INTERFACE_DEF (fann, get_outputs),
+ LUA_INTERFACE_DEF (fann, get_layers),
LUA_INTERFACE_DEF (fann, get_mse),
{"__gc", lua_fann_dtor},
{"__tostring", rspamd_lua_class_tostring},
@@ -519,6 +521,41 @@ lua_fann_get_mse (lua_State *L)
}
/***
+ * @method rspamd_fann:get_layers()
+ * Returns array of neurons count for each layer
+ * @return {table/number} table with number ofr neurons in each layer
+ */
+static gint
+lua_fann_get_layers (lua_State *L)
+{
+#ifndef WITH_FANN
+ return 0;
+#else
+ struct fann *f = rspamd_lua_check_fann (L, 1);
+ guint nlayers, i, *layers;
+
+ if (f != NULL) {
+ nlayers = fann_get_num_layers (f);
+ layers = g_new (guint, nlayers);
+ fann_get_layer_array (f, layers);
+ lua_createtable (L, nlayers, 0);
+
+ for (i = 0; i < nlayers; i ++) {
+ lua_pushnumber (L, layers[i]);
+ lua_rawseti (L, -1, i + 1);
+ }
+
+ g_free (layers);
+ }
+ else {
+ lua_pushnil (L);
+ }
+
+ return 1;
+#endif
+}
+
+/***
* @method rspamd_fann:save(fname)
* Save fann to file named 'fname'
* @param {string} fname filename to save fann into