Implements the Box-Muller transform, which converts random floats in the range of [0, 1] from uniform distribution to normal distribution with mean 0 and variance 1. For more detail on the Box-Muller transform, see http://en.wikipedia.org/wiki/Box%E2%80%93Muller_transform#Basic_form
| 423 | // and variance 1. For more detail on the Box-Muller transform, see |
| 424 | // http://en.wikipedia.org/wiki/Box%E2%80%93Muller_transform#Basic_form |
| 425 | std::pair<XlaOp, XlaOp> BoxMullerTransform(XlaOp x0, XlaOp x1) { |
| 426 | // Do not send a really small number to log(). |
| 427 | XlaOp u1 = Max(x0, ScalarLike(x0, 1.0e-7f)); |
| 428 | |
| 429 | XlaOp v1 = ScalarLike(x1, 2.0f * M_PI) * x1; |
| 430 | XlaOp u2 = Sqrt(ScalarLike(u1, -2.0f) * Log(u1)); |
| 431 | return {Sin(v1) * u2, Cos(v1) * u2}; |
| 432 | } |
| 433 | |
| 434 | } // namespace |
| 435 |
no test coverage detected