As Theano doesn't have einsum, this transitions everything over to functions
shared by both numpy and theano.