The original function sampleFromSalpeterDATA itself is quite slow to evaluate (in python3 at least), so it is not very surprising that it is even slower when wrapped in theano.as_op.
The best way forward I think, it’s to rewrite sampleFromSalpeter into a vectorized numpy function (without the while loop), and then extend it into a theano function.