提交 96a2c0b6 authored 作者: Pascal Lamblin's avatar Pascal Lamblin

Merge pull request #2670 from bartvm/rng_weakref

Allow MRG RNG shared variables to be recognised as such
......@@ -6,6 +6,7 @@ http://www.iro.umontreal.ca/~simardr/ssj/indexe.html
"""
import warnings
import weakref
import numpy
......@@ -1220,6 +1221,8 @@ class MRG_RandomStreams(object):
u = self.pretty_return(node_rstate,
*mrg_uniform.new(node_rstate,
ndim, dtype, size))
# Add a reference to distinguish from other shared variables
node_rstate.rng_owner = weakref.ref(self)
r = u * (high - low) + low
if u.type.broadcastable != r.type.broadcastable:
......
......@@ -5,6 +5,7 @@ __docformat__ = "restructuredtext en"
import copy
import numpy
import weakref
from theano.compile.sharedvalue import (SharedVariable, shared_constructor,
shared)
......@@ -132,6 +133,8 @@ class RandomStreams(raw_random.RandomStreamsBase):
"""
seed = int(self.gen_seedgen.randint(2 ** 30))
random_state_variable = shared(numpy.random.RandomState(seed))
# Add a reference to distinguish from other shared variables
random_state_variable.rng_owner = weakref.ref(self)
new_r, out = op(random_state_variable, *args, **kwargs)
out.rng = random_state_variable
out.update = (random_state_variable, new_r)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论