提交 f36f5f25 authored 作者: Eric Larsen's avatar Eric Larsen 提交者: Frederic

including and testing suggestion to use 'borrow=true' flag when shared variable…

including and testing suggestion to use 'borrow=true' flag when shared variable constructor exceeds available memory
上级 272620f9
...@@ -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,19 @@ def shared(value, name=None, strict=False, allow_downcast=None, **kwargs): ...@@ -190,8 +194,19 @@ 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:
# Note: the following instruction is inappropriate as it is followed
# automatically by a misleading message from line 207
# sys.stderr.write('Insufficient memory available: you might consider'
# ' using \'theano.shared(..., borrow=True)\'')
sys.exit('Insufficient memory available: you might consider'
' using \'theano.shared(..., borrow=True)\'')
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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论