#NEWLINE# @ lower ( 'np.random.geometric' , types . Float ) #NEWLINE# def geometric_impl( context , builder , sig , args ) : #NEWLINE# #INDENT# _random = np . random . random #NEWLINE# intty = sig . return_type #NEWLINE# def geometric_impl( p ) : #NEWLINE# #INDENT# if ( ( p <= 0.0 ) or ( p > 1.0 ) ) : #NEWLINE# #INDENT# raise ValueError ( 'geometric(): p outside of (0, 1]' ) #NEWLINE# #UNINDENT# q = ( 1.0 - p ) #NEWLINE# if ( p >= 0.3333333333333333 ) : #NEWLINE# #INDENT# X = intty ( 1 ) #NEWLINE# sum = prod = p #NEWLINE# U = _random ( ) #NEWLINE# while ( U > sum ) : #NEWLINE# #INDENT# prod *= q #NEWLINE# sum += prod #NEWLINE# X += 1 #NEWLINE# #UNINDENT# return X #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return math . ceil ( ( math . log ( ( 1.0 - _random ( ) ) ) / math . log ( q ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# res = context . compile_internal ( args , geometric_impl , sig , args ) #NEWLINE# return impl_ret_untracked ( context , builder , sig . return_type , res )