human
Complete the below
def get_neg_detection_mode():

    ''''Returns a theano Mode that detects if any negative value occurs in the
    evaluation of a theano function.'
    '''
assistant
#Here is the Python program you requested.
    class NegDetectionMode(Mode, ):
        def __init__(self):
            def flatten(l):
                if isinstance(l, (list, tuple)):
                    rval = []
                    for elem in l:
                        if isinstance(elem, (list, tuple)):
                            rval.extend(flatten(elem))
                        else:
                            rval.append(elem)
                    else:
                        return rval
            def do_check_on(var, nd, f):
                if (var.min() < 0):
                    raise NegativeVariableError()
            def neg_check(i, node, fn):
                inputs = fn.inputs
                for x in flatten(inputs):
                    do_check_on(x, node, fn)
                fn()
                outputs = fn.outputs
                for (j, x) in enumerate(flatten(outputs)):
                    do_check_on(x, node, fn)
            wrap_linker = theano.gof.WrapLinkerMany([theano.gof.OpWiseCLinker()], [neg_check])
            super(NegDetectionMode, self).__init__(wrap_linker, optimizer='fast_run')
    return NegDetectionMode()