提交 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'
# Standard imports
import copy
import logging
import sys
# Third-party imports
import numpy
......@@ -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.
"""
for ctor in reversed(shared.constructors):
try:
return ctor(value, name=name, strict=strict,
allow_downcast=allow_downcast, **kwargs)
except TypeError:
continue
# This may happen when kwargs were supplied
# 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.
try:
for ctor in reversed(shared.constructors):
try:
return ctor(value, name=name, strict=strict,
allow_downcast=allow_downcast, **kwargs)
except TypeError:
continue
# This may happen when kwargs were supplied
# 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',
(value, kwargs))
shared.constructors = []
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论