§
    ¡éUgŸ`  ã                   óØ   — 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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dS )é    Né   )Úapprox_derivativeÚgroup_columns)ÚHessianUpdateStrategy)ÚLinearOperator)Ú
atleast_ndÚarray_namespace)z2-pointz3-pointÚcs© c                 ó$   ‡ ‡‡— dgŠˆˆ ˆfd„}|‰fS )Nr   c                 ó(  •— ‰dxx         dz  cc<    ‰t          j        | ¦  «        g‰¢R Ž }t          j        |¦  «        sQ	 t          j        |¦  «                             ¦   «         }n)# t
          t          f$ r}t          d¦  «        |‚d }~ww xY w|S )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      €€€úg/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/scipy/optimize/_differentiable_functions.pyÚwrappedz_wrapper_fun.<locals>.wrapped   s°   ø€ Øˆqˆ	ˆ	Œ	�Q‰ˆ	ˆ	‰	ð ˆS•”˜‘”Ð#˜dÐ#Ð#Ð#ˆåŒ{˜2‰Œð 	ðÝ”Z ‘^”^×(Ò(Ñ*Ô*��øÝ�zÐ*ð ð ð Ý ð2ñô ð ðøøøøðøøøð
 ˆ	s   Á&A) Á)BÁ:B
Â
Br   )r   r   r   r   s   `` @r   Ú_wrapper_funr      s;   øøø€ ØˆS€Fðð ð ð ð ð ð ð  �Fˆ?Ðó    c                 ót   ‡ ‡‡‡‡— dgŠt          ‰ ¦  «        rˆˆ ˆfd„}|‰fS ‰ t          v rdˆˆˆfd„	}|‰fS d S )Nr   c                 ó~   •— ‰dxx         dz  cc<   t          j         ‰t          j        | ¦  «        g‰¢R Ž ¦  «        S ©Nr   r   )r   Ú
atleast_1dr   )r   Úkwdsr   Úgradr   s     €€€r   r   z_wrapper_grad.<locals>.wrapped&   sB   ø€ à�1ˆIˆIŒI˜‰NˆIˆI‰IÝ”=  ¥b¤g¨a¡j¤jÐ!8°4Ð!8Ð!8Ð!8Ñ9Ô9Ð9r   c                 óD   •— ‰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-   sD   ø€ Ø�1ˆIˆIŒI˜‰NˆIˆI‰IÝ$Ø�Qðð ØðØ!4ðð ð r   ©N)ÚcallableÚ
FD_METHODS)r$   r   r   r(   r   r)   r   s   ````  @r   Ú_wrapper_gradr-   "   s“   øøøøø€ ØˆS€Få��~„~ð  ð	:ð 	:ð 	:ð 	:ð 	:ð 	:ð 	:ð ˜ˆÐà	•Ð	Ð	ð	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð ˜ÐÐð 
Ð	r   c                 ó˜  ‡ ‡‡‡‡— t          ‰ ¦  «        r� ‰ t          j        |¦  «        g‰¢R Ž }dgŠt          j        |¦  «        rˆˆ ˆfd„}t          j        |¦  «        }nJt          |t          ¦  «        rˆˆ ˆfd„}n-ˆˆ ˆfd„}t          j        t          j	        |¦  «        ¦  «        }|‰|fS ‰ t          v rdgŠdˆˆfd„	}|‰d fS d S )Nr   c                 ó~   •— ‰dxx         dz  cc<   t          j         ‰t          j        | ¦  «        g‰¢R Ž ¦  «        S r!   )ÚspsÚ
csr_matrixr   r   ©r   r#   r   Úhessr   s     €€€r   r   z_wrapper_hess.<locals>.wrapped<   sB   ø€ Ø�q�	�	”	˜Q‘�	�	‘	Ý”~ d d­2¬7°1©:¬:Ð&=¸Ð&=Ð&=Ð&=Ñ>Ô>Ð>r   c                 óZ   •— ‰dxx         dz  cc<    ‰t          j        | ¦  «        g‰¢R Ž S r!   )r   r   r2   s     €€€r   r   z_wrapper_hess.<locals>.wrappedC   s8   ø€ Ø�q�	�	”	˜Q‘�	�	‘	Ø�t�BœG A™JœJÐ.¨Ð.Ð.Ð.Ð.r   c           	      ó¢   •— ‰dxx         dz  cc<   t          j        t          j         ‰t          j        | ¦  «        g‰¢R Ž ¦  «        ¦  «        S r!   )r   Ú
atleast_2dr   r   r2   s     €€€r   r   z_wrapper_hess.<locals>.wrappedH   sL   ø€ Ø�q�	�	”	˜Q‘�	�	‘	Ý”}¥R¤Z°°µR´W¸Q±Z´ZÐ0GÀ$Ð0GÐ0GÐ0GÑ%HÔ%HÑIÔIÐIr   r   c                 ó$   •— t          ‰| fd|i‰¤ŽS ©Nr&   r'   )r   r&   r(   r$   s     €€r   r)   z_wrapper_hess.<locals>.wrapped1R   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=   6   sW  øøøøø€ Ý��~„~ð  &ØˆD•”˜‘”Ð$˜tÐ$Ð$Ð$ˆØ�ˆåŒ<˜‰?Œ?ð 	-ð?ð ?ð ?ð ?ð ?ð ?ð ?õ ”˜qÑ!Ô!ˆAˆAå˜�>Ñ*Ô*ð 
	-ð/ð /ð /ð /ð /ð /ð /ð /ð
Jð Jð Jð Jð Jð Jð Jõ ”�bœj¨™mœmÑ,Ô,ˆAà˜ Ð!Ð!Ø	•Ð	Ð	Ø�ˆð	ð 	ð 	ð 	ð 	ð 	ð 	ð
 ˜ Ð%Ð%ð 
Ð	r   c                   óŽ   — 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dS )Ú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	                 ó8  — t          |¦  «        s!|t          vrt          dt          › d�¦  «        ‚t          |¦  «        s6|t          v s-t          |t          ¦  «        st          dt          › d�¦  «        ‚|t          v r|t          v rt          d¦  «        ‚t          |¦  «        x| _        }	t          |d|	¬¦  «        }
|	j        }|	 	                    |
j
        d¦  «        r|
j
        }t          ||¬¦  «        \  | _        | _        || _        || _        || _        || _        |	                     |
|¦  «        | _        || _        | j        j        | _        d	| _        d	| _        d	| _        d | _        t6          j        | _        i }|t          v r||d
<   ||d<   ||d<   ||d<   |t          v r||d
<   ||d<   ||d<   d|d<   |                      ¦   «          t?          || j        ||¬¦  «        \  | _         | _!        |  "                    ¦   «          t          |¦  «        r.tG          |||¬¦  «        \  | _$        | _%        | _&        d| _        d S |t          v rntG          || j         ||¬¦  «        \  | _$        | _%        | _&        |  "                    ¦   «          |  $                    | j        | j'        ¬¦  «        | _&        d| _        d S t          |t          ¦  «        rF|| _&        | j&         (                    | j        d¦  «         d| _        d | _)        d | _*        dg| _%        d S d S )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   r   Ú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Ð"8ÝØI½JÐIÐIÐIñô ð õ ˜‘”ð 	 $­*Ð"4Ð"4Ý˜dÕ$9Ñ:Ô:ð #5åð,Ý(ð,ð ,ð ,ñô ð ð
 •:ÐÐ $­*Ð"4Ð"4Ýð 8ñ 9ô 9ð 9õ
 ' rÑ*Ô*Ð*ˆŒ�"Ý˜  rÐ*Ñ*Ô*ˆØ”ˆØ�:Š:�b”h Ñ0Ô0ð 	Ø”XˆFõ )5°S¸tÐ(DÑ(DÔ(DÑ%ˆÔ˜4œ:ØˆŒØˆŒØˆŒØˆŒ
ð —’˜2˜vÑ&Ô&ˆŒØˆŒØ””ˆŒØˆŒØˆŒØˆŒàˆŒÝœˆŒà ÐØ•:ÐÐØ,0Ð Ñ)Ø.BÐ 
Ñ+Ø.5Ð 
Ñ+Ø,>Ð Ñ)Ø•:ÐÐØ,0Ð Ñ)Ø.BÐ 
Ñ+Ø.5Ð 
Ñ+Ø8<ÐÐ 4Ñ5ð 	×ÒÑÔÐõ *7ØØÔ!ØØ 3ð	*
ñ *
ô *
Ñ&ˆÔ˜DœJð 	×ÒÑÔÐõ �D‰>Œ>ð 	Ý5BØ˜ $ð6ñ 6ô 6Ñ2ˆDÔ ¤
¨D¬Fð "ˆDŒNˆNˆNØ•ZÐÐÝ5BØØÔ'ØØ$7ð	6ñ 6ô 6Ñ2ˆDÔ ¤
¨D¬Fð ×ÒÑÔÐØ×'Ò'¨¬°4´6Ð'Ñ:Ô:ˆDŒFØ!ˆDŒNˆNˆNÝ˜Õ3Ñ4Ô4ð 	ØˆDŒFØŒF×Ò˜dœf fÑ-Ô-Ð-Ø!ˆDŒNØˆDŒKØˆDŒKØ˜ˆDŒJˆJˆJð	ð 	r   c                 ó   — | j         d         S ©Nr   )rP   ©ri   s    r   ÚnfevzScalarFunction.nfev  ó   € àŒz˜!Œ}Ðr   c                 ó   — | j         d         S rq   )ra   rr   s    r   ÚngevzScalarFunction.ngev  rt   r   c                 ó   — | j         d         S rq   )rd   rr   s    r   ÚnhevzScalarFunction.nhev	  rt   r   c                 ó  — t          | j        t          ¦  «        r“|                      ¦   «          | j        | _        | j        | _        t          |d| j	        ¬¦  «        }| j	         
                    || j        ¦  «        | _        d| _        d| _        d| _        |                      ¦   «          d S t          |d| j	        ¬¦  «        }| j	         
                    || j        ¦  «        | _        d| _        d| _        d| _        d S ©Nr   rB   F)r:   rS   r   rb   r   rg   re   rh   r   rD   rU   rV   rY   rZ   r[   Ú_update_hess©ri   r   rm   s      r   Ú	_update_xzScalarFunction._update_x  sã   € Ý�d”oÕ'<Ñ=Ô=ð 	#Ø×ÒÑÔÐØœ&ˆDŒKØœ&ˆDŒKõ ˜A A¨$¬'Ð2Ñ2Ô2ˆBØ”W—^’^ B¨¬Ñ5Ô5ˆDŒFØ"ˆDŒNØ"ˆDŒNØ"ˆDŒNØ×ÒÑÔÐÐÐõ ˜A A¨$¬'Ð2Ñ2Ô2ˆBØ”W—^’^ B¨¬Ñ5Ô5ˆDŒFØ"ˆDŒNØ"ˆDŒNØ"ˆDŒNˆNˆNr   c                 ó¤   — | j         sH|                      | j        ¦  «        }|| j        k     r| j        | _        || _        || _        d| _         d S d S ©NT)rY   rO   r   r^   r\   Úf)ri   r   s     r   r_   zScalarFunction._update_fun$  sZ   € ØŒ~ð 	"Ø×"Ò" 4¤6Ñ*Ô*ˆBØ�D”NÒ"Ð"Ø!%¤�”Ø!#�”àˆDŒFØ!ˆDŒNˆNˆNð	"ð 	"r   c                 ó¶   — | j         sQ| j        t          v r|                      ¦   «          |                      | j        | j        ¬¦  «        | _        d| _         d S d S ©NrK   T)rZ   rR   r,   r_   r`   r   r€   re   rr   s    r   rb   zScalarFunction._update_grad.  s^   € ØŒ~ð 	"ØŒ¥*Ð,Ð,Ø× Ò Ñ"Ô"Ð"Ø×'Ò'¨¬°4´6Ð'Ñ:Ô:ˆDŒFØ!ˆDŒNˆNˆNð		"ð 	"r   c                 ó¾  — | j         sÕ| j        t          v r;|                      ¦   «          |                      | j        | j        ¬¦  «        | _        nƒt          | j        t          ¦  «        rJ|                      ¦   «          | j         
                    | j        | j        z
  | j        | j        z
  ¦  «         n|                      | j        ¦  «        | _        d| _         d S d S r‚   )r[   rS   r,   rb   rc   r   re   r<   r:   r   Úupdaterg   rh   rr   s    r   r{   zScalarFunction._update_hess5  sÉ   € ØŒ~ð 
	"ØŒ¥*Ð,Ð,Ø×!Ò!Ñ#Ô#Ð#Ø×+Ò+¨D¬F°t´vÐ+Ñ>Ô>�”�Ý˜DœOÕ-BÑCÔCð 4Ø×!Ò!Ñ#Ô#Ð#Ø”—’˜dœf t¤{Ñ2°D´F¸T¼[Ñ4HÑIÔIÐIÐIà×+Ò+¨D¬FÑ3Ô3�”à!ˆDŒNˆNˆNð
	"ð 
	"r   c                 ó–   — t          j        || j        ¦  «        s|                      |¦  «         |                      ¦   «          | j        S r*   )r   Úarray_equalr   r}   r_   r€   ©ri   r   s     r   r   zScalarFunction.funB  sC   € ÝŒ~˜a ¤Ñ(Ô(ð 	Ø�NŠN˜1ÑÔÐØ×ÒÑÔÐØŒvˆr   c                 ó–   — t          j        || j        ¦  «        s|                      |¦  «         |                      ¦   «          | j        S r*   )r   r†   r   r}   rb   re   r‡   s     r   r$   zScalarFunction.gradH  óC   € ÝŒ~˜a ¤Ñ(Ô(ð 	Ø�NŠN˜1ÑÔÐØ×ÒÑÔÐØŒvˆr   c                 ó–   — t          j        || j        ¦  «        s|                      |¦  «         |                      ¦   «          | j        S r*   )r   r†   r   r}   r{   r<   r‡   s     r   r3   zScalarFunction.hessN  r‰   r   c                 óÌ   — t          j        || j        ¦  «        s|                      |¦  «         |                      ¦   «          |                      ¦   «          | j        | j        fS r*   )r   r†   r   r}   r_   rb   r€   re   r‡   s     r   Úfun_and_gradzScalarFunction.fun_and_gradT  s\   € ÝŒ~˜a ¤Ñ(Ô(ð 	Ø�NŠN˜1ÑÔÐØ×ÒÑÔÐØ×ÒÑÔÐØŒv�t”vˆ~Ðr   r*   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__ro   Úpropertyrs   rv   rx   r}   r_   rb   r{   r   r$   r3   rŒ   r   r   r   r?   r?   Z   s  € € € € € ðIð IðV .2ðZð Zð Zð Zðx ðð ñ „Xðð ðð ñ „Xðð ðð ñ „Xðð#ð #ð #ð."ð "ð "ð"ð "ð "ð"ð "ð "ðð ð ðð ð ðð ð ðð ð ð ð r   r?   c                   óH   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z	d„ Z
d	„ Zd
„ ZdS )Ú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	                 óp  ‡ ‡‡‡‡‡‡‡‡— t          ‰¦  «        s!‰t          vrt          dt          › d�¦  «        ‚t          ‰¦  «        s6‰t          v s-t          ‰t          ¦  «        st          dt          › d�¦  «        ‚‰t          v r‰t          v rt          d¦  «        ‚t          |¦  «        x‰ _        }	t          |d|	¬¦  «        }
|	j        }|	 	                    |
j
        d¦  «        r|
j
        }|	                     |
|¦  «        ‰ _        |‰ _        ‰ j        j        ‰ _        d‰ _        d‰ _        d‰ _        d	‰ _        d	‰ _        d	‰ _        i Š‰t          v rE‰‰d
<   |‰d<   |�t-          |¦  «        }||f‰d<   |‰d<   t/          j        ‰ j        ¦  «        ‰ _        ‰t          v r-‰‰d
<   |‰d<   d‰d<   t/          j        ‰ j        ¦  «        ‰ _        ‰t          v r‰t          v rt          d¦  «        ‚ˆˆ fd„Šˆˆ fd„}|‰ _         |¦   «          t/          j        ‰ j        ¦  «        ‰ _        ‰ j        j        ‰ _        t          ‰¦  «        rì ‰‰ j        ¦  «        ‰ _        d‰ _        ‰ xj        dz  c_        |s|€EtA          j!        ‰ j        ¦  «        r,ˆˆ fd„ŠtA          j"        ‰ j        ¦  «        ‰ _        d‰ _#        nptA          j!        ‰ j        ¦  «        r,ˆˆ fd„Š‰ j         $                    ¦   «         ‰ _        d	‰ _#        n+ˆˆ fd„Št/          j%        ‰ j        ¦  «        ‰ _        d	‰ _#        ˆˆ fd„}në‰t          v râtM          ‰‰ j        fd‰ j        i‰¤Ž‰ _        d‰ _        |s|€FtA          j!        ‰ j        ¦  «        r-ˆˆˆ fd„}tA          j"        ‰ j        ¦  «        ‰ _        d‰ _#        nrtA          j!        ‰ j        ¦  «        r-ˆˆˆ fd„}‰ j         $                    ¦   «         ‰ _        d	‰ _#        n,ˆˆˆ fd„}t/          j%        ‰ j        ¦  «        ‰ _        d	‰ _#        |‰ _'        t          ‰¦  «        rÎ ‰‰ j        ‰ j        ¦  «        ‰ _(        d‰ _        ‰ xj        dz  c_        tA          j!        ‰ j(        ¦  «        r%ˆˆ fd„ŠtA          j"        ‰ j(        ¦  «        ‰ _(        nWt          ‰ j(        tR          ¦  «        rˆˆ fd„Šn6ˆˆ fd„Št/          j%        t/          j*        ‰ j(        ¦  «        ¦  «        ‰ _(        ˆˆ fd„}n}‰t          v rˆfd„Šˆˆˆ fd„} |¦   «          d‰ _        nVt          ‰t          ¦  «        rA‰‰ _(        ‰ j(         +                    ‰ j        d ¦  «         d‰ _        d ‰ _,        d ‰ _-        ˆ fd!„}|‰ _.        t          ‰t          ¦  «        rˆ fd"„}nˆ fd#„}|‰ _/        d S )$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                 ó^   •— ‰xj         dz  c_         t          j         ‰| ¦  «        ¦  «        S ©Nr   )rs   r   r"   )r   r   ri   s    €€r   Úfun_wrappedz,VectorFunction.__init__.<locals>.fun_wrapped¦  s*   ø€ ØˆIŒI˜‰NˆIŒIÝ”=   Q¡¤Ñ(Ô(Ð(r   c                  ó2   •—  ‰ ‰j         ¦  «        ‰_        d S r*   )r   r€   )r˜   ri   s   €€r   Ú
update_funz+VectorFunction.__init__.<locals>.update_funª  s   ø€ Ø �[ ¤Ñ(Ô(ˆDŒFˆFˆFr   c                 ó^   •— ‰xj         dz  c_         t          j         ‰| ¦  «        ¦  «        S r—   )Únjevr0   r1   ©r   Újacri   s    €€r   Újac_wrappedz,VectorFunction.__init__.<locals>.jac_wrapped»  s*   ø€ Ø�I”I ‘N�I”IÝœ>¨#¨#¨a©&¬&Ñ1Ô1Ð1r   c                 ó^   •— ‰xj         dz  c_          ‰| ¦  «                             ¦   «         S r—   )rœ   Útoarrayr�   s    €€r   rŸ   z,VectorFunction.__init__.<locals>.jac_wrappedÂ  s*   ø€ Ø�I”I ‘N�I”IØ˜3˜q™6œ6Ÿ>š>Ñ+Ô+Ð+r   c                 ó^   •— ‰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”IÝœ=¨¨¨Q©¬Ñ0Ô0Ð0r   c                  ó2   •—  ‰ ‰j         ¦  «        ‰_        d S r*   )r   ÚJ)rŸ   ri   s   €€r   Ú
update_jacz+VectorFunction.__init__.<locals>.update_jacÏ  s   ø€ Ø$˜ T¤VÑ,Ô,�”��r   r&   c                  ó’   •— ‰                      ¦   «          t          j        t          ‰‰j        fd‰j        i‰ ¤Ž¦  «        ‰_        d S r8   )r_   r0   r1   r   r   r€   r¤   ©r(   r˜   ri   s   €€€r   r¥   z+VectorFunction.__init__.<locals>.update_jacÙ  s\   ø€ Ø×$Ò$Ñ&Ô&Ð&Ý œ^Ý)¨+°t´vð Að AÀ$Ä&ð AØ,?ðAð AñBô B�D”F�F�Fr   c                  ó’   •— ‰                      ¦   «          t          ‰‰j        fd‰j        i‰ ¤Ž                     ¦   «         ‰_        d S r8   )r_   r   r   r€   r¡   r¤   r§   s   €€€r   r¥   z+VectorFunction.__init__.<locals>.update_jacâ  sW   ø€ Ø×$Ò$Ñ&Ô&Ð&Ý.¨{¸D¼Fð Fð FÀtÄvð FØ1DðFð FßFMÂgÁiÄið ”F�F�Fr   c                  ó’   •— ‰                      ¦   «          t          j        t          ‰‰j        fd‰j        i‰ ¤Ž¦  «        ‰_        d S r8   )r_   r   r6   r   r   r€   r¤   r§   s   €€€r   r¥   z+VectorFunction.__init__.<locals>.update_jacê  s\   ø€ Ø×$Ò$Ñ&Ô&Ð&Ýœ]Ý)¨+°t´vð Að AÀ$Ä&ð AØ,?ðAð AñBô B�D”F�F�Fr   c                 ó`   •— ‰xj         dz  c_         t          j         ‰| |¦  «        ¦  «        S r—   )rx   r0   r1   ©r   Úvr3   ri   s     €€r   Úhess_wrappedz-VectorFunction.__init__.<locals>.hess_wrappedû  s,   ø€ Ø�I”I ‘N�I”IÝœ>¨$¨$¨q°!©*¬*Ñ5Ô5Ð5r   c                 ó<   •— ‰xj         dz  c_          ‰| |¦  «        S r—   )rx   r«   s     €€r   r­   z-VectorFunction.__init__.<locals>.hess_wrapped  s"   ø€ Ø�I”I ‘N�I”IØ˜4  1™:œ:Ð%r   c                 ó„   •— ‰xj         dz  c_         t          j        t          j         ‰| |¦  «        ¦  «        ¦  «        S r—   )rx   r   r6   r   r«   s     €€r   r­   z-VectorFunction.__init__.<locals>.hess_wrapped  s6   ø€ Ø�I”I ‘N�I”IÝœ=­¬°D°D¸¸A±J´JÑ)?Ô)?Ñ@Ô@Ð@r   c                  ó>   •—  ‰ ‰j         ‰j        ¦  «        ‰_        d S r*   )r   r¬   r<   )r­   ri   s   €€r   Úupdate_hessz,VectorFunction.__init__.<locals>.update_hess  s   ø€ Ø%˜ d¤f¨d¬fÑ5Ô5�”��r   c                 ó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                  ó¶   •— ‰                      ¦   «          t          ‰‰j        f‰j        j                             ‰j        ¦  «        ‰j        fdœ‰ ¤Ž‰_        d S )N)r&   r   )Ú_update_jacr   r   r¤   r³   r´   r¬   r<   )r(   rµ   ri   s   €€€r   r±   z,VectorFunction.__init__.<locals>.update_hess  sf   ø€ Ø× Ò Ñ"Ô"Ð"Ý*¨9°d´fð BØ.2¬f¬h¯lªl¸4¼6Ñ.BÔ.BØ15´°	ðBð Bð .AðBð B�”��r   r3   c                  ó:  •— ‰                      ¦   «          ‰j        �|‰j        �w‰j        ‰j        z
  } ‰j        j                             ‰j        ¦  «        ‰j        j                             ‰j        ¦  «        z
  }‰j         	                    | |¦  «         d S d S d S r*   )
r·   rg   ÚJ_prevr   r¤   r³   r´   r¬   r<   r„   )Údelta_xÚdelta_gri   s     €r   r±   z,VectorFunction.__init__.<locals>.update_hess   sŽ   ø€ Ø× Ò Ñ"Ô"Ð"ð ”;Ð*¨t¬{Ð/FØ"œf t¤{Ñ2�GØ"œfœhŸlšl¨4¬6Ñ2Ô2°T´[´]×5FÒ5FÀtÄvÑ5NÔ5NÑN�GØ”F—M’M '¨7Ñ3Ô3Ð3Ð3Ð3ð +Ð*Ð/FÐ/Fr   c                 ó*  •— ‰                      ¦   «          ‰j        ‰_        ‰j        ‰_        t          | d‰j        ¬¦  «        }‰j                             |‰j        ¦  «        ‰_        d‰_	        d‰_
        d‰_        ‰                     ¦   «          d S rz   )r·   r   rg   r¤   r¹   r   rD   rU   rV   rY   Ú	J_updatedr[   r{   ©r   rm   ri   s     €r   Úupdate_xz)VectorFunction.__init__.<locals>.update_x,  sƒ   ø€ Ø× Ò Ñ"Ô"Ð"Ø"œf�”Ø"œf�”Ý ¨¨d¬gÐ6Ñ6Ô6�ØœŸš¨¨D¬LÑ9Ô9�”Ø!&�”Ø!&�”Ø!&�”Ø×!Ò!Ñ#Ô#Ð#Ð#Ð#r   c                 óª   •— t          | d‰j        ¬¦  «        }‰j                             |‰j        ¦  «        ‰_        d‰_        d‰_        d‰_        d S rz   )r   rD   rU   rV   r   rY   r½   r[   r¾   s     €r   r¿   z)VectorFunction.__init__.<locals>.update_x7  sK   ø€ Ý ¨¨d¬gÐ6Ñ6Ô6�ØœŸš¨¨D¬LÑ9Ô9�”Ø!&�”Ø!&�”Ø!&�”��r   )0r+   r,   r   r:   r   r	   rD   r   rL   rM   rN   rU   r   rV   rW   rX   rs   rœ   rx   rY   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   r   rf   rg   r¹   Ú_update_hess_implÚ_update_x_impl)ri   r   r;   rž   r3   rj   Úfinite_diff_jac_sparsityrk   rÅ   rD   rm   rn   Úsparsity_groupsrš   r¥   r±   r¿   r(   r˜   r­   rµ   rŸ   s   `` ``            @@@@@r   ro   zVectorFunction.__init__m  s™  øøøøøøøøø€ õ ˜‰}Œ}ð 	W ­JÐ!6Ð!6ÝÐUÍ
ÐUÐUÐUÑVÔVÐVå˜‘”ð 	O $­*Ð"4Ð"4Ý˜dÕ$9Ñ:Ô:ð #5åð NÝ@JðNð Nð Nñ Oô Oð Oð •*ÐÐ ­Ð!3Ð!3Ýð +ñ ,ô ,ð ,õ
 ' rÑ*Ô*Ð*ˆŒ�"Ý˜  rÐ*Ñ*Ô*ˆØ”ˆØ�:Š:�b”h Ñ0Ô0ð 	Ø”XˆFð —’˜2˜vÑ&Ô&ˆŒØˆŒà””ˆŒØˆŒ	ØˆŒ	ØˆŒ	ØˆŒØˆŒØˆŒà ÐØ•*ÐÐØ,/Ð Ñ)Ø.BÐ 
Ñ+Ø'Ð3Ý"/Ð0HÑ"IÔ"I�Ø3KØ3Bð3DÐ# JÑ/à,>Ð Ñ)Ýœ' $¤&™/œ/ˆDŒKØ•:ÐÐØ,0Ð Ñ)Ø.BÐ 
Ñ+Ø8<ÐÐ 4Ñ5Ýœ' $¤&™/œ/ˆDŒKØ•*ÐÐ ­Ð!3Ð!3Ýð +ñ ,ô ,ð ,ð	)ð 	)ð 	)ð 	)ð 	)ð 	)ð	)ð 	)ð 	)ð 	)ð 	)ð 	)ð !+ˆÔØˆ
‰Œˆå”˜tœvÑ&Ô&ˆŒØ””ˆŒõ �C‰=Œ=ð <	-Ø�S˜œ‘[”[ˆDŒFØ!ˆDŒNØˆIŒI˜‰NˆIŒIàð -Ø#Ð+µ´¸T¼VÑ0DÔ0DÐ+ð2ð 2ð 2ð 2ð 2ð 2õ œ¨¬Ñ/Ô/�”Ø'+�Ô$Ð$å”˜dœfÑ%Ô%ð -ð,ð ,ð ,ð ,ð ,ð ,ð œŸšÑ)Ô)�”Ø',�Ô$Ð$ð1ð 1ð 1ð 1ð 1ð 1õ œ t¤vÑ.Ô.�”Ø',�Ô$ð-ð -ð -ð -ð -ð -ð -ð •JÐÐÝ& {°D´Fð >ð >¸t¼vð >Ø)<ð>ð >ˆDŒFà!ˆDŒNàð -Ø#Ð+µ´¸T¼VÑ0DÔ0DÐ+ðBð Bð Bð Bð Bð Bð Bõ
 œ¨¬Ñ/Ô/�”Ø'+�Ô$Ð$å”˜dœfÑ%Ô%ð -ðPð Pð Pð Pð Pð Pð Pð œŸšÑ)Ô)�”Ø',�Ô$Ð$ðBð Bð Bð Bð Bð Bð Bõ
 œ t¤vÑ.Ô.�”Ø',�Ô$à *ˆÔõ �D‰>Œ>ð 2	4Ø�T˜$œ& $¤&Ñ)Ô)ˆDŒFØ!ˆDŒNØˆIŒI˜‰NˆIŒIåŒ|˜DœFÑ#Ô#ð ;ð6ð 6ð 6ð 6ð 6ð 6õ œ¨¬Ñ/Ô/�”�å˜DœF¥NÑ3Ô3ð 	;ð&ð &ð &ð &ð &ð &ð &ð
Að Að Að Að Að Aõ œ¥r¤z°$´&Ñ'9Ô'9Ñ:Ô:�”ð6ð 6ð 6ð 6ð 6ð 6ð 6à•ZÐÐð/ð /ð /ð /ð /ðBð Bð Bð Bð Bð Bð Bð ˆK‰MŒMˆMØ!ˆDŒNˆNÝ˜Õ3Ñ4Ô4ð 	4ØˆDŒFØŒF×Ò˜dœf fÑ-Ô-Ð-Ø!ˆDŒNØˆDŒKØˆDŒKð4ð 4ð 4ð 4ð 4ð "-ˆÔå�dÕ1Ñ2Ô2ð 	'ð	$ð 	$ð 	$ð 	$ð 	$ð 	$ð'ð 'ð 'ð 'ð 'ð 'ˆÔÐÐr   c                 óZ   — t          j        || j        ¦  «        s|| _        d| _        d S d S )NF)r   r†   r¬   r[   )ri   r¬   s     r   Ú	_update_vzVectorFunction._update_v@  s4   € ÝŒ~˜a ¤Ñ(Ô(ð 	#ØˆDŒFØ"ˆDŒNˆNˆNð	#ð 	#r   c                 óh   — t          j        || j        ¦  «        s|                      |¦  «         d S d S r*   )r   r†   r   rÈ   r‡   s     r   r}   zVectorFunction._update_xE  s<   € ÝŒ~˜a ¤Ñ(Ô(ð 	#Ø×Ò Ñ"Ô"Ð"Ð"Ð"ð	#ð 	#r   c                 óN   — | j         s|                      ¦   «          d| _         d S d S r   )rY   rÂ   rr   s    r   r_   zVectorFunction._update_funI  ó3   € ØŒ~ð 	"Ø×!Ò!Ñ#Ô#Ð#Ø!ˆDŒNˆNˆNð	"ð 	"r   c                 óN   — | j         s|                      ¦   «          d| _         d S d S r   )r½   rÆ   rr   s    r   r·   zVectorFunction._update_jacN  rÏ   r   c                 óN   — | j         s|                      ¦   «          d| _         d S d S r   )r[   rÇ   rr   s    r   r{   zVectorFunction._update_hessS  s3   € ØŒ~ð 	"Ø×"Ò"Ñ$Ô$Ð$Ø!ˆDŒNˆNˆNð	"ð 	"r   c                 ób   — |                       |¦  «         |                      ¦   «          | j        S r*   )r}   r_   r€   r‡   s     r   r   zVectorFunction.funX  ó-   € Ø�Š�qÑÔÐØ×ÒÑÔÐØŒvˆr   c                 ób   — |                       |¦  «         |                      ¦   «          | j        S r*   )r}   r·   r¤   r‡   s     r   rž   zVectorFunction.jac]  rÓ   r   c                 óŒ   — |                       |¦  «         |                      |¦  «         |                      ¦   «          | j        S r*   )rÌ   r}   r{   r<   ©ri   r   r¬   s      r   r3   zVectorFunction.hessb  s?   € à�Š�qÑÔÐØ�Š�qÑÔÐØ×ÒÑÔÐØŒvˆr   N)r�   rŽ   r�   r�   ro   rÌ   r}   r_   r·   r{   r   rž   r3   r   r   r   r“   r“   \  s©   € € € € € ðð ð Q'ð Q'ð Q'ðf#ð #ð #ð
#ð #ð #ð"ð "ð "ð
"ð "ð "ð
"ð "ð "ð
ð ð ð
ð ð ð
ð ð ð ð r   r“   c                   ó0   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ ZdS )Ú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                 óH  — |s|€5t          j        |¦  «        r!t          j        |¦  «        | _        d| _        ngt          j        |¦  «        r!|                     ¦   «         | _        d| _        n2t          j        t          j        |¦  «        ¦  «        | _        d| _        | j        j	        \  | _
        | _        t          |¦  «        x| _        }t          |d|¬¦  «        }|j        }|                     |j        d¦  «        r|j        }|                     ||¦  «        | _        || _        | j                             | j        ¦  «        | _        d| _        t          j        | j
        t2          ¬¦  «        | _        t          j        | j        | j        f¦  «        | _        d S )NTFr   rB   rE   )rN   )r0   r9   r1   r¤   rÅ   r¡   r   r6   r   ÚshaperÄ   rX   r	   rD   r   rL   rM   rN   rU   r   rV   r´   r€   rY   ÚzerosÚfloatr¬   r<   )ri   ÚAr;   rÅ   rD   rm   rn   s          r   ro   zLinearVectorFunction.__init__q  sV  € Øð 		)˜oÐ5½#¼,Àq¹/¼/Ð5Ý”^ AÑ&Ô&ˆDŒFØ#'ˆDÔ Ð ÝŒ\˜!‰_Œ_ð 	)Ø—Y’Y‘[”[ˆDŒFØ#(ˆDÔ Ð õ ”]¥2¤:¨a¡=¤=Ñ1Ô1ˆDŒFØ#(ˆDÔ àœœ‰ˆŒ�”å& rÑ*Ô*Ð*ˆŒ�"Ý˜  rÐ*Ñ*Ô*ˆØ”ˆØ�:Š:�b”h Ñ0Ô0ð 	Ø”XˆFð —’˜2˜vÑ&Ô&ˆŒØˆŒà”—’˜DœFÑ#Ô#ˆŒØˆŒå”˜$œ&­Ð.Ñ.Ô.ˆŒÝ” ¤¨¬Ð 0Ñ1Ô1ˆŒˆˆr   c                 óÄ   — t          j        || j        ¦  «        sEt          |d| j        ¬¦  «        }| j                             || j        ¦  «        | _        d| _        d S d S rz   )r   r†   r   r   rD   rU   rV   rY   r|   s      r   r}   zLinearVectorFunction._update_x�  s\   € ÝŒ~˜a ¤Ñ(Ô(ð 	#Ý˜A A¨$¬'Ð2Ñ2Ô2ˆBØ”W—^’^ B¨¬Ñ5Ô5ˆDŒFØ"ˆDŒNˆNˆNð	#ð 	#r   c                 ó”   — |                       |¦  «         | j        s&| j                             |¦  «        | _        d| _        | j        S r   )r}   rY   r¤   r´   r€   r‡   s     r   r   zLinearVectorFunction.fun•  s?   € Ø�Š�qÑÔÐØŒ~ð 	"Ø”V—Z’Z ‘]”]ˆDŒFØ!ˆDŒNØŒvˆr   c                 ó:   — |                       |¦  «         | j        S r*   )r}   r¤   r‡   s     r   rž   zLinearVectorFunction.jacœ  s   € Ø�Š�qÑÔÐØŒvˆr   c                 óH   — |                       |¦  «         || _        | j        S r*   )r}   r¬   r<   rÖ   s      r   r3   zLinearVectorFunction.hess   s"   € Ø�Š�qÑÔÐØˆŒØŒvˆr   N)	r�   rŽ   r�   r�   ro   r}   r   rž   r3   r   r   r   rØ   rØ   j  si   € € € € € ðð ð2ð 2ð 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	          ¦   «                              |||¦  «         d S )NÚcsr)ÚformatTF)Úlenr0   Úeyer   Úsuperro   )ri   r;   rÅ   rX   rÝ   Ú	__class__s        €r   ro   zIdentityVectorFunction.__init__­  sj   ø€ Ý�‰GŒGˆØð 	$˜oÐ5Ý”˜ %Ð(Ñ(Ô(ˆAØ"ˆOˆOå”�q‘	”	ˆAØ#ˆOÝ‰Œ×Ò˜˜B Ñ0Ô0Ð0Ð0Ð0r   )r�   rŽ   r�   r�   ro   Ú__classcell__)rê   s   @r   rã   rã   ¦  sB   ø€ € € € € ðð ð1ð 1ð 1ð 1ð 1ð 1ð 1ð 1ð 1r   rã   )r   )Nr   N)NNr   N)Únumpyr   Úscipy.sparseÚsparser0   Ú_numdiffr   r   Ú_hessian_update_strategyr   Úscipy.sparse.linalgr   Úscipy._lib._array_apir   r	   r,   r   r-   r=   r?   r“   rØ   rã   r   r   r   ú<module>ró      s{  ðØ Ð Ð Ð Ø Ð Ð Ð Ð Ð Ø 6Ð 6Ð 6Ð 6Ð 6Ð 6Ð 6Ð 6Ø ;Ð ;Ð ;Ð ;Ð ;Ð ;Ø .Ð .Ð .Ð .Ð .Ð .Ø =Ð =Ð =Ð =Ð =Ð =Ð =Ð =ð *€
ðð ð ð ð, ð  ð  ð  ð(!&ð !&ð !&ð !&ðHð ð ð ð ñ ô ð ðDKð Kð Kð Kð Kñ Kô Kð Kð\9ð 9ð 9ð 9ð 9ñ 9ô 9ð 9ðx1ð 1ð 1ð 1ð 1Ð1ñ 1ô 1ð 1ð 1ð 1r   