提交 5dcad44a authored 作者: Iban Harlouchet's avatar Iban Harlouchet 提交者: Arnaud Bergeron

testcode for doc/tutorial/modes.txt

上级 b0c8223d
...@@ -43,7 +43,7 @@ Exercise ...@@ -43,7 +43,7 @@ Exercise
Consider the logistic regression: Consider the logistic regression:
.. code-block:: python .. testcode::
import numpy import numpy
import theano import theano
...@@ -84,26 +84,76 @@ Consider the logistic regression: ...@@ -84,26 +84,76 @@ Consider the logistic regression:
if any([x.op.__class__.__name__ in ['Gemv', 'CGemv', 'Gemm', 'CGemm'] for x in if any([x.op.__class__.__name__ in ['Gemv', 'CGemv', 'Gemm', 'CGemm'] for x in
train.maker.fgraph.toposort()]): train.maker.fgraph.toposort()]):
print 'Used the cpu' print('Used the cpu')
elif any([x.op.__class__.__name__ in ['GpuGemm', 'GpuGemv'] for x in elif any([x.op.__class__.__name__ in ['GpuGemm', 'GpuGemv'] for x in
train.maker.fgraph.toposort()]): train.maker.fgraph.toposort()]):
print 'Used the gpu' print('Used the gpu')
else: else:
print 'ERROR, not able to tell if theano used the cpu or the gpu' print('ERROR, not able to tell if theano used the cpu or the gpu')
print train.maker.fgraph.toposort() print(train.maker.fgraph.toposort())
for i in range(training_steps): for i in range(training_steps):
pred, err = train(D[0], D[1]) pred, err = train(D[0], D[1])
#print "Final model:" #print "Final model:"
#print w.get_value(), b.get_value() #print w.get_value(), b.get_value()
print "target values for D" print("target values for D")
print D[1] print(D[1])
print("prediction on D")
print(predict(D[0]))
.. testoutput::
:hide:
:options: +ELLIPSIS
Used the cpu
targe values for D
...
prediction on D
...
.. code-block:: none
Used the cpu
target values for D
[ 0. 0. 1. 0. 1. 1. 0. 1. 0. 1. 0. 1. 0. 0. 0. 0. 1. 0.
1. 0. 1. 1. 0. 1. 0. 0. 1. 1. 1. 0. 1. 0. 0. 1. 1. 1.
0. 0. 0. 0. 0. 1. 1. 1. 0. 0. 1. 1. 1. 1. 1. 0. 0. 1.
0. 1. 0. 0. 1. 1. 0. 1. 1. 1. 1. 0.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 1 0 1 0 1 0 0 0 0 1 0 1 0 1 1 0 1 0 0 1 1 1 0 1 0 0 1 1 1 0
0 0 0 0 1 1 1 0 0 1 1 1 1 1 0 0 1 0 1 0 0 1 1 0 1 1 1 1 0 0 1 1 0 1 1 1 1
0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 1 0 1 0 0 0 1 1 0 1 0 1 0 1 0 1 0 1 0
0 0 1 0 0 1 1 1 0 1 1 0 0 1 0 1 1 1 0 1 1 0 0 1 0 1 0 0 1 0 0 0 1 0 0 0 0
0 1 1 1 1 1 1 0 0 1 1 0 1 0 0 0 0 1 1 1 0 0 0 1 1 1 0 1 0 0 0 0 1 1 1 1 1
0 1 1 0 0 0 0 0 1 1 1 1 1 0 1 1 1 0 1 1 0 0 0 1 1 1 0 0 0 1 0 0 1 0 1 1 1
0 1 1 1 0 0 0 1 1 0 1 0 0 1 1 0 1 1 1 0 0 1 1 1 0 1 1 1 1 0 1 0 1 0 0 0 1
0 0 1 0 0 1 0 1 0 0 0 1 0 0 0 0 0 1 1 0 1 0 0 0 0 1 0 0 0 1 0 0 0 1 1 0 1
0 0 0 0 0 0 0 1 1 1 1 1 1 1 0 0 0 1 1 1 0 1 1 1 0 1 1 0 1 1 1 0 1 1 0 0 1
1 0 1 0 1 1 1 1 1 0 0 0 1 1 0 0 1 1 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 1 1 0
0 1 1 1 0 1 1 0 0 0 1 0 1 1 1 1 1 1 0 1 1 1 1 0 0 1 1 1 1 1]
print "prediction on D"
print predict(D[0])
Modify and execute this example to run on CPU (the default) with floatX=float32 and Modify and execute this example to run on CPU (the default) with floatX=float32 and
time the execution using the command line ``time python file.py``. Save your code time the execution using the command line ``time python file.py``. Save your code
as it will be useful later on. as it will be useful later on.
...@@ -215,7 +265,7 @@ cluster!). ...@@ -215,7 +265,7 @@ cluster!).
DebugMode is used as follows: DebugMode is used as follows:
.. code-block:: python .. testcode::
x = T.dvector('x') x = T.dvector('x')
...@@ -311,7 +361,7 @@ regression example. ...@@ -311,7 +361,7 @@ regression example.
Compiling the module with ``ProfileMode`` and calling ``profmode.print_summary()`` Compiling the module with ``ProfileMode`` and calling ``profmode.print_summary()``
generates the following output: generates the following output:
.. code-block:: python .. testcode::
""" """
ProfileMode.print_summary() ProfileMode.print_summary()
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论