!5319 [MS][LITE][Develop]optimize tanh

Merge pull request !5319 from chenjianping/lite_dev2
pull/5319/MERGE
mindspore-ci-bot 5 years ago committed by Gitee
commit 83b9d1c57d

@ -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;
}

Loading…
Cancel
Save