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

Merge pull request !5319 from chenjianping/lite_dev2
This commit is contained in:
mindspore-ci-bot 2020-08-27 19:45:31 +08:00 committed by Gitee
commit 83b9d1c57d
1 changed files with 8 additions and 1 deletions

View File

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