Move call to log and fmaxf outside of inner loop. (#745)

This commit is contained in:
Scott McKay 2019-04-01 15:19:21 +10:00 committed by GitHub
parent 40839f1f84
commit f4b47ad9f6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -79,8 +79,9 @@ common::Status SoftmaxCPU(const int64_t N,
}
} else {
for (int i = 0; i < N; ++i) {
auto log_fmaxf_scale_i = log(fmaxf(scale[i], 1e-20f));
for (int j = 0; j < D; ++j) {
Ydata[i * D + j] = Xdata[i * D + j] - rowmax[i] - log(fmaxf(scale[i], 1e-20f));
Ydata[i * D + j] = Xdata[i * D + j] - rowmax[i] - log_fmaxf_scale_i;
}
}
}