Skip to content

Commit

Permalink
Update expected messages of type_check errors
Browse files Browse the repository at this point in the history
  • Loading branch information
toslunar committed Nov 11, 2019
1 parent 42f085e commit c70dd76
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion chainer/functions/array/reshape.py
Expand Up @@ -89,7 +89,7 @@ def reshape(x, shape):
chainer.utils.type_check.InvalidType:
Invalid operation is performed in: Reshape (Forward)
<BLANKLINE>
Expect: prod(in_types[0].shape) == prod((4, 3))
Expect: prod(x.shape) == prod((4, 3))
Actual: 8 != 12
"""
Expand Down
30 changes: 15 additions & 15 deletions docs/source/tips.rst
Expand Up @@ -109,20 +109,20 @@ Here are some examples of ``InvalidType`` errors:
import chainer.functions as F
import numpy as np

x = np.arange(10) - 5
F.relu(x)
arr = np.arange(10) - 5
F.relu(arr)

.. testoutput::

Traceback (most recent call last):
...
chainer.utils.type_check.InvalidType:
Invalid operation is performed in: ReLU (Forward)
Traceback (most recent call last):
...
chainer.utils.type_check.InvalidType:
Invalid operation is performed in: ReLU (Forward)

Expect: in_types[0].dtype.kind == f
Actual: i != f
Expect: x.dtype.kind == f
Actual: i != f

In this case, :attr:`~numpy.dtype.kind` of ``in_types[0]`` (which means the first input to the function, ``x``) is expected to be ``f`` (floating-point), whereas the input was ``i`` (signed integer).
In this case, :attr:`~numpy.dtype.kind` of ``x`` (the first argument of the function :func:`~chainer.functions.relu`) is expected to be ``f`` (floating-point), whereas the input was ``i`` (signed integer).
You need to cast the input appropriately before passing to the function (e.g., ``x.astype(np.float32)``).

.. testcode::
Expand All @@ -136,13 +136,13 @@ You need to cast the input appropriately before passing to the function (e.g., `

.. testoutput::

Traceback (most recent call last):
...
chainer.utils.type_check.InvalidType:
Invalid operation is performed in: Concat (Forward)
Traceback (most recent call last):
...
chainer.utils.type_check.InvalidType:
Invalid operation is performed in: Concat (Forward)

Expect: in_types[0].shape[0] == in_types[1].shape[0]
Actual: 4 != 3
Expect: in_types[0].shape[0] == in_types[1].shape[0]
Actual: 4 != 3

In this case, the function expects that ``x.shape[0]`` is equal to ``y.shape[0]``, but actually it was ``4`` and ``3``, respectively.

Expand Down

0 comments on commit c70dd76

Please sign in to comment.