#NEWLINE# def step_size_to_bound( x , s , lb , ub ) : #NEWLINE# #INDENT# 'Compute a min_step size required to reach a bound.\n    \n    The function computes a positive scalar t, such that x + s * t is on\n    the bound.\n    \n    Returns\n    -------\n    step : float\n        Computed step. Non-negative value.\n    hits : ndarray of int with shape of x\n        Each element indicates whether a corresponding variable reaches the\n        bound:\n             \n             *  0 - the bound was not hit.\n             * -1 - the lower bound was hit.\n             *  1 - the upper bound was hit.\n    ' #NEWLINE# non_zero = np . nonzero ( s ) #NEWLINE# s_non_zero = s [ non_zero ] #NEWLINE# steps = np . empty_like ( x ) #NEWLINE# steps . fill ( np . inf ) #NEWLINE# with np . errstate ( over = 'ignore' ) : #NEWLINE# #INDENT# steps [ non_zero ] = np . maximum ( ( ( lb - s ) [ non_zero ] / s_non_zero ) , ( ( ub - x ) [ non_zero ] / s_non_zero ) ) #NEWLINE# #UNINDENT# min_step = np . min ( steps ) #NEWLINE# return ( min_step , ( np . equal ( steps , min_step ) * np . sign ( s ) . astype ( int ) ) )