Permalink
Browse files

Insert type check to Variable.__init__

  • Loading branch information...
unnonouno committed Jun 29, 2015
1 parent 6dba259 commit 1c6cecdf4e8e7c5b77181dac4cf86a6d7a5c199e
Showing with 8 additions and 0 deletions.
  1. +4 −0 chainer/variable.py
  2. +4 −0 tests/test_variable.py
View
@@ -59,6 +59,10 @@ def __init__(self, data, volatile=False):
:mod:`cuda` automatically uses this allocator.
"""
assert(isinstance(data, numpy.ndarray) or
isinstance(data, cuda.GPUArray))
assert(isinstance(volatile, bool))
self.data = data
self.rank = 0
self.volatile = volatile
View
@@ -116,3 +116,7 @@ def test_unchain_backward_gpu_retain_grad(self):
ret = self.create_linear_chain(3, False)
ret[1].unchain_backward()
self.check_backward((ret[1], ), (ret[2], ), (ret[3], ), False)
def test_invalid_value_type(self):
with self.assertRaises(AssertionError):
chainer.Variable(1)

0 comments on commit 1c6cecd

Please sign in to comment.