Did you try to warp it as a theano op using as_op
? There are similar discussion here you might found useful: Fitting a distribution with custom functions
Also, just a small tip: you can wrap your code as a Markdown code broke https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet#code