#NEWLINE# def CL_scaling_vector( x , g , lb , ub ) : #NEWLINE# #INDENT# 'Compute Coleman-Li scaling vector and its derivatives.\n    \n    Components of a vector v are defined as follows:\n    ::\n               | ub[i] - x[i], if g[i] < 0 and ub[i] < np.inf\n        v[i] = | x[i] - lb[i], if g[i] > 0 and lb[i] > -np.inf\n               | 1,           otherwise\n    \n    According to this definition v[i] >= 0 for all i. It differs from the\n    definition in paper [1]_ (eq. (2.2)), where the absolute value of v is\n    used. Both definitions are equivalent down the line.\n    Derivatives of v with respect to x take value 1, -1 or 0 depending on a\n    case.\n    \n    Returns\n    -------\n    v : ndarray with shape of x\n        Scaling vector.\n    dv : ndarray with shape of x\n        Derivatives of v[i] with respect to x[i], diagonal elements of v\'s\n        Jacobian.\n    \n    References\n    ----------\n    .. [1] M.A. Branch, T.F. Coleman, and Y. Li, "A Subspace, Interior,\n           and Conjugate Gradient Method for Large-Scale Bound-Constrained\n           Minimization Problems," SIAM Journal on Scientific Computing,\n           Vol. 21, Number 1, pp 1-23, 1999.\n    ' #NEWLINE# v = np . ones_like ( x ) #NEWLINE# dv = np . zeros_like ( x ) #NEWLINE# mask = ( ( g < 0 ) & np . isfinite ( ub ) ) #NEWLINE# v [ mask ] = ( ub [ mask ] - x [ mask ] ) #NEWLINE# dv [ mask ] = ( - 1 ) #NEWLINE# mask = ( ( g > 0 ) & np . isfinite ( lb ) ) #NEWLINE# v [ mask ] = ( x [ mask ] - lb [ mask ] ) #NEWLINE# dv [ mask ] = 1 #NEWLINE# return ( v , dv )