提交 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,6 +180,9 @@ def shared(value, name=None, strict=False, allow_downcast=None, **kwargs): ...@@ -179,6 +180,9 @@ 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.
""" """
try:
for ctor in reversed(shared.constructors): for ctor in reversed(shared.constructors):
try: try:
return ctor(value, name=name, strict=strict, return ctor(value, name=name, strict=strict,
...@@ -190,8 +194,15 @@ def shared(value, name=None, strict=False, allow_downcast=None, **kwargs): ...@@ -190,8 +194,15 @@ def shared(value, name=None, strict=False, allow_downcast=None, **kwargs):
# #
# This was done on purpose, the rationale being that if kwargs # This was done on purpose, the rationale being that if kwargs
# were supplied, the user didn't want them to be ignored. # 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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论