MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / drawFromGaussianPdf

Function drawFromGaussianPdf

pocs/vdot/vdot.cpp:19–30  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

17constexpr int kVecSize = 1 << 18;
18
19static float drawFromGaussianPdf(std::mt19937& rndm) {
20 constexpr double kScale = 1./(1. + std::mt19937::max());
21 constexpr double kTwoPiTimesScale = 6.28318530717958647692*kScale;
22 static float lastX;
23 static bool haveX = false;
24 if (haveX) { haveX = false; return lastX; }
25 auto r = sqrt(-2*log(1 - kScale*rndm()));
26 auto phi = kTwoPiTimesScale * rndm();
27 lastX = r*sin(phi);
28 haveX = true;
29 return r*cos(phi);
30}
31
32static void fillRandomGaussianFloats(std::vector<float>& values, std::mt19937& rndm, float mean = 0) {
33 for (auto& v : values) v = mean + drawFromGaussianPdf(rndm);

Callers 1

fillRandomGaussianFloatsFunction · 0.70

Calls 5

maxFunction · 0.85
sqrtFunction · 0.85
logFunction · 0.85
sinFunction · 0.85
cosFunction · 0.85

Tested by

no test coverage detected