(x)
| 256 | def trunc_normal_(tensor, mean=0.0, std=1.0, a=-2.0, b=2.0): |
| 257 | # Method based on https://people.sc.fsu.edu/~jburkardt/presentations/truncated_normal.pdf |
| 258 | def norm_cdf(x): |
| 259 | # Computes standard normal cumulative distribution function |
| 260 | return (1.0 + math.erf(x / math.sqrt(2.0))) / 2.0 |
| 261 | |
| 262 | if (mean < a - 2 * std) or (mean > b + 2 * std): |
| 263 | warnings.warn( |