Function
smelu
Source from the content-addressed store, hash-verified
| 2210 | // ---------------------------------------------------------------------------------------- |
| 2211 | |
| 2212 | void smelu ( |
| 2213 | tensor& dest, |
| 2214 | const tensor& src, |
| 2215 | const float beta |
| 2216 | ) |
| 2217 | { |
| 2218 | const float* s = src.host(); |
| 2219 | float* d = dest.host(); |
| 2220 | for (size_t i = 0; i < dest.size(); ++i) |
| 2221 | { |
| 2222 | if (s[i] >= beta) |
| 2223 | d[i] = s[i]; |
| 2224 | else if (s[i] <= -beta) |
| 2225 | d[i] = 0; |
| 2226 | else |
| 2227 | d[i] = (s[i] + beta) * (s[i] + beta) / (4 * beta); |
| 2228 | } |
| 2229 | } |
| 2230 | |
| 2231 | void smelu_gradient ( |
| 2232 | tensor& grad, |