Theano Op in Python for CPU
As a mathematical compilation engine, Theano's purpose is to compile a graph of computations in an optimal way for a target platform.
The development of new operators is possible in Python or C for compilation either on the CPU or GPU.
First, we address the simplest case, in Python for CPU, which will enable you to add new operations very easily and quickly.
To fix the ideas, let's implement a simple affine operator that performs the affine transformation a * x + b, given x as the input.
The operator is defined by a class deriving from the generic theano.Op
class:
import theano, numpy class AXPBOp(theano.Op): """ This creates an Op that takes x to a*x+b. """ __props__ = ("a", "b") def __init__(self, a, b): self.a = a self.b = b super(AXPBOp, self).__init__() def make_node(self, x): x = theano.tensor.as_tensor_variable(x) return theano.Apply...