fix doctest of function.py
@@ -495,28 +495,29 @@ class FunctionHook(object):
in this way are registered to all functions within ``with`` statement
and are unregistered at the end of ``with`` statement.
+ .. admonition:: Example
+
The following code is a simple example in which
we measure the elapsed time of a part of forward propagation procedure
with :class:`~chainer.function_hooks.TimerHook`, which is a subclass of
:class:`~chainer.function.FunctionHook`.
- >>> import chainer, chainer.links as L, chainer.functions as F
- ... class Model(chainer.Chain):
+ >>> class Model(chainer.Chain):
... def __call__(self, x1):
... return F.exp(self.l(x1))
- ... model1 = Model(l=L.Linear(10, 10))
- ... model2 = Model(l=L.Linear(10, 10))
- ... x = chainer.Variable(numpy.zeros((1, 10), 'f'))
- ... with chainer.function_hooks.TimerHook() as m:
+ >>> model1 = Model(l=L.Linear(10, 10))
+ >>> model2 = Model(l=L.Linear(10, 10))
+ >>> x = chainer.Variable(np.zeros((1, 10), 'f'))
+ >>> with chainer.function_hooks.TimerHook() as m:
... _ = model1(x)
... y = model2(x)
- ... print(m.total_time())
+ ... # print(m.total_time())
... model3 = Model(l=L.Linear(10, 10))
... z = model3(y)
- In this example, we measure the elapsed times for each forward propagation
- of all functions in ``model1`` and ``model2`` (specifically,
- :class:`~chainer.functions.LinearFunction` and
+ In this example, we measure the elapsed times for each forward
+ propagation of all functions in ``model1`` and ``model2``
+ (specifically, :class:`~chainer.functions.LinearFunction` and
:class:`~chainer.functions.Exp` of ``model1`` and ``model2``).
Note that ``model3`` is not a target of measurement
as :class:`~chainer.function_hooks.TimerHook` is unregistered
