aboutsummaryrefslogtreecommitdiff
path: root/nerv
diff options
context:
space:
mode:
authortxh18 <[email protected]>2015-11-29 23:56:09 +0800
committertxh18 <[email protected]>2015-11-29 23:56:09 +0800
commitd17e801f3de1e31cd06b181f5f0acb7adb2ad08c (patch)
tree9c291f9973f50435fe53c50dddc85c6306e3c8d5 /nerv
parentb4207a46686e899b797e70f0ace352107bbc0d54 (diff)
bug fix: tanh implementation could cause nan
Diffstat (limited to 'nerv')
-rw-r--r--nerv/lib/matrix/generic/cukernel.cu3
1 files changed, 2 insertions, 1 deletions
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,