提交 eeb9aa28 authored 作者: nouiz's avatar nouiz

Merge pull request #769 from larseeri/shared_borrow

including and testing suggestion to use 'borrow=true' flag when shared v...
...@@ -4,6 +4,7 @@ __docformat__ = 'restructuredtext en' ...@@ -4,6 +4,7 @@ __docformat__ = 'restructuredtext en'
# Standard imports # Standard imports
import copy import copy
import logging import logging
import sys
# Third-party imports # Third-party imports
import numpy import numpy
...@@ -179,19 +180,29 @@ def shared(value, name=None, strict=False, allow_downcast=None, **kwargs): ...@@ -179,19 +180,29 @@ def shared(value, name=None, strict=False, allow_downcast=None, **kwargs):
`See <http://deeplearning.net/software/theano/tutorial/aliasing.html#borrowing-when-creating-shared-variables>`_ for detail. `See <http://deeplearning.net/software/theano/tutorial/aliasing.html#borrowing-when-creating-shared-variables>`_ for detail.
""" """
for ctor in reversed(shared.constructors):
try: try:
return ctor(value, name=name, strict=strict,
allow_downcast=allow_downcast, **kwargs) for ctor in reversed(shared.constructors):
except TypeError: try:
continue return ctor(value, name=name, strict=strict,
# This may happen when kwargs were supplied allow_downcast=allow_downcast, **kwargs)
# if kwargs were given, the generic_constructor won't be callable. except TypeError:
# continue
# This was done on purpose, the rationale being that if kwargs # This may happen when kwargs were supplied
# were supplied, the user didn't want them to be ignored. # if kwargs were given, the generic_constructor won't be callable.
#
# This was done on purpose, the rationale being that if kwargs
# were supplied, the user didn't want them to be ignored.
except MemoryError, e:
e.args = e.args + ('you might consider'
' using \'theano.shared(..., borrow=True)\'',)
raise
raise TypeError('No suitable SharedVariable constructor could be found', raise TypeError('No suitable SharedVariable constructor could be found',
(value, kwargs)) (value, kwargs))
shared.constructors = [] shared.constructors = []
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论