optimize tanh

This commit is contained in:
chenjianping 2020-08-27 19:23:25 +08:00
parent b346f0b3ec
commit a61bfd87c7
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;
}