提交 a61bfd87 编写于 作者: C chenjianping

optimize tanh

上级 b346f0b3
......@@ -62,7 +62,14 @@ int Sigmoid(const float *src, int length, float *dst) {
int Tanh(const float *src, int length, float *dst) {
for (int i = 0; i < length; ++i) {
dst[i] = 1.0f - 2.0f / (exp(2 * src[i]) + 1);
float tmp_in = src[i];
if (tmp_in > 5.0) {
dst[i] = 1.0f;
} else if (tmp_in < -5.0) {
dst[i] = -1.0f;
} else {
dst[i] = 1.0f - 2.0f / (exp(2 * tmp_in) + 1);
}
}
return NNACL_OK;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册
新手
引导
客服 返回
顶部