Skip to content

Commit

Permalink
Insert type check to Variable.__init__
Browse files Browse the repository at this point in the history
  • Loading branch information
unnonouno committed Jun 29, 2015
1 parent 6dba259 commit 1c6cecd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions chainer/variable.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ def __init__(self, data, volatile=False):
:mod:`cuda` automatically uses this allocator. :mod:`cuda` automatically uses this allocator.
""" """
assert(isinstance(data, numpy.ndarray) or
isinstance(data, cuda.GPUArray))
assert(isinstance(volatile, bool))

self.data = data self.data = data
self.rank = 0 self.rank = 0
self.volatile = volatile self.volatile = volatile
Expand Down
4 changes: 4 additions & 0 deletions tests/test_variable.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -116,3 +116,7 @@ def test_unchain_backward_gpu_retain_grad(self):
ret = self.create_linear_chain(3, False) ret = self.create_linear_chain(3, False)
ret[1].unchain_backward() ret[1].unchain_backward()
self.check_backward((ret[1], ), (ret[2], ), (ret[3], ), False) 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.