Register the merge opt in the gpu optimizer.

This make the graph smaller faster, so it speed up optimization
Faster gpu opt: use isinstance instead of ==, as it is faster.

Also import a module in an opt only once.
Make PatternSub simpler.
Speed up gpu opt by iterating less frequently on the graph.
remove the inplace tag to a not inplace opt.
Register constant_folding during gpu opt.

This give a small speed up.
small speed up
replace numpy.all/any to all/any, faster.

also a few pep8, as we support python 2.6+ now this is valid.
gemm opt speed up: small refactoring to call less fct.
Refactor condition and use isinstance
Define local fct outside of the loop.
Make simpler tests that was crashing as I restricted too much the exception catched.

I review the code, we always put a tuple or a Theano variable in that
list. We only want to work with the tuple case. So just test for the
tuple. We don't want to cover the case where we have a Theano vector
with a know lenght.
Merge pull request #1779 from nouiz/faster_opt

Faster opt