#NEWLINE# def hard_sigmoid( x ) : #NEWLINE# #INDENT# '\n    An approximation of sigmoid.\n\n    More approximate and faster than ultra_fast_sigmoid.\n\n    Approx in 3 parts: 0, scaled linear, 1.\n\n    Removing the slope and shift does not make it faster.\n\n    ' #NEWLINE# out_dtype = scalar . upgrade_to_float ( scalar . Scalar ( dtype = x . dtype ) ) [ 0 ] . dtype #NEWLINE# slope = tensor . constant ( 0.2 , dtype = out_dtype ) #NEWLINE# shift = tensor . constant ( 0.5 , dtype = out_dtype ) #NEWLINE# x = ( ( x * slope ) + shift ) #NEWLINE# x = tensor . clip ( x , 0 , 1 ) #NEWLINE# return x