print 'time spent evaluating both values %f sec'%(time.clock()-tic)
tic = time.clock()
for i in xrange(n_times):
f_lazyifelse(val1, val2, big_mat1, big_mat2)
print 'time spent evaluating one value %f sec'%(time.clock()-tic)
In this example, IfElse Op spend less time (about an half) than Switch
since it computes only one variable instead of both.
.. code-block:: python
>>> python ifelse_switch.py
time spent evaluating both values 0.6700 sec
time spent evaluating one value 0.3500 sec
It is actually important to use ``linker='vm'`` or ``linker='cvm'``,
otherwise IfElse will compute both variables and take the same computation
time as the Switch Op. The linker is not currently set by default to 'cvm' but
it will be in a near future.
There is not an optimization to automatically change a switch with a broadcasted scalar to an ifelse, as this is not always the faster. See this `ticket <http://trac-hg.assembla.com/theano/ticket/764>`_