提交 e49b58aa authored 作者: Frederic's avatar Frederic

Update comment and add doc about the new warning in the infer_shape tester.

上级 bf645558
...@@ -228,13 +228,23 @@ output. ...@@ -228,13 +228,23 @@ output.
``self._compile_and_check`` compiles a Theano function. It takes as ``self._compile_and_check`` compiles a Theano function. It takes as
parameters the lists of input and output Theano variables, as would be parameters the lists of input and output Theano variables, as would be
provided to ``theano.function``, and a list of real values to pass to the provided to ``theano.function``, and a list of real values to pass to the
compiled function (do not use symmetric shapes, e.g. (3, 3), compiled function. It also takes the op class as a parameter
as they can easily hide errors). It also takes the op class as a parameter
in order to verify that no instance of it appears in the shape-optimized graph. in order to verify that no instance of it appears in the shape-optimized graph.
If there is an error, the function raises an exception. If you want to If there is an error, the function raises an exception. If you want to
see it fail, you can implement an incorrect ``infer_shape``. see it fail, you can implement an incorrect ``infer_shape``.
When testing with input values with shapes that take the same value
over different dimensions (for instance, a square matrix, or a tensor3
with shape (n, n, n), or (m, n, m)), it is not possible to detect if
the output shape was computed correctly, or if some shapes with the
same value have been mixed up. For instance, if the infer_shape uses
the width of a matrix instead of its height, then testing with only
square matrices will not detect the problem. This is why the
``self._compile_and_check`` method print a warning in such a case. If
your op work only in such case, you can diable the warning with the
warn=True parameter.
.. code-block:: python .. code-block:: python
from theano.tests import unittest_tools as utt from theano.tests import unittest_tools as utt
......
...@@ -176,7 +176,19 @@ class InferShapeTester(unittest.TestCase): ...@@ -176,7 +176,19 @@ class InferShapeTester(unittest.TestCase):
def _compile_and_check(self, inputs, outputs, numeric_inputs, cls, def _compile_and_check(self, inputs, outputs, numeric_inputs, cls,
excluding=None, warn=True): excluding=None, warn=True):
"""This tests the infer_shape method only""" """This tests the infer_shape method only
When testing with input values with shapes that take the same
value over different dimensions (for instance, a square
matrix, or a tensor3 with shape (n, n, n), or (m, n, m)), it
is not possible to detect if the output shape was computed
correctly, or if some shapes with the same value have been
mixed up. For instance, if the infer_shape uses the width of a
matrix instead of its height, then testing with only square
matrices will not detect the problem. If warn=True, we emit a
warning when testing with such values.
"""
mode = self.mode mode = self.mode
if excluding: if excluding:
mode = mode.excluding(*excluding) mode = mode.excluding(*excluding)
...@@ -194,9 +206,12 @@ class InferShapeTester(unittest.TestCase): ...@@ -194,9 +206,12 @@ class InferShapeTester(unittest.TestCase):
else: else:
shp = inp.shape shp = inp.shape
if len(set(shp)) != len(shp): if len(set(shp)) != len(shp):
_logger.warn("While testing the shape, we received input" _logger.warn(
" with dimensions of the same shape %s! This" "While testing the shape inference, we received an"
" lower the quality of the verification.", " input with a shape that has some repeated values: %s"
", like a square matrix. This makes it impossible to"
" check if the values for these dimensions have been"
" correctly used, or if they have been mixed up.",
str(inp.shape)) str(inp.shape))
break break
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论