提交 d61c929b authored 作者: Olivier Delalleau's avatar Olivier Delalleau

Merge pull request #1142 from nouiz/err_msg3

Now raise an error if theano.shared() called with a Theano variable as d...
...@@ -182,6 +182,8 @@ def shared(value, name=None, strict=False, allow_downcast=None, **kwargs): ...@@ -182,6 +182,8 @@ def shared(value, name=None, strict=False, allow_downcast=None, **kwargs):
""" """
try: try:
if isinstance(value, Variable):
raise TypeError(" Shared variable constructor needs numeric values and not symbolic variables.")
for ctor in reversed(shared.constructors): for ctor in reversed(shared.constructors):
try: try:
......
import numpy import numpy
import unittest import unittest
import theano import theano
from theano.tensor import Tensor, TensorType from theano.tensor import Tensor, TensorType
from theano.compile.sharedvalue import * from theano.compile.sharedvalue import *
...@@ -305,3 +305,7 @@ class Test_SharedVariable(unittest.TestCase): ...@@ -305,3 +305,7 @@ class Test_SharedVariable(unittest.TestCase):
b = shared(numpy.zeros((5, 5), dtype='float32')) b = shared(numpy.zeros((5, 5), dtype='float32'))
self.assertRaises(TypeError, f, b, numpy.random.rand(5, 5)) self.assertRaises(TypeError, f, b, numpy.random.rand(5, 5))
def test_err_symbolic_variable(self):
self.assertRaises(TypeError, shared, theano.tensor.ones((2, 3)))
shared(numpy.ones((2, 4)))
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论