Tips

Reusing outputs

WRITEME

Don’t define new Ops unless you have to

It is usually not useful to define Ops that can be easilyimplemented using other already existing Ops. For example, instead ofwriting a “sum_square_difference” Op, you should probably just write asimple function:

  1. from theano import tensor as T
  2.  
  3. def sum_square_difference(a, b):
  4. return T.sum((a - b)**2)

Even without taking Theano’s optimizations into account, it is likelyto work just as well as a custom implementation. It also supports alldata types, tensors of all dimensions as well as broadcasting, whereasa custom implementation would probably only bother to supportcontiguous vectors/matrices of doubles…

Use Theano’s high order Ops when applicable

Theano provides some generic Op classes which allow you to generate alot of Ops at a lesser effort. For instance, Elemwise can be used tomake elementwise operations easily whereas DimShuffle can beused to make transpose-like transformations. These higher order Opsare mostly Tensor-related, as this is Theano’s specialty.

Op Checklist

Use this list to make sure you haven’t forgotten anything whendefining a new Op. It might not be exhaustive but it covers a lot ofcommon mistakes.

WRITEME