From 1f5568a9e1457dcf5aadd08749aef6194370b43f Mon Sep 17 00:00:00 2001 From: Qi Liu Date: Fri, 29 Apr 2016 16:00:20 +0800 Subject: add relu layer --- nerv/matrix/generic/matrix.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'nerv/matrix/generic/matrix.c') diff --git a/nerv/matrix/generic/matrix.c b/nerv/matrix/generic/matrix.c index 800408d..9f31b4b 100644 --- a/nerv/matrix/generic/matrix.c +++ b/nerv/matrix/generic/matrix.c @@ -430,4 +430,27 @@ static int nerv_matrix_(lua_tanh_grad)(lua_State *L) { return 0; } +static int nerv_matrix_(lua_relu)(lua_State *L) { + Status status; + MATRIX_CONTEXT *context; + MATRIX_GET_CONTEXT(L, 3); + Matrix *a = luaT_checkudata(L, 1, nerv_matrix_(tname)); + Matrix *b = luaT_checkudata(L, 2, nerv_matrix_(tname)); + nerv_matrix_(relu)(a, b, context, &status); + NERV_LUA_CHECK_STATUS(L, status); + return 0; +} + +static int nerv_matrix_(lua_relu_grad)(lua_State *L) { + Status status; + MATRIX_CONTEXT *context; + MATRIX_GET_CONTEXT(L, 4); + Matrix *nerr = luaT_checkudata(L, 1, nerv_matrix_(tname)); + Matrix *err = luaT_checkudata(L, 2, nerv_matrix_(tname)); + Matrix *output = luaT_checkudata(L, 3, nerv_matrix_(tname)); + nerv_matrix_(relu_grad)(nerr, err, output, context, &status); + NERV_LUA_CHECK_STATUS(L, status); + return 0; +} + #endif -- cgit v1.2.3