From d17e801f3de1e31cd06b181f5f0acb7adb2ad08c Mon Sep 17 00:00:00 2001 From: txh18 Date: Sun, 29 Nov 2015 23:56:09 +0800 Subject: bug fix: tanh implementation could cause nan --- nerv/lib/matrix/generic/cukernel.cu | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nerv/lib/matrix/generic/cukernel.cu b/nerv/lib/matrix/generic/cukernel.cu index c82041f..1a20b4f 100644 --- a/nerv/lib/matrix/generic/cukernel.cu +++ b/nerv/lib/matrix/generic/cukernel.cu @@ -60,7 +60,8 @@ __global__ void cudak_(tanh)(const MATRIX_ELEM *a, MATRIX_ELEM *b, long idx; if (i >= nrow || j >= ncol) return; idx = j + i * stride; - b[idx] = (exp(a[idx]) - exp(-a[idx])) / (exp(a[idx]) + exp(-a[idx])); + //b[idx] = (exp(a[idx]) - exp(-a[idx])) / (exp(a[idx]) + exp(-a[idx])); //could cause nan + b[idx] = tanh(a[idx]); } __global__ void cudak_(tanh_grad)(const MATRIX_ELEM *output, -- cgit v1.2.3-70-g09d2