def step_size_to_bound(x, s, lb, ub):
 non_zero = np.nonzero(s)
 s_non_zero = s[non_zero]
 steps = np.empty_like(x)
 steps.fill(np.inf)
 with np.errstate(over='ignore'):
  steps[non_zero] = np.maximum(((lb - x)[non_zero] / s_non_zero), ((ub - x)[non_zero] / s_non_zero))
 min_step = np.min(steps)
 return (min_step, (np.equal(steps, min_step) * np.sign(s).astype(int)))

def step_size_to_bound ( x , s , lb , ub ) : non_zero = np . nonzero ( s ) s_non_zero = s [ non_zero ] steps = np . empty_like ( x ) steps . fill ( np . inf ) with np . errstate ( over = 'ignore' ) : steps [ non_zero ] = np . maximum ( ( ( lb - x ) [ non_zero ] / s_non_zero ) , ( ( ub - x ) [ non_zero ] / s_non_zero ) ) min_step = np . min ( steps ) return ( min_step , ( np . equal ( steps , min_step ) * np . sign ( s ) . astype ( int ) ) )
compute a min_step size required to reach a bound .