#NEWLINE# def as_theano_expression( input ) : #NEWLINE# #INDENT# 'Wrap as Theano expression.\n\n    Wraps the given input as a Theano constant if it is not\n    a valid Theano expression already. Useful to transparently\n    handle numpy arrays and Python scalars, for example.\n\n    Parameters\n    ----------\n    input : number, numpy array or Theano expression\n        Expression to be converted to a Theano constant.\n\n    Returns\n    -------\n    Theano symbolic constant\n        Theano constant version of `input`.\n    ' #NEWLINE# if isinstance ( input , theano . gof . Variable ) : #NEWLINE# #INDENT# return input #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# return theano . tensor . constant ( input ) #NEWLINE# #UNINDENT# except Exception as e : #NEWLINE# #INDENT# raise TypeError ( ( 'Input of type %s is not a Theano expression and cannot be wrapped as a Theano constant (original exception: %s)' % ( type ( input ) , e ) ) )