Skip to content

Commit

Permalink
Merge pull request #4312 from mizuno-gsinet/fnode-error-msg
Browse files Browse the repository at this point in the history
Improve error messages of array type check.
  • Loading branch information
kmaehashi committed Mar 16, 2018
2 parents 8c26e04 + df986ff commit 8e58b24
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
8 changes: 4 additions & 4 deletions chainer/function_node.py
Expand Up @@ -227,10 +227,10 @@ def apply(self, inputs):

# Check for input array types
if not chainer.is_arrays_compatible(in_data):
raise ValueError(
raise TypeError(
'incompatible array types are mixed in the forward input '
'({}).\n'
'{}'.format(
'Actual: {}'.format(
self.label,
', '.join(str(type(x)) for x in in_data)))

Expand Down Expand Up @@ -264,10 +264,10 @@ def apply(self, inputs):
'Actual: {}'.format(self.label, type(outputs)))

if not chainer.is_arrays_compatible(outputs):
raise ValueError(
raise TypeError(
'incompatible array types are mixed in the forward output '
'({}).\n'
'{}'.format(
'Actual: {}'.format(
self.label,
', '.join(str(type(x)) for x in outputs)))

Expand Down
2 changes: 1 addition & 1 deletion docs/source/upgrade.rst
Expand Up @@ -42,7 +42,7 @@ Suppose the following code:
F.maximum(v1, v2)
Prior to v4, the above code raises an exception like ``ValueError: object __array__ method not producing an array``, which was difficult to understand.
In v4, the error message would become ``ValueError: incompatible array types are mixed in the forward input (Maximum)``.
In v4, the error message would become ``TypeError: incompatible array types are mixed in the forward input (Maximum)``.
This kind of error usually occurs by mistake (for example, not performing ``to_gpu`` for some variables).

.. attention::
Expand Down
Expand Up @@ -56,13 +56,13 @@ def test_forward_gpu(self):
@attr.gpu
def test_forward_mixed_cpu_gpu_1(self):
# self.link is not sent to gpu
with self.assertRaises(ValueError):
with self.assertRaises(TypeError):
self.check_forward(cuda.to_gpu(self.x))

@attr.gpu
def test_forward_mixed_cpu_gpu_2(self):
self.link.to_gpu()
with self.assertRaises(ValueError):
with self.assertRaises(TypeError):
# self.x is not sent to gpu
self.check_forward(self.x)

Expand Down
4 changes: 2 additions & 2 deletions tests/chainer_tests/test_function_node.py
Expand Up @@ -337,7 +337,7 @@ def forward(self, inputs):
x1 = chainer.Variable(x1)
x2 = chainer.Variable(self.x2)

with self.assertRaises(ValueError):
with self.assertRaises(TypeError):
f.apply((x1, x2))

@attr.gpu
Expand All @@ -353,7 +353,7 @@ def forward(self, inputs):
x1 = chainer.Variable(self.x1)
x2 = chainer.Variable(self.x2)

with self.assertRaises(ValueError):
with self.assertRaises(TypeError):
f.apply((x1, x2))


Expand Down

0 comments on commit 8e58b24

Please sign in to comment.