Ë
    âQ(hZa  ã                   óÆ   — d dl Zd dlmZ ddlmZmZ ddlm	Z	 d dl
mZ d dlmZ d dlmZ dZdd	„Zdd
„Zdd„Z G d„ d«      Z G d„ d«      Z G d„ d«      Z G d„ de«      Zy)é    Né   )Úapprox_derivativeÚgroup_columns)ÚHessianUpdateStrategy)ÚLinearOperator)Úarray_namespace)Úarray_api_extra)z2-pointz3-pointÚcsc                 ó$   ‡ ‡‡— dgŠˆˆ ˆfd„}|‰fS )Nr   c                 ó  •— ‰dxx   dz  cc<    ‰t        j                  | «      g‰¢­Ž }t        j                  |«      s&	 t        j                  |«      j	                  «       }|S |S # t
        t        f$ r}t        d«      |‚d }~ww xY w)Nr   r   z@The user-provided objective function must return a scalar value.)ÚnpÚcopyÚisscalarÚasarrayÚitemÚ	TypeErrorÚ
ValueError)ÚxÚfxÚeÚargsÚfunÚncallss      €€€úf/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/scipy/optimize/_differentiable_functions.pyÚwrappedz_wrapper_fun.<locals>.wrapped   sˆ   ø€ Øˆq‹	�Q‰‹	ñ ”—‘˜“Ð#˜dÒ#ˆä�{‰{˜2ŒðÜ—Z‘Z “^×(Ñ(Ó*�ð ˆ	ˆrˆ	øô œzÐ*ò Ü ð2óð ðûðús   Á#A( Á(BÁ7BÂB© )r   r   r   r   s   `` @r   Ú_wrapper_funr      s   ú€ ØˆS€Föð  �Fˆ?Ðó    c                 óh   ‡ ‡‡‡‡— dgŠt        ‰ «      rˆˆ ˆfd„}|‰fS ‰ t        v rdˆˆˆfd„	}|‰fS y )Nr   c                 ó|   •— ‰dxx   dz  cc<   t        j                   ‰t        j                  | «      g‰¢­Ž «      S ©Nr   r   )r   Ú
atleast_1dr   )r   Úkwdsr   Úgradr   s     €€€r   r   z_wrapper_grad.<locals>.wrapped'   s1   ø€ à�1‹I˜‰N‹IÜ—=‘=¡¤b§g¡g¨a£jÐ!8°4Ò!8Ó9Ð9r   c                 ó<   •— ‰dxx   dz  cc<   t        ‰| fd|i‰¤ŽS )Nr   r   Úf0©r   )r   r&   Úfinite_diff_optionsr   r   s     €€€r   Úwrapped1z_wrapper_grad.<locals>.wrapped1.   s2   ø€ Ø�1‹I˜‰N‹IÜ$Ø�QñØðØ!4ñð r   ©N)ÚcallableÚ
FD_METHODS)r$   r   r   r(   r   r)   r   s   ````  @r   Ú_wrapper_gradr-   #   sA   ü€ ØˆS€Fä�„~ö	:ð ˜ˆÐà	”Ñ	÷	ð ˜ÐÐð 
r   c                 óŒ  ‡ ‡‡‡‡— t        ‰ «      r� ‰ t        j                  |«      g‰¢­Ž }dgŠt        j                  |«      rˆˆ ˆfd„}t        j
                  |«      }nGt        |t        «      rˆˆ ˆfd„}n/ˆˆ ˆfd„}t        j                  t        j                  |«      «      }|‰|fS ‰ t        v rdgŠdˆˆfd„	}|‰d fS y )Nr   c                 ó|   •— ‰dxx   dz  cc<   t        j                   ‰t        j                  | «      g‰¢­Ž «      S r!   )ÚspsÚ
csr_matrixr   r   ©r   r#   r   Úhessr   s     €€€r   r   z_wrapper_hess.<locals>.wrapped=   s1   ø€ Ø�q“	˜Q‘“	Ü—~‘~¡d¬2¯7©7°1«:Ð&=¸Ò&=Ó>Ð>r   c                 óV   •— ‰dxx   dz  cc<    ‰t        j                  | «      g‰¢­Ž S r!   )r   r   r2   s     €€€r   r   z_wrapper_hess.<locals>.wrappedD   s(   ø€ Ø�q“	˜Q‘“	ÙœBŸG™G A›JÐ.¨Ò.Ð.r   c           	      ó¢   •— ‰dxx   dz  cc<   t        j                  t        j                   ‰t        j                  | «      g‰¢­Ž «      «      S r!   )r   Ú
atleast_2dr   r   r2   s     €€€r   r   z_wrapper_hess.<locals>.wrappedI   s:   ø€ Ø�q“	˜Q‘“	Ü—}‘}¤R§Z¡Z±´R·W±W¸Q³ZÐ0GÀ$Ò0GÓ%HÓIÐIr   r   c                 ó"   •— t        ‰| fd|i‰¤ŽS ©Nr&   r'   )r   r&   r(   r$   s     €€r   r)   z_wrapper_hess.<locals>.wrapped1S   s%   ø€ Ü$Ø�añØðØ"5ñð r   r*   )r+   r   r   r0   Úissparser1   Ú
isinstancer   r6   r   r,   )	r3   r$   Úx0r   r(   ÚHr   r)   r   s	   `` ``   @r   Ú_wrapper_hessr=   7   sª   ü€ Ü�„~Ù”—‘˜“Ð$˜tÒ$ˆØ�ˆä�<‰<˜Œ?ö?ô —‘˜qÓ!‰Aä˜œ>Ô*÷/ö
Jô —‘œbŸj™j¨›mÓ,ˆAà˜ Ð!Ð!Ø	”Ñ	Ø�ˆö	ð
 ˜ Ð%Ð%ð 
r   c                   óz   — e Zd ZdZ	 dd„Zed„ «       Zed„ «       Zed„ «       Zd„ Z	d„ Z
d	„ Zd
„ Zd„ Zd„ Zd„ Zd„ Zy)ÚScalarFunctiona©  Scalar function and its derivatives.

    This class defines a scalar function F: R^n->R and methods for
    computing or approximating its first and second derivatives.

    Parameters
    ----------
    fun : callable
        evaluates the scalar function. Must be of the form ``fun(x, *args)``,
        where ``x`` is the argument in the form of a 1-D array and ``args`` is
        a tuple of any additional fixed parameters needed to completely specify
        the function. Should return a scalar.
    x0 : array-like
        Provides an initial set of variables for evaluating fun. Array of real
        elements of size (n,), where 'n' is the number of independent
        variables.
    args : tuple, optional
        Any additional fixed parameters needed to completely specify the scalar
        function.
    grad : {callable, '2-point', '3-point', 'cs'}
        Method for computing the gradient vector.
        If it is a callable, it should be a function that returns the gradient
        vector:

            ``grad(x, *args) -> array_like, shape (n,)``

        where ``x`` is an array with shape (n,) and ``args`` is a tuple with
        the fixed parameters.
        Alternatively, the keywords  {'2-point', '3-point', 'cs'} can be used
        to select a finite difference scheme for numerical estimation of the
        gradient with a relative step size. These finite difference schemes
        obey any specified `bounds`.
    hess : {callable, '2-point', '3-point', 'cs', HessianUpdateStrategy}
        Method for computing the Hessian matrix. If it is callable, it should
        return the  Hessian matrix:

            ``hess(x, *args) -> {LinearOperator, spmatrix, array}, (n, n)``

        where x is a (n,) ndarray and `args` is a tuple with the fixed
        parameters. Alternatively, the keywords {'2-point', '3-point', 'cs'}
        select a finite difference scheme for numerical estimation. Or, objects
        implementing `HessianUpdateStrategy` interface can be used to
        approximate the Hessian.
        Whenever the gradient is estimated via finite-differences, the Hessian
        cannot be estimated with options {'2-point', '3-point', 'cs'} and needs
        to be estimated using one of the quasi-Newton strategies.
    finite_diff_rel_step : None or array_like
        Relative step size to use. The absolute step size is computed as
        ``h = finite_diff_rel_step * sign(x0) * max(1, abs(x0))``, possibly
        adjusted to fit into the bounds. For ``method='3-point'`` the sign
        of `h` is ignored. If None then finite_diff_rel_step is selected
        automatically,
    finite_diff_bounds : tuple of array_like
        Lower and upper bounds on independent variables. Defaults to no bounds,
        (-np.inf, np.inf). Each bound must match the size of `x0` or be a
        scalar, in the latter case the bound will be the same for all
        variables. Use it to limit the range of function evaluation.
    epsilon : None or array_like, optional
        Absolute step size to use, possibly adjusted to fit into the bounds.
        For ``method='3-point'`` the sign of `epsilon` is ignored. By default
        relative steps are used, only if ``epsilon is not None`` are absolute
        steps used.

    Notes
    -----
    This class implements a memoization logic. There are methods `fun`,
    `grad`, hess` and corresponding attributes `f`, `g` and `H`. The following
    things should be considered:

        1. Use only public methods `fun`, `grad` and `hess`.
        2. After one of the methods is called, the corresponding attribute
           will be set. However, a subsequent call with a different argument
           of *any* of the methods may overwrite the attribute.
    Nc	                 ó  — t        |«      s|t        vrt        dt        › d�«      ‚t        |«      s+|t        v s#t        |t        «      st        dt        › d�«      ‚|t        v r|t        v rt        d«      ‚t        |«      x| _        }	t        j                  |	j                  |«      d|	¬«      }
|	j                  }|	j                  |
j                  d«      r|
j                  }t        ||¬«      \  | _        | _        || _        || _        || _        || _        |	j)                  |
|«      | _        || _        | j*                  j.                  | _        d	| _        d	| _        d	| _        d | _        t:        j<                  | _        i }|t        v r||d
<   ||d<   ||d<   ||d<   |t        v r||d
<   ||d<   ||d<   d|d<   | jA                  «        tC        || j                  ||¬«      \  | _"        | _#        | jI                  «        t        |«      r)tK        |||¬«      \  | _&        | _'        | _(        d| _        y |t        v rptK        || jD                  ||¬«      \  | _&        | _'        | _(        | jI                  «        | jM                  | j*                  | jR                  ¬«      | _(        d| _        y t        |t        «      rK|| _(        | jP                  jU                  | j0                  d«       d| _        d | _+        d | _,        dg| _'        y y )Nz)`grad` must be either callable or one of ú.z@`hess` must be either callable, HessianUpdateStrategy or one of z‹Whenever the gradient is estimated via finite-differences, we require the Hessian to be estimated using one of the quasi-Newton strategies.r   ©ÚndimÚxpúreal floating)r   FÚmethodÚrel_stepÚabs_stepÚboundsTÚas_linear_operator)r   r   r(   )r;   r   )r$   r;   r(   ©r&   r3   r   )-r+   r,   r   r:   r   r   rD   ÚxpxÚ
atleast_ndr   Úfloat64ÚisdtypeÚdtyper   Ú_wrapped_funÚ_nfevÚ	_orig_funÚ
_orig_gradÚ
_orig_hessÚ_argsÚastyper   Úx_dtypeÚsizeÚnÚ	f_updatedÚ	g_updatedÚ	H_updatedÚ	_lowest_xr   ÚinfÚ	_lowest_fÚ_update_funr-   Ú_wrapped_gradÚ_ngevÚ_update_gradr=   Ú_wrapped_hessÚ_nhevr<   ÚgÚ
initializeÚx_prevÚg_prev)Úselfr   r;   r   r$   r3   Úfinite_diff_rel_stepÚfinite_diff_boundsÚepsilonrD   Ú_xÚ_dtyper(   s                r   Ú__init__zScalarFunction.__init__¦   sò  € ä˜Œ~ $¬jÑ"8ÜØ;¼J¸<ÀqÐIóð ô ˜” $¬*Ñ"4Ü˜dÔ$9Ô:ÜðÜ(˜\¨ð,óð ð
 ”:Ñ $¬*Ñ"4Üð 8ó 9ð 9ô
 ' rÓ*Ð*ˆŒ�"Ü�^‰^˜BŸJ™J r›N°°rÔ:ˆØ—‘ˆØ�:‰:�b—h‘h Ô0Ø—X‘XˆFô )5°S¸tÔ(DÑ%ˆÔ˜4œ:ØˆŒØˆŒØˆŒØˆŒ
ð —‘˜2˜vÓ&ˆŒØˆŒØ—‘—‘ˆŒØˆŒØˆŒØˆŒàˆŒÜŸ™ˆŒà ÐØ”:ÑØ,0Ð Ñ)Ø.BÐ 
Ñ+Ø.5Ð 
Ñ+Ø,>Ð Ñ)Ø”:ÑØ,0Ð Ñ)Ø.BÐ 
Ñ+Ø.5Ð 
Ñ+Ø8<ÐÐ 4Ñ5ð 	×ÑÔô *7ØØ×!Ñ!ØØ 3ô	*
Ñ&ˆÔ˜DœJð 	×ÑÔô �DŒ>Ü5BØ˜ $ô6Ñ2ˆDÔ ¤
¨D¬Fð "ˆD�NØ”ZÑÜ5BØØ×'Ñ'ØØ$7ô	6Ñ2ˆDÔ ¤
¨D¬Fð ×ÑÔØ×'Ñ'¨¯©°4·6±6Ð'Ó:ˆDŒFØ!ˆD�NÜ˜Ô3Ô4ØˆDŒFØ�F‰F×Ñ˜dŸf™f fÔ-Ø!ˆDŒNØˆDŒKØˆDŒKØ˜ˆD�Jð 5r   c                 ó    — | j                   d   S ©Nr   )rR   ©rk   s    r   ÚnfevzScalarFunction.nfev  ó   € à�z‰z˜!‰}Ðr   c                 ó    — | j                   d   S rs   )rc   rt   s    r   ÚngevzScalarFunction.ngev  rv   r   c                 ó    — | j                   d   S rs   )rf   rt   s    r   ÚnhevzScalarFunction.nhev
  rv   r   c                 óª  — t        | j                  t        «      r¾| j                  «        | j                  | _        | j                  | _        t        j                  | j                  j                  |«      d| j                  ¬«      }| j                  j                  || j                  «      | _        d| _        d| _        d| _        | j#                  «        y t        j                  | j                  j                  |«      d| j                  ¬«      }| j                  j                  || j                  «      | _        d| _        d| _        d| _        y ©Nr   rB   F)r:   rU   r   rd   r   ri   rg   rj   rL   rM   rD   r   rW   rX   r[   r\   r]   Ú_update_hess©rk   r   ro   s      r   Ú	_update_xzScalarFunction._update_x  sç   € Ü�d—o‘oÔ'<Ô=Ø×ÑÔØŸ&™&ˆDŒKØŸ&™&ˆDŒKô —‘ §¡§¡°Ó 2¸¸t¿w¹wÔGˆBØ—W‘W—^‘^ B¨¯©Ó5ˆDŒFØ"ˆDŒNØ"ˆDŒNØ"ˆDŒNØ×ÑÕô —‘ §¡§¡°Ó 2¸¸t¿w¹wÔGˆBØ—W‘W—^‘^ B¨¯©Ó5ˆDŒFØ"ˆDŒNØ"ˆDŒNØ"ˆD�Nr   c                 ó¾   — | j                   sQ| j                  | j                  «      }|| j                  k  r| j                  | _        || _        || _        d| _         y y ©NT)r[   rQ   r   r`   r^   Úf)rk   r   s     r   ra   zScalarFunction._update_fun%  sN   € Ø�~Š~Ø×"Ñ" 4§6¡6Ó*ˆBØ�D—N‘NÒ"Ø!%§¡�”Ø!#�”àˆDŒFØ!ˆD�Nð r   c                 óÈ   — | j                   sV| j                  t        v r| j                  «        | j	                  | j
                  | j                  ¬«      | _        d| _         y y ©NrK   T)r\   rT   r,   ra   rb   r   r‚   rg   rt   s    r   rd   zScalarFunction._update_grad/  sL   € Ø�~Š~Ø�‰¤*Ñ,Ø× Ñ Ô"Ø×'Ñ'¨¯©°4·6±6Ð'Ó:ˆDŒFØ!ˆD�Nð	 r   c                 óô  — | j                   sì| j                  t        v r=| j                  «        | j	                  | j
                  | j                  ¬«      | _        n•t        | j                  t        «      r[| j                  «        | j                  j                  | j
                  | j                  z
  | j                  | j                  z
  «       n | j	                  | j
                  «      | _        d| _         y y r„   )r]   rU   r,   rd   re   r   rg   r<   r:   r   Úupdateri   rj   rt   s    r   r}   zScalarFunction._update_hess6  s©   € Ø�~Š~Ø�‰¤*Ñ,Ø×!Ñ!Ô#Ø×+Ñ+¨D¯F©F°t·v±vÐ+Ó>�•Ü˜DŸO™OÔ-BÔCØ×!Ñ!Ô#Ø—‘—‘˜dŸf™f t§{¡{Ñ2°D·F±F¸T¿[¹[Ñ4HÕIà×+Ñ+¨D¯F©FÓ3�”à!ˆD�Nð r   c                 óœ   — t        j                  || j                  «      s| j                  |«       | j	                  «        | j
                  S r*   )r   Úarray_equalr   r   ra   r‚   ©rk   r   s     r   r   zScalarFunction.funC  s5   € Ü�~‰~˜a §¡Ô(Ø�N‰N˜1ÔØ×ÑÔØ�v‰vˆr   c                 óœ   — t        j                  || j                  «      s| j                  |«       | j	                  «        | j
                  S r*   )r   rˆ   r   r   rd   rg   r‰   s     r   r$   zScalarFunction.gradI  ó5   € Ü�~‰~˜a §¡Ô(Ø�N‰N˜1ÔØ×ÑÔØ�v‰vˆr   c                 óœ   — t        j                  || j                  «      s| j                  |«       | j	                  «        | j
                  S r*   )r   rˆ   r   r   r}   r<   r‰   s     r   r3   zScalarFunction.hessO  r‹   r   c                 óÔ   — t        j                  || j                  «      s| j                  |«       | j	                  «        | j                  «        | j                  | j                  fS r*   )r   rˆ   r   r   ra   rd   r‚   rg   r‰   s     r   Úfun_and_gradzScalarFunction.fun_and_gradU  sJ   € Ü�~‰~˜a §¡Ô(Ø�N‰N˜1ÔØ×ÑÔØ×ÑÔØ�v‰v�t—v‘vˆ~Ðr   r*   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__rq   Úpropertyru   rx   rz   r   ra   rd   r}   r   r$   r3   rŽ   r   r   r   r?   r?   [   sy   „ ñIðV .2óZðx ñó ðð ñó ðð ñó ðò#ò."ò"ò"òòòór   r?   c                   óF   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z	d„ Z
d	„ Zd
„ Zy)ÚVectorFunctiona‘  Vector function and its derivatives.

    This class defines a vector function F: R^n->R^m and methods for
    computing or approximating its first and second derivatives.

    Notes
    -----
    This class implements a memoization logic. There are methods `fun`,
    `jac`, hess` and corresponding attributes `f`, `J` and `H`. The following
    things should be considered:

        1. Use only public methods `fun`, `jac` and `hess`.
        2. After one of the methods is called, the corresponding attribute
           will be set. However, a subsequent call with a different argument
           of *any* of the methods may overwrite the attribute.
    c	                 óB  ‡ ‡‡‡‡‡‡‡‡— t        ‰«      s‰t        vrt        dt        › d�«      ‚t        ‰«      s+‰t        v s#t        ‰t        «      st        dt        › d�«      ‚‰t        v r‰t        v rt        d«      ‚t        |«      x‰ _        }	t        j                  |	j                  |«      d|	¬«      }
|	j                  }|	j                  |
j                  d«      r|
j                  }|	j                  |
|«      ‰ _        |‰ _        ‰ j                  j                   ‰ _        d‰ _        d‰ _        d‰ _        d	‰ _        d	‰ _        d	‰ _        i Š‰t        v rG‰‰d
<   |‰d<   |�t1        |«      }||f‰d<   |‰d<   t3        j4                  ‰ j                  «      ‰ _        ‰t        v r3‰‰d
<   |‰d<   d‰d<   t3        j4                  ‰ j                  «      ‰ _        ‰t        v r‰t        v rt        d«      ‚ˆˆ fd„Šˆˆ fd„}|‰ _         |«        t3        j:                  ‰ j<                  «      ‰ _        ‰ j>                  j                   ‰ _         t        ‰«      �r ‰‰ j                  «      ‰ _!        d‰ _        ‰ xj&                  dz  c_        |s!|€QtE        jF                  ‰ jB                  «      r2ˆˆ fd„ŠtE        jH                  ‰ jB                  «      ‰ _!        d‰ _%        n}tE        jF                  ‰ jB                  «      r-ˆˆ fd„Š‰ jB                  jM                  «       ‰ _!        d	‰ _%        n1ˆˆ fd„Št3        jN                  ‰ jB                  «      ‰ _!        d	‰ _%        ˆˆ fd„}�n‰t        v �rtQ        ‰‰ j                  fd‰ j<                  i‰¤Ž‰ _!        d‰ _        |s!|€RtE        jF                  ‰ jB                  «      r3ˆˆˆ fd„}tE        jH                  ‰ jB                  «      ‰ _!        d‰ _%        ntE        jF                  ‰ jB                  «      r.ˆˆˆ fd„}‰ jB                  jM                  «       ‰ _!        d	‰ _%        n2ˆˆˆ fd„}t3        jN                  ‰ jB                  «      ‰ _!        d	‰ _%        ‰ _)        t        ‰«      rí ‰‰ j                  ‰ j>                  «      ‰ _*        d‰ _        ‰ xj(                  dz  c_        tE        jF                  ‰ jT                  «      r+ˆˆ fd„ŠtE        jH                  ‰ jT                  «      ‰ _*        n^t        ‰ jT                  tV        «      rˆˆ fd„Šn=ˆˆ fd„Št3        jN                  t3        j                  ‰ jT                  «      «      ‰ _*        ˆˆ fd„}nz‰t        v rˆfd„Šˆˆˆ fd„} |«        d‰ _        nWt        ‰t        «      rG‰‰ _*        ‰ jT                  jY                  ‰ j"                  d «       d‰ _        d ‰ _-        d ‰ _.        ˆ fd!„}‰ _/        t        ‰t        «      rˆ fd"„}|‰ _0        y ˆ fd#„}|‰ _0        y )$Nz(`jac` must be either callable or one of rA   z?`hess` must be either callable,HessianUpdateStrategy or one of z‹Whenever the Jacobian is estimated via finite-differences, we require the Hessian to be estimated using one of the quasi-Newton strategies.r   rB   rE   r   FrF   rG   ÚsparsityrI   TrJ   c                 ód   •— ‰xj                   dz  c_         t        j                   ‰| «      «      S ©Nr   )ru   r   r"   )r   r   rk   s    €€r   Úfun_wrappedz,VectorFunction.__init__.<locals>.fun_wrapped§  s#   ø€ Ø�IŠI˜‰N�IÜ—=‘=¡ Q£Ó(Ð(r   c                  ó4   •—  ‰ ‰j                   «      ‰_        y r*   )r   r‚   )rš   rk   s   €€r   Ú
update_funz+VectorFunction.__init__.<locals>.update_fun«  s   ø€ Ù  §¡Ó(ˆD�Fr   c                 ód   •— ‰xj                   dz  c_         t        j                   ‰| «      «      S r™   )Únjevr0   r1   ©r   Újacrk   s    €€r   Újac_wrappedz,VectorFunction.__init__.<locals>.jac_wrapped¼  s#   ø€ Ø—I’I ‘N•IÜŸ>™>©#¨a«&Ó1Ð1r   c                 óZ   •— ‰xj                   dz  c_          ‰| «      j                  «       S r™   )rž   ÚtoarrayrŸ   s    €€r   r¡   z,VectorFunction.__init__.<locals>.jac_wrappedÃ  s!   ø€ Ø—I’I ‘N•IÙ˜q›6Ÿ>™>Ó+Ð+r   c                 ód   •— ‰xj                   dz  c_         t        j                   ‰| «      «      S r™   )rž   r   r6   rŸ   s    €€r   r¡   z,VectorFunction.__init__.<locals>.jac_wrappedÊ  s#   ø€ Ø—I’I ‘N•IÜŸ=™=©¨Q«Ó0Ð0r   c                  ó4   •—  ‰ ‰j                   «      ‰_        y r*   )r   ÚJ)r¡   rk   s   €€r   Ú
update_jacz+VectorFunction.__init__.<locals>.update_jacÐ  s   ø€ Ù$ T§V¡VÓ,�•r   r&   c                  óœ   •— ‰j                  «        t        j                  t        ‰‰j                  fd‰j
                  i‰ ¤Ž«      ‰_        y r8   )ra   r0   r1   r   r   r‚   r¦   ©r(   rš   rk   s   €€€r   r§   z+VectorFunction.__init__.<locals>.update_jacÚ  sF   ø€ Ø×$Ñ$Ô&Ü Ÿ^™^Ü)¨+°t·v±vñ AÀ$Ç&Á&ð AØ,?ñAóB�D•Fr   c                  ó’   •— ‰j                  «        t        ‰‰j                  fd‰j                  i‰ ¤Žj	                  «       ‰_        y r8   )ra   r   r   r‚   r£   r¦   r©   s   €€€r   r§   z+VectorFunction.__init__.<locals>.update_jacã  sC   ø€ Ø×$Ñ$Ô&Ü.¨{¸D¿F¹Fñ FÀtÇvÁvð FØ1DñFßFMÁgÃið •Fr   c                  óœ   •— ‰j                  «        t        j                  t        ‰‰j                  fd‰j
                  i‰ ¤Ž«      ‰_        y r8   )ra   r   r6   r   r   r‚   r¦   r©   s   €€€r   r§   z+VectorFunction.__init__.<locals>.update_jacë  sF   ø€ Ø×$Ñ$Ô&ÜŸ]™]Ü)¨+°t·v±vñ AÀ$Ç&Á&ð AØ,?ñAóB�D•Fr   c                 óf   •— ‰xj                   dz  c_         t        j                   ‰| |«      «      S r™   )rz   r0   r1   ©r   Úvr3   rk   s     €€r   Úhess_wrappedz-VectorFunction.__init__.<locals>.hess_wrappedü  s%   ø€ Ø—I’I ‘N•IÜŸ>™>©$¨q°!«*Ó5Ð5r   c                 ó@   •— ‰xj                   dz  c_          ‰| |«      S r™   )rz   r­   s     €€r   r¯   z-VectorFunction.__init__.<locals>.hess_wrapped  s   ø€ Ø—I’I ‘N•IÙ  1›:Ð%r   c                 óŒ   •— ‰xj                   dz  c_         t        j                  t        j                   ‰| |«      «      «      S r™   )rz   r   r6   r   r­   s     €€r   r¯   z-VectorFunction.__init__.<locals>.hess_wrapped  s.   ø€ Ø—I’I ‘N•IÜŸ=™=¬¯©±D¸¸A³JÓ)?Ó@Ð@r   c                  óJ   •—  ‰ ‰j                   ‰j                  «      ‰_        y r*   )r   r®   r<   )r¯   rk   s   €€r   Úupdate_hessz,VectorFunction.__init__.<locals>.update_hess  s   ø€ Ù% d§f¡f¨d¯f©fÓ5�•r   c                 óF   •—  ‰| «      j                   j                  |«      S r*   )ÚTÚdot)r   r®   r¡   s     €r   Ú	jac_dot_vz*VectorFunction.__init__.<locals>.jac_dot_v  s   ø€ Ù" 1“~×'Ñ'×+Ñ+¨AÓ.Ð.r   c                  óÔ   •— ‰j                  «        t        ‰‰j                  f‰j                  j                  j                  ‰j                  «      ‰j                  fdœ‰ ¤Ž‰_        y )N)r&   r   )Ú_update_jacr   r   r¦   rµ   r¶   r®   r<   )r(   r·   rk   s   €€€r   r³   z,VectorFunction.__init__.<locals>.update_hess  sW   ø€ Ø× Ñ Ô"Ü*¨9°d·f±fð BØ.2¯f©f¯h©h¯l©l¸4¿6¹6Ó.BØ15·±°	ñBð .AñB�•r   r3   c                  ó‚  •— ‰j                  «        ‰j                  �¢‰j                  �•‰j                  ‰j                  z
  } ‰j                  j
                  j                  ‰j                  «      ‰j                  j
                  j                  ‰j                  «      z
  }‰j                  j                  | |«       y y y r*   )
r¹   ri   ÚJ_prevr   r¦   rµ   r¶   r®   r<   r†   )Údelta_xÚdelta_grk   s     €r   r³   z,VectorFunction.__init__.<locals>.update_hess!  s‡   ø€ Ø× Ñ Ô"ð —;‘;Ð*¨t¯{©{Ð/FØ"Ÿf™f t§{¡{Ñ2�GØ"Ÿf™fŸh™hŸl™l¨4¯6©6Ó2°T·[±[·]±]×5FÑ5FÀtÇvÁvÓ5NÑN�GØ—F‘F—M‘M '¨7Õ3ð 0GÐ*r   c                 ó€  •— ‰j                  «        ‰j                  ‰_        ‰j                  ‰_        t        j                  ‰j                  j                  | «      d‰j                  ¬«      }‰j                  j                  |‰j                  «      ‰_        d‰_        d‰_        d‰_        ‰j                  «        y r|   )r¹   r   ri   r¦   r»   rL   rM   rD   r   rW   rX   r[   Ú	J_updatedr]   r}   ©r   ro   rk   s     €r   Úupdate_xz)VectorFunction.__init__.<locals>.update_x-  sƒ   ø€ Ø× Ñ Ô"Ø"Ÿf™f�”Ø"Ÿf™f�”Ü—^‘^ D§G¡G§O¡O°AÓ$6¸QÀ4Ç7Á7ÔK�ØŸ™Ÿ™¨¨D¯L©LÓ9�”Ø!&�”Ø!&�”Ø!&�”Ø×!Ñ!Õ#r   c                 óü   •— t        j                  ‰j                  j                  | «      d‰j                  ¬«      }‰j                  j	                  |‰j
                  «      ‰_        d‰_        d‰_        d‰_	        y r|   )
rL   rM   rD   r   rW   rX   r   r[   r¿   r]   rÀ   s     €r   rÁ   z)VectorFunction.__init__.<locals>.update_x8  sU   ø€ Ü—^‘^ D§G¡G§O¡O°AÓ$6¸QÀ4Ç7Á7ÔK�ØŸ™Ÿ™¨¨D¯L©LÓ9�”Ø!&�”Ø!&�”Ø!&�•r   )1r+   r,   r   r:   r   r   rD   rL   rM   r   rN   rO   rP   rW   r   rX   rY   rZ   ru   rž   rz   r[   r¿   r]   r   r   r   Úx_diffÚ_update_fun_implÚ
zeros_liker‚   r®   Úmr¦   r0   r9   r1   Úsparse_jacobianr£   r6   r   Ú_update_jac_implr<   r   rh   ri   r»   Ú_update_hess_implÚ_update_x_impl)rk   r   r;   r    r3   rl   Úfinite_diff_jac_sparsityrm   rÇ   rD   ro   rp   Úsparsity_groupsrœ   r§   r³   rÁ   r(   rš   r¯   r·   r¡   s   `` ``            @@@@@r   rq   zVectorFunction.__init__n  só  ÿø€ ô ˜Œ} ¬JÑ!6ÜÐGÌ
À|ÐSTÐUÓVÐVä˜” $¬*Ñ"4Ü˜dÔ$9Ô:Üð @Ü@J¸|È1ðNó Oð Oð ”*Ñ ¬Ñ!3Üð +ó ,ð ,ô
 ' rÓ*Ð*ˆŒ�"Ü�^‰^˜BŸJ™J r›N°°rÔ:ˆØ—‘ˆØ�:‰:�b—h‘h Ô0Ø—X‘XˆFð —‘˜2˜vÓ&ˆŒØˆŒà—‘—‘ˆŒØˆŒ	ØˆŒ	ØˆŒ	ØˆŒØˆŒØˆŒà ÐØ”*ÑØ,/Ð Ñ)Ø.BÐ 
Ñ+Ø'Ð3Ü"/Ð0HÓ"I�Ø3KØ3Bð3DÐ# JÑ/à,>Ð Ñ)ÜŸ'™' $§&¡&›/ˆDŒKØ”:ÑØ,0Ð Ñ)Ø.BÐ 
Ñ+Ø8<ÐÐ 4Ñ5ÜŸ'™' $§&¡&›/ˆDŒKØ”*Ñ ¬Ñ!3Üð +ó ,ð ,õ	)õ	)ð !+ˆÔÙŒä—‘˜tŸv™vÓ&ˆŒØ—‘—‘ˆŒô �C�=Ù˜Ÿ™“[ˆDŒFØ!ˆDŒNØ�IŠI˜‰N�IáØ#Ð+´·±¸T¿V¹VÔ0Dõ2ô Ÿ™¨¯©Ó/�”Ø'+�Õ$ä—‘˜dŸf™fÔ%õ,ð Ÿ™Ÿ™Ó)�”Ø',�Õ$õ1ô Ÿ™ t§v¡vÓ.�”Ø',�Ô$÷-ð ”JÒÜ& {°D·F±Fñ >¸t¿v¹vð >Ø)<ñ>ˆDŒFà!ˆDŒNáØ#Ð+´·±¸T¿V¹VÔ0DöBô
 Ÿ™¨¯©Ó/�”Ø'+�Õ$ä—‘˜dŸf™fÔ%öPð Ÿ™Ÿ™Ó)�”Ø',�Õ$öBô
 Ÿ™ t§v¡vÓ.�”Ø',�Ô$à *ˆÔô �DŒ>Ù˜$Ÿ&™& $§&¡&Ó)ˆDŒFØ!ˆDŒNØ�IŠI˜‰N�Iä�|‰|˜DŸF™FÔ#õ6ô Ÿ™¨¯©Ó/�•ä˜DŸF™F¤NÔ3ö&õ
Aô Ÿ™¤r§z¡z°$·&±&Ó'9Ó:�”ö6à”ZÑô/öBñ ŒMØ!ˆD�NÜ˜Ô3Ô4ØˆDŒFØ�F‰F×Ñ˜dŸf™f fÔ-Ø!ˆDŒNØˆDŒKØˆDŒKô4ð "-ˆÔä�dÔ1Ô2ô	$ð$ 'ˆÕô'ð 'ˆÕr   c                 ób   — t        j                  || j                  «      s|| _        d| _        y y )NF)r   rˆ   r®   r]   )rk   r®   s     r   Ú	_update_vzVectorFunction._update_vA  s'   € Ü�~‰~˜a §¡Ô(ØˆDŒFØ"ˆD�Nð )r   c                 óh   — t        j                  || j                  «      s| j                  |«       y y r*   )r   rˆ   r   rÊ   r‰   s     r   r   zVectorFunction._update_xF  s'   € Ü�~‰~˜a §¡Ô(Ø×Ñ Õ"ð )r   c                 óL   — | j                   s| j                  «        d| _         y y r�   )r[   rÄ   rt   s    r   ra   zVectorFunction._update_funJ  ó!   € Ø�~Š~Ø×!Ñ!Ô#Ø!ˆD�Nð r   c                 óL   — | j                   s| j                  «        d| _         y y r�   )r¿   rÈ   rt   s    r   r¹   zVectorFunction._update_jacO  rÑ   r   c                 óL   — | j                   s| j                  «        d| _         y y r�   )r]   rÉ   rt   s    r   r}   zVectorFunction._update_hessT  s!   € Ø�~Š~Ø×"Ñ"Ô$Ø!ˆD�Nð r   c                 ó\   — | j                  |«       | j                  «        | j                  S r*   )r   ra   r‚   r‰   s     r   r   zVectorFunction.funY  ó#   € Ø�‰�qÔØ×ÑÔØ�v‰vˆr   c                 ó\   — | j                  |«       | j                  «        | j                  S r*   )r   r¹   r¦   r‰   s     r   r    zVectorFunction.jac^  rÕ   r   c                 ó~   — | j                  |«       | j                  |«       | j                  «        | j                  S r*   )rÎ   r   r}   r<   ©rk   r   r®   s      r   r3   zVectorFunction.hessc  s/   € à�‰�qÔØ�‰�qÔØ×ÑÔØ�v‰vˆr   N)r�   r�   r‘   r’   rq   rÎ   r   ra   r¹   r}   r   r    r3   r   r   r   r•   r•   ]  s6   „ ñò Q'òf#ò
#ò"ò
"ò
"ò
ò
ó
r   r•   c                   ó.   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ Zy)ÚLinearVectorFunctionzüLinear vector function and its derivatives.

    Defines a linear function F = A x, where x is N-D vector and
    A is m-by-n matrix. The Jacobian is constant and equals to A. The Hessian
    is identically zero and it is returned as a csr matrix.
    c                 ó¸  — |s|€7t        j                  |«      r"t        j                  |«      | _        d| _        nft        j                  |«      r|j                  «       | _        d| _        n4t        j                  t        j                  |«      «      | _        d| _        | j                  j                  \  | _
        | _        t        |«      x| _        }t        j                  |j                  |«      d|¬«      }|j                   }|j#                  |j$                  d«      r|j$                  }|j'                  ||«      | _        || _        | j                  j-                  | j(                  «      | _        d| _        t        j2                  | j                  t4        ¬«      | _        t        j                  | j                  | j                  f«      | _        y )NTFr   rB   rE   )rP   )r0   r9   r1   r¦   rÇ   r£   r   r6   r   ÚshaperÆ   rZ   r   rD   rL   rM   rN   rO   rP   rW   r   rX   r¶   r‚   r[   ÚzerosÚfloatr®   r<   )rk   ÚAr;   rÇ   rD   ro   rp   s          r   rq   zLinearVectorFunction.__init__r  s?  € Ù˜oÐ5¼#¿,¹,Àq¼/Ü—^‘^ AÓ&ˆDŒFØ#'ˆDÕ Ü�\‰\˜!Œ_Ø—Y‘Y“[ˆDŒFØ#(ˆDÕ ô —]‘]¤2§:¡:¨a£=Ó1ˆDŒFØ#(ˆDÔ àŸ™Ÿ™‰ˆŒ�”ä& rÓ*Ð*ˆŒ�"Ü�^‰^˜BŸJ™J r›N°°rÔ:ˆØ—‘ˆØ�:‰:�b—h‘h Ô0Ø—X‘XˆFð —‘˜2˜vÓ&ˆŒØˆŒà—‘—‘˜DŸF™FÓ#ˆŒØˆŒä—‘˜$Ÿ&™&¬Ô.ˆŒÜ—‘ §¡¨¯©Ð 0Ó1ˆ�r   c                 ó   — t        j                  || j                  «      snt        j                  | j
                  j                  |«      d| j
                  ¬«      }| j
                  j                  || j                  «      | _        d| _	        y y r|   )
r   rˆ   r   rL   rM   rD   r   rW   rX   r[   r~   s      r   r   zLinearVectorFunction._update_x�  s]   € Ü�~‰~˜a §¡Ô(Ü—‘ §¡§¡°Ó 2¸¸t¿w¹wÔGˆBØ—W‘W—^‘^ B¨¯©Ó5ˆDŒFØ"ˆD�Nð )r   c                 ó¢   — | j                  |«       | j                  s'| j                  j                  |«      | _        d| _        | j                  S r�   )r   r[   r¦   r¶   r‚   r‰   s     r   r   zLinearVectorFunction.fun–  s8   € Ø�‰�qÔØ�~Š~Ø—V‘V—Z‘Z “]ˆDŒFØ!ˆDŒNØ�v‰vˆr   c                 ó<   — | j                  |«       | j                  S r*   )r   r¦   r‰   s     r   r    zLinearVectorFunction.jac�  s   € Ø�‰�qÔØ�v‰vˆr   c                 óJ   — | j                  |«       || _        | j                  S r*   )r   r®   r<   rØ   s      r   r3   zLinearVectorFunction.hess¡  s   € Ø�‰�qÔØˆŒØ�v‰vˆr   N)	r�   r�   r‘   r’   rq   r   r   r    r3   r   r   r   rÚ   rÚ   k  s    „ ñò2ò<#òòór   rÚ   c                   ó"   ‡ — e Zd ZdZˆ fd„Zˆ xZS )ÚIdentityVectorFunctionzþIdentity vector function and its derivatives.

    The Jacobian is the identity matrix, returned as a dense array when
    `sparse_jacobian=False` and as a csr matrix otherwise. The Hessian is
    identically zero and it is returned as a csr matrix.
    c                 ó¨   •— t        |«      }|s|€t        j                  |d¬«      }d}nt        j                  |«      }d}t        ‰| �  |||«       y )NÚcsr)ÚformatTF)Úlenr0   Úeyer   Úsuperrq   )rk   r;   rÇ   rZ   rß   Ú	__class__s        €r   rq   zIdentityVectorFunction.__init__®  sL   ø€ Ü�‹GˆÙ˜oÐ5Ü—‘˜ %Ô(ˆAØ"‰Oä—‘�q“	ˆAØ#ˆOÜ‰Ñ˜˜B Õ0r   )r�   r�   r‘   r’   rq   Ú__classcell__)rì   s   @r   rå   rå   §  s   ø„ ñ÷1ð 1r   rå   )r   )Nr   N)NNr   N)Únumpyr   Úscipy.sparseÚsparser0   Ú_numdiffr   r   Ú_hessian_update_strategyr   Úscipy.sparse.linalgr   Úscipy._lib._array_apir   Ú
scipy._libr	   rL   r,   r   r-   r=   r?   r•   rÚ   rå   r   r   r   ú<module>rö      sc   ðÛ Ý ß 6Ý ;Ý .Ý 1Ý -ð *€
óó, ó(!&÷Hñ ÷DKñ K÷\9ñ 9ôx1Ð1õ 1r   