MCPcopy Create free account
hub / github.com/numpy/numpy / gauss_from_uint

Function gauss_from_uint

numpy/random/tests/test_direct.py:107–129  ·  view source on GitHub ↗
(x, n, bits)

Source from the content-addressed store, hash-verified

105
106
107def gauss_from_uint(x, n, bits):
108 if bits in (64, 63):
109 doubles = uniform_from_uint64(x)
110 elif bits == 32:
111 doubles = uniform_from_uint32(x)
112 else: # bits == 'dsfmt'
113 doubles = uniform_from_dsfmt(x)
114 gauss = []
115 loc = 0
116 x1 = x2 = 0.0
117 while len(gauss) < n:
118 r2 = 2
119 while r2 >= 1.0 or r2 == 0.0:
120 x1 = 2.0 * doubles[loc] - 1.0
121 x2 = 2.0 * doubles[loc + 1] - 1.0
122 r2 = x1 * x1 + x2 * x2
123 loc += 2
124
125 f = np.sqrt(-2.0 * np.log(r2) / r2)
126 gauss.append(f * x2)
127 gauss.append(f * x1)
128
129 return gauss[:n]
130
131
132def test_seedsequence():

Callers 1

test_gauss_invMethod · 0.85

Calls 3

uniform_from_uint64Function · 0.85
uniform_from_uint32Function · 0.85
uniform_from_dsfmtFunction · 0.85

Tested by

no test coverage detected