提交 6b02f8ca authored 作者: Frédéric Bastien's avatar Frédéric Bastien

Merge pull request #4030 from hantek/fixtesterr

solving doc test failures
......@@ -66,7 +66,7 @@ script:
- cd -; cd Theano
- theano-nose -v $PART
- if [[ $DOC == "1" ]]; then python doc/scripts/docgen.py --nopdf --check; fi
# - if [[ $DOC == "1" ]]; then python doc/scripts/docgen.py --test --check; fi
- if [[ $DOC == "1" ]]; then python doc/scripts/docgen.py --test --check; fi
after_failure:
- cat /home/travis/.pip/pip.log
......@@ -41,14 +41,14 @@ Conditions
n_times = 10
tic = time.clock()
for i in xrange(n_times):
for i in range(n_times):
f_switch(val1, val2, big_mat1, big_mat2)
print 'time spent evaluating both values %f sec'%(time.clock()-tic)
print('time spent evaluating both values %f sec' % (time.clock()-tic))
tic = time.clock()
for i in xrange(n_times):
for i in range(n_times):
f_lazyifelse(val1, val2, big_mat1, big_mat2)
print 'time spent evaluating one value %f sec'%(time.clock()-tic)
print('time spent evaluating one value %f sec' % (time.clock()-tic))
.. testoutput::
:hide:
......@@ -142,7 +142,7 @@ Loops
outputs=polynomial)
test_coeff = numpy.asarray([1, 0, 2], dtype=numpy.float32)
print calculate_polynomial(test_coeff, 3)
print(calculate_polynomial(test_coeff, 3))
.. testoutput::
......
......@@ -350,7 +350,7 @@ Example: Op definition
return eval_points
return self.grad(inputs, eval_points)
doubleOp2 = DoubleOp2()
doubleOp2 = DoubleOp2()
At a high level, the code fragment declares a class (e.g., ``DoubleOp1``) and then
creates one instance of it (e.g., ``doubleOp1``).
......@@ -412,8 +412,9 @@ but it must not influence the semantics of the Op output.
You can try the new Op as follows:
.. testcode:: example(Using make_node)
.. testcode:: example
import theano
x = theano.tensor.matrix()
f = theano.function([x], DoubleOp1()(x))
import numpy
......@@ -425,10 +426,9 @@ You can try the new Op as follows:
.. testoutput:: example
:hide:
:options: +ELLIPSIS
...
...
:options: +ELLIPSIS, +SKIP
<BLANKLINE>
.. code-block:: none
......@@ -443,8 +443,9 @@ You can try the new Op as follows:
[ 1.5465443 1.30803715 1.53125983 1.88291403]
[ 1.6904152 0.61000201 1.76861002 1.9163731 ]]
.. testcode:: example (Using itypes and otypes)
.. testcode:: example
import theano
x = theano.tensor.matrix()
f = theano.function([x], DoubleOp2()(x))
import numpy
......@@ -457,10 +458,9 @@ You can try the new Op as follows:
.. testoutput:: example
:hide:
:options: +ELLIPSIS
:options: +ELLIPSIS, +SKIP
...
...
<BLANKLINE>
.. code-block:: none
......@@ -503,8 +503,8 @@ and ``b`` are equal.
def make_node(self, x):
# check that the theano version has support for __props__.
assert hasattr(self, '_props'), "Your version of theano is too old
to support __props__."
assert hasattr(self, '_props'), ("Your version of theano is too"
"old to support __props__.")
x = theano.tensor.as_tensor_variable(x)
return theano.Apply(self, [x], [x.type()])
......
......@@ -156,9 +156,6 @@ the params type.
return ("%(z)s = %(x)s * PyFloat_AsDouble(%(p)s);" %
dict(z=outputs[0], x=inputs[0], p=sub['params']))
.. testoutput::
:hide:
A more complex example
----------------------
......@@ -225,5 +222,3 @@ weights.
%(z)s = alpha_%(name)s * %(x)s + beta_%(name)s * %(y)s;
""" % dict(name=name, z=outputs[0], x=inputs[0], y=inputs[1])
.. testoutput::
:hide:
......@@ -420,9 +420,9 @@ Create a test file containing:
t_start = time.time()
tAB = mf(A,B)
t_end = time.time()
print "NP time: %f[s], theano time: %f[s] (times should be close when run on CPU!)" %(
np_end-np_start, t_end-t_start)
print "Result difference: %f" % (np.abs(AB-tAB).max(), )
print("NP time: %f[s], theano time: %f[s] (times should be close when run on CPU!)" %(
np_end-np_start, t_end-t_start))
print("Result difference: %f" % (np.abs(AB-tAB).max(), ))
.. testoutput::
:hide:
......
......@@ -187,7 +187,7 @@ downcast** of the latter.
# test
some_num = 15
print(triangular_sequence(some_num))
print([n * (n + 1) // 2 for n in xrange(some_num)])
print([n * (n + 1) // 2 for n in range(some_num)])
.. testoutput::
......
......@@ -336,7 +336,7 @@ shows how to print all inputs and outputs:
end='')
def inspect_outputs(i, node, fn):
print("output(s) value(s):", [output[0] for output in fn.outputs])
print(" output(s) value(s):", [output[0] for output in fn.outputs])
x = theano.tensor.dscalar('x')
f = theano.function([x], [5 * x],
......
......@@ -125,7 +125,7 @@ array(35.0)
This makes use of the :ref:`In <function_inputs>` class which allows
you to specify properties of your function's parameters with greater detail. Here we
give a default value of 1 for *y* by creating a ``In`` instance with
its ``default`` field set to 1.
its ``value`` field set to 1.
Inputs with default values must follow inputs without default
values (like Python's functions). There can be multiple inputs with default values. These parameters can
......@@ -206,15 +206,15 @@ Let's try it out!
.. If you modify this code, also change :
.. theano/tests/test_tutorial.py:T_examples.test_examples_8
>>> state.get_value()
>>> print(state.get_value())
0
>>> accumulator(1)
array(0)
>>> state.get_value()
>>> print(state.get_value())
1
>>> accumulator(300)
array(1)
>>> state.get_value()
>>> print(state.get_value())
301
It is possible to reset the state. Just use the ``.set_value()`` method:
......@@ -222,7 +222,7 @@ It is possible to reset the state. Just use the ``.set_value()`` method:
>>> state.set_value(-1)
>>> accumulator(3)
array(-1)
>>> state.get_value()
>>> print(state.get_value())
2
As we mentioned above, you can define more than one function to use the same
......@@ -234,7 +234,7 @@ shared variable. These functions can all update the value.
>>> decrementor = function([inc], state, updates=[(state, state-inc)])
>>> decrementor(2)
array(2)
>>> state.get_value()
>>> print(state.get_value())
0
You might be wondering why the updates mechanism exists. You can always
......@@ -261,7 +261,7 @@ for the purpose of one particular function.
>>> skip_shared = function([inc, foo], fn_of_state, givens=[(state, foo)])
>>> skip_shared(1, 3) # we're using 3 for the state, not state.value
array(7)
>>> state.get_value() # old state still there, but we didn't use it
>>> print(state.get_value()) # old state still there, but we didn't use it
0
The ``givens`` parameter can be used to replace any symbolic variable, not just a
......
......@@ -30,10 +30,7 @@ The Basics of Pickling
The two modules ``pickle`` and ``cPickle`` have the same functionalities, but
``cPickle``, coded in C, is much faster.
.. If you modify this code, also change :
.. theano/tests/test_tutorial.py:T_loading_and_saving.test_loading_and_saving_3
>>> import cPickle
>>> from six.moves import cPickle
You can serialize (or *save*, or *pickle*) objects to a file with
``cPickle.dump``:
......@@ -42,7 +39,7 @@ You can serialize (or *save*, or *pickle*) objects to a file with
my_obj = object()
>>> f = file('obj.save', 'wb')
>>> f = open('obj.save', 'wb')
>>> cPickle.dump(my_obj, f, protocol=cPickle.HIGHEST_PROTOCOL)
>>> f.close()
......@@ -60,7 +57,7 @@ You can serialize (or *save*, or *pickle*) objects to a file with
To de-serialize (or *load*, or *unpickle*) a pickled file, use
``cPickle.load``:
>>> f = file('obj.save', 'rb')
>>> f = open('obj.save', 'rb')
>>> loaded_obj = cPickle.load(f)
>>> f.close()
......@@ -74,14 +71,14 @@ same order):
obj2 = object()
obj3 = object()
>>> f = file('objects.save', 'wb')
>>> f = open('objects.save', 'wb')
>>> for obj in [obj1, obj2, obj3]:
... cPickle.dump(obj, f, protocol=cPickle.HIGHEST_PROTOCOL)
>>> f.close()
Then:
>>> f = file('objects.save', 'rb')
>>> f = open('objects.save', 'rb')
>>> loaded_objects = []
>>> for i in range(3):
... loaded_objects.append(cPickle.load(f))
......@@ -121,7 +118,7 @@ For instance, you can define functions along the lines of:
def __setstate__(self, d):
self.__dict__.update(d)
self.training_set = cPickle.load(file(self.training_set_file, 'rb'))
self.training_set = cPickle.load(open(self.training_set_file, 'rb'))
Robust Serialization
......
......@@ -66,7 +66,7 @@ Debug Print
The pre-compilation graph:
>>> theano.printing.debugprint(prediction) # doctest: +NORMALIZE_WHITESPACE
>>> theano.printing.debugprint(prediction) # doctest: +NORMALIZE_WHITESPACE, +ELLIPSIS
Elemwise{gt,no_inplace} [id A] ''
|Elemwise{true_div,no_inplace} [id B] ''
| |DimShuffle{x} [id C] ''
......@@ -87,9 +87,9 @@ Elemwise{gt,no_inplace} [id A] ''
The post-compilation graph:
>>> theano.printing.debugprint(predict) # doctest: +NORMALIZE_WHITESPACE
>>> theano.printing.debugprint(predict) # doctest: +NORMALIZE_WHITESPACE, +ELLIPSIS
Elemwise{Composite{GT(scalar_sigmoid((-((-i0) - i1))), i2)}} [id A] '' 4
|CGemv{inplace} [id B] '' 3
|...Gemv{inplace} [id B] '' 3
| |AllocEmpty{dtype='float64'} [id C] '' 2
| | |Shape_i{0} [id D] '' 1
| | |x [id E]
......
......@@ -30,14 +30,15 @@ functions using either of the following two options:
2. Pass the argument :attr:`profile=True` to the function :func:`theano.function <function.function>`. And then call :attr:`f.profile.print_summary()` for a single function.
- Use this option when you want to profile not all the
functions but one or more specific function(s).
- You can also combine the profile of many functions:
.. testcode::
- You can also combine the profile of many functions:
.. doctest::
:hide:
profile = theano.compile.ProfileStats()
f = theano.function(..., profile=profile)
g = theano.function(..., profile=profile)
...
f = theano.function(..., profile=profile) # doctest: +SKIP
g = theano.function(..., profile=profile) # doctest: +SKIP
... # doctest: +SKIP
profile.print_summary()
......
......@@ -45,7 +45,8 @@ def function_dump(filename, inputs, outputs=None, mode=None, updates=None,
To load such a dump and do the compilation:
>>> import cPickle, theano
>>> from six.moves import cPickle
>>> import theano
>>> d = cPickle.load(open("func_dump.bin", "rb")) # doctest: +SKIP
>>> f = theano.function(**d) # doctest: +SKIP
......
......@@ -327,13 +327,13 @@ def dump(obj, file_handler, protocol=DEFAULT_PROTOCOL,
>>> import theano
>>> foo_1 = theano.shared(0, name='foo')
>>> foo_2 = theano.shared(1, name='foo')
>>> with open('model.zip', 'w') as f:
>>> with open('model.zip', 'wb') as f:
... dump((foo_1, foo_2, numpy.array(2)), f)
>>> numpy.load('model.zip').keys()
['foo', 'foo_2', 'array_0', 'pkl']
>>> numpy.load('model.zip')['foo']
array(0)
>>> with open('model.zip') as f:
>>> with open('model.zip', 'rb') as f:
... foo_1, foo_2, array = load(f)
>>> array
array(2)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论