提交 e1c3665a authored 作者: Bart van Merrienboer's avatar Bart van Merrienboer

Add rng_owner attribute to RandomStreams as well

上级 7f4b36c6
...@@ -5,6 +5,7 @@ __docformat__ = "restructuredtext en" ...@@ -5,6 +5,7 @@ __docformat__ = "restructuredtext en"
import copy import copy
import numpy import numpy
import weakref
from theano.compile.sharedvalue import (SharedVariable, shared_constructor, from theano.compile.sharedvalue import (SharedVariable, shared_constructor,
shared) shared)
...@@ -132,6 +133,8 @@ class RandomStreams(raw_random.RandomStreamsBase): ...@@ -132,6 +133,8 @@ class RandomStreams(raw_random.RandomStreamsBase):
""" """
seed = int(self.gen_seedgen.randint(2 ** 30)) seed = int(self.gen_seedgen.randint(2 ** 30))
random_state_variable = shared(numpy.random.RandomState(seed)) 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) new_r, out = op(random_state_variable, *args, **kwargs)
out.rng = random_state_variable out.rng = random_state_variable
out.update = (random_state_variable, new_r) out.update = (random_state_variable, new_r)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论