Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/torch/nn.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'generic/Exp.c')
-rw-r--r--generic/Exp.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/generic/Exp.c b/generic/Exp.c
new file mode 100644
index 0000000..b56f379
--- /dev/null
+++ b/generic/Exp.c
@@ -0,0 +1,43 @@
+#ifndef TH_GENERIC_FILE
+#define TH_GENERIC_FILE "generic/Exp.c"
+#else
+
+static int nn_(Exp_updateOutput)(lua_State *L)
+{
+ THTensor *input = luaT_checkudata(L, 2, torch_(Tensor_id));
+ THTensor *output = luaT_getfieldcheckudata(L, 1, "output", torch_(Tensor_id));
+
+ THTensor_(resizeAs)(output, input);
+
+ TH_TENSOR_APPLY2(real, output, real, input, \
+ *output_data = exp(*input_data);)
+
+ return 1;
+}
+
+static int nn_(Exp_updateGradInput)(lua_State *L)
+{
+ THTensor *gradOutput = luaT_checkudata(L, 3, torch_(Tensor_id));
+ THTensor *output = luaT_getfieldcheckudata(L, 1, "output", torch_(Tensor_id));
+ THTensor *gradInput = luaT_getfieldcheckudata(L, 1, "gradInput", torch_(Tensor_id));
+
+ THTensor_(resizeAs)(gradInput, output);
+ TH_TENSOR_APPLY3(real, gradInput, real, gradOutput, real, output, \
+ *gradInput_data = *gradOutput_data * *output_data;);
+ return 1;
+}
+
+static const struct luaL_Reg nn_(Exp__) [] = {
+ {"Exp_updateOutput", nn_(Exp_updateOutput)},
+ {"Exp_updateGradInput", nn_(Exp_updateGradInput)},
+ {NULL, NULL}
+};
+
+static void nn_(Exp_init)(lua_State *L)
+{
+ luaT_pushmetaclass(L, torch_(Tensor_id));
+ luaT_registeratname(L, nn_(Exp__), "nn");
+ lua_pop(L,1);
+}
+
+#endif