提交 85b28c25 authored 作者: James Bergstra's avatar James Bergstra

rng_mrg - use numpy.seterr to suppress overflow warnings

上级 9f5955d0
...@@ -31,11 +31,15 @@ def mulmod(a, b, c, m): ...@@ -31,11 +31,15 @@ def mulmod(a, b, c, m):
def matVecModM(A, s, m): def matVecModM(A, s, m):
# return (A * s) % m # return (A * s) % m
err_orig = numpy.seterr(over='ignore')
try:
x = numpy.zeros_like(s) x = numpy.zeros_like(s)
for i in xrange(len(x)): for i in xrange(len(x)):
for j in xrange(len(s)): for j in xrange(len(s)):
x[i] = mulmod(A[i][j], s[j], x[i], m) x[i] = mulmod(A[i][j], s[j], x[i], m)
return x return x
finally:
numpy.seterr(**err_orig)
def multMatVect(v, A, m1, B, m2): def multMatVect(v, A, m1, B, m2):
#multiply the first half of v by A with a modulo of m1 #multiply the first half of v by A with a modulo of m1
...@@ -81,6 +85,8 @@ def ff_2p72(rstate): ...@@ -81,6 +85,8 @@ def ff_2p72(rstate):
return multMatVect(rstate, A1p72, M1, A2p72, M2) return multMatVect(rstate, A1p72, M1, A2p72, M2)
def mrg_next_value(rstate, new_rstate): def mrg_next_value(rstate, new_rstate):
err_orig = numpy.seterr(over='ignore')
try:
x11, x12, x13, x21, x22, x23 = rstate x11, x12, x13, x21, x22, x23 = rstate
assert type(x11) == numpy.int32 assert type(x11) == numpy.int32
...@@ -129,6 +135,8 @@ def mrg_next_value(rstate, new_rstate): ...@@ -129,6 +135,8 @@ def mrg_next_value(rstate, new_rstate):
return (x11 - x21 + M1) * NORM return (x11 - x21 + M1) * NORM
else: else:
return (x11 - x21) * NORM return (x11 - x21) * NORM
finally:
numpy.seterr(**err_orig)
class mrg_uniform_base(Op): class mrg_uniform_base(Op):
def __init__(self, output_type, inplace=False): def __init__(self, output_type, inplace=False):
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论