MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / BoxMullerTransform

Function BoxMullerTransform

tensorflow/compiler/xla/client/lib/prng.cc:425–432  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

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
425std::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

Callers 1

Calls 6

ScalarLikeFunction · 0.85
MaxFunction · 0.50
SqrtFunction · 0.50
LogFunction · 0.50
SinFunction · 0.50
CosFunction · 0.50

Tested by

no test coverage detected