ó
    Eñiu  ã                   ó.  • S SK Jr  S SKrS SKJr  SSKJrJ	r	  SSK
Jr  S SKJr  S SKJrJr  S SKJr  S S	KJr  S
r " S S5      r " S S5      r " S S5      r " S S5      r " S S5      r " S S5      r " S S5      r " S S5      r " S S\5      rg)é    )Ú
namedtupleNé   )Úapprox_derivativeÚgroup_columns)ÚHessianUpdateStrategy)ÚLinearOperator)Úarray_namespaceÚxp_copy)Úarray_api_extra)Ú_ScalarFunctionWrapper)z2-pointz3-pointÚcsc                   ó2   • \ rS rSrSr   SS jrSS jrSrg)	Ú_ScalarGradWrapperé   z(
Wrapper class for gradient calculation
Nc                 ó\   • X l         Xl        Uc  / OUU l        X@l        SU l        SU l        g ©Nr   )ÚfunÚgradÚargsÚfinite_diff_optionsÚngevÚnfev)Úselfr   r   r   r   s        Úe/home/mande/repo/quber/.venv/lib/python3.13/site-packages/scipy/optimize/_differentiable_functions.pyÚ__init__Ú_ScalarGradWrapper.__init__   s/   € ð ŒØŒ	Ø™,‘B¨DˆŒ	Ø#6Ô ØˆŒ	àˆ�	ó    c                 ó’  • [        U R                  5      (       aF  [        R                  " U R                  " [        R                  " U5      /U R
                  Q76 5      nOQU R                  [        ;   a=  [        U R                  U4SU0U R                  D6u  pEU =R                  US   -  sl
        U =R                  S-  sl        W$ )NÚf0r   r   )Úcallabler   ÚnpÚ
atleast_1dÚcopyr   Ú
FD_METHODSr   r   r   r   r   )r   Úxr   ÚkwdsÚgÚdcts         r   Ú__call__Ú_ScalarGradWrapper.__call__#   s�   € ô �D—I‘I×ÑÜ—’˜dŸiši¬¯ª°«
Ð?°T·Y±YÒ?Ó@‰AØ�Y‰Yœ*Ó$Ü&Ø—‘Øñð ðð ×*Ñ*ñ	‰FˆAð �IŠI˜˜V™Ñ$�Ià�	Š	�Q‰�	Øˆr   )r   r   r   r   r   r   ©NNN©N©Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   r)   Ú__static_attributes__© r   r   r   r      s   † ñð ØØ $ô÷r   r   c                   óP   • \ rS rSrSr    SS jrSS jrSS jrS rS r	S	 r
S
rg)Ú_ScalarHessWrapperé5   z;
Wrapper class for hess calculation via finite differences
Nc                 óž  • Xl         X0l        Uc  / OUU l        XPl        SU l        SU l        S U l        S U l        [        U5      (       añ  U" [        R                  " U5      /UQ76 U l        U =R
                  S-  sl        [        R                  " U R                  5      (       a-  SU l        [        R                  " U R                  5      U l        g [        U R                  [        5      (       a  SU l        g SU l        [        R                   " [        R"                  " U R                  5      5      U l        g U[$        ;   a  SU l        g g )Nr   r   Úsparse_callableÚlinearoperator_callableÚdense_callableÚfd_hess)Úhessr   r   r   r   ÚnhevÚHÚ
_hess_funcr    r!   r#   ÚspsÚissparseÚ	csr_arrayÚ
isinstancer   Ú
atleast_2dÚasarrayr$   )r   r=   Úx0r   r   r   s         r   r   Ú_ScalarHessWrapper.__init__9   sì   € ð Œ	ØŒ	Ø™,‘B¨DˆŒ	Ø#6Ô àˆŒ	ØˆŒ	ØˆŒØˆŒä�D�>‰>Ùœ"Ÿ'š' "›+Ð-¨Ò-ˆDŒFØ�IŠI˜‰N�Iä�|Š|˜DŸF™F×#Ñ#Ø"3�”ÜŸš t§v¡vÓ.�•Ü˜DŸF™F¤N×3Ñ3Ø";�•ð #3�”ÜŸš¤r§z¢z°$·&±&Ó'9Ó:�•Ø”ZÓØ"+�•ð  r   c                 óè   • U R                   =S:X  a    U R                  nO9=S:X  a    U R                  nO%=S:X  a    U R                  nOS:X  a  U R                  nW" [
        R                  " U5      US9$ )Nr9   r:   r;   r<   ©r   )r@   Ú_sparse_callableÚ_linearoperator_callableÚ_dense_callableÚ_fd_hessr!   r#   )r   r%   r   r&   Ú_hs        r   r)   Ú_ScalarHessWrapper.__call__[   sT   € Ø�o‰oÞ"Ø×*Ñ*‘Þ*Ø×2Ñ2‘Þ!Ø×)Ñ)‘ÜØ—]‘]�á”"—'’'˜!“* Ñ$Ð$r   c                 ó    • [        U R                  U4SU0U R                  D6u  U l        nU =R                  US   -  sl        U R                  $ )Nr   r   )r   r   r   r?   r   )r   r%   r   r&   r(   s        r   rN   Ú_ScalarHessWrapper._fd_hessh   sN   € Ü'Ø�I‰I�qñ
Øð
Ø#'×#;Ñ#;ñ
‰ˆŒ�ð 	�	Š	�S˜‘[Ñ �	Ø�v‰vˆr   c                 ó°   • U =R                   S-  sl         [        R                  " U R                  " U/U R                  Q76 5      U l        U R
                  $ ©Nr   )r>   rA   rC   r=   r   r?   ©r   r%   r&   s      r   rK   Ú#_ScalarHessWrapper._sparse_callableo   s:   € Ø�	Š	�Q‰�	Ü—’˜tŸyšy¨Ð7¨T¯Y©YÒ7Ó8ˆŒØ�v‰vˆr   c                 óØ   • U =R                   S-  sl         [        R                  " [        R                  " U R                  " U/U R
                  Q76 5      5      U l        U R                  $ rT   )r>   r!   rE   rF   r=   r   r?   rU   s      r   rM   Ú"_ScalarHessWrapper._dense_callablet   sH   € Ø�	Š	�Q‰�	Ü—’Ü�JŠJ�t—y’y Ð/ T§Y¡YÒ/Ó0ó
ˆŒð �v‰vˆr   c                 óˆ   • U =R                   S-  sl         U R                  " U/U R                  Q76 U l        U R                  $ rT   )r>   r=   r   r?   rU   s      r   rL   Ú+_ScalarHessWrapper._linearoperator_callable{   s1   € Ø�	Š	�Q‰�	Ø—’˜1Ð)˜tŸy™yÒ)ˆŒØ�v‰vˆr   )r?   r@   r   r   r   r=   r   r>   )NNNNr,   )r.   r/   r0   r1   r2   r   r)   rN   rK   rM   rL   r3   r4   r   r   r6   r6   5   s4   † ñð ØØØ $ô ,ôD%ôòò
õr   r6   c                   ó¸   • \ rS rSrSrS\R                  * \R                  4SS4S jr\S 5       r	\S 5       r
\S 5       rS rS	 rS
 rS rS rS rS rS rSrg)ÚScalarFunctioné€   a“  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.
workers : map-like callable, optional
    A map-like callable, such as `multiprocessing.Pool.map` for evaluating
    any numerical differentiation in parallel.
    This evaluation is carried out as ``workers(fun, iterable)``, or
    ``workers(grad, iterable)``, depending on what is being numerically
    differentiated.
    Alternatively, if `workers` is an int the task is subdivided into `workers`
    sections and the function evaluated in parallel
    (uses `multiprocessing.Pool <multiprocessing>`).
    Supply -1 to use all available CPU cores.
    It is recommended that a map-like be used instead of int, as repeated
    calls to `approx_derivative` will incur large overhead from setting up
    new processes.

    .. versionadded:: 1.16.0

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
                 óŒ  • [        U5      (       d  U[        ;  a  [        S[         S35      e[        U5      (       d2  U[        ;   d(  [        U[        5      (       d  [        S[         S35      eU[        ;   a  U[        ;   a  [        S5      e[        U5      =U l        n
[        R                  " U
R                  U5      SU
S9nU
R                  nU
R                  UR                  S5      (       a  UR                  n[        X5      U l        Xl        X@l        XPl        X0l        U
R'                  X¼5      U l        XÀl        U R(                  R,                  U l        SU l        SU l        SU l        S U l        [8        R:                  U l        U	=(       d    [>        n	0 nU[        ;   a  XMS	'   XmS
'   X�S'   X}S'   X�S'   SUS'   U[        ;   a  X]S	'   XmS
'   X�S'   SUS'   X�S'   SUS'   SU l         U RC                  5         [E        UU R                  UUS9U l#        U RI                  5         [        U[        5      (       a\  XPl%        U RJ                  RM                  U R.                  S5        SU l        S U l'        S U l(        [S        SSS/5      nU" SSS9U l*        g [        U5      (       a4  [W        UUUUS9U l*        U RT                  RJ                  U l%        SU l        g U[        ;   a]  [W        UUUU RF                  US9U l*        U RI                  5         U RU                  U R(                  U RX                  S9U l%        SU l        g g )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 floatingFÚmethodÚrel_stepÚabs_stepÚboundsÚworkersTÚfull_outputÚas_linear_operatorr   )r   r   r   r=   Ú_FakeCounterr   r>   )r   r>   )rG   r   r   )rG   r   r   r   rJ   )-r    r$   Ú
ValueErrorrD   r   r	   rb   ÚxpxÚ
atleast_ndrF   Úfloat64ÚisdtypeÚdtyper   Ú_wrapped_funÚ	_orig_funÚ
_orig_gradÚ
_orig_hessÚ_argsÚastyper%   Úx_dtypeÚsizeÚnÚ	f_updatedÚ	g_updatedÚ	H_updatedÚ	_lowest_xr!   ÚinfÚ	_lowest_fÚmapÚ_nfevÚ_update_funr   Ú_wrapped_gradÚ_update_gradr?   Ú
initializeÚx_prevÚg_prevr   Ú_wrapped_hessr6   r'   )r   r   rG   r   r   r=   Úfinite_diff_rel_stepÚfinite_diff_boundsÚepsilonrh   rb   Ú_xÚ_dtyper   rk   s                  r   r   Ú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Ñ0Ø—X‘XˆFô 3°3Ó=ˆÔØŒØŒØŒØŒ
ð —‘˜2Ó&ˆŒØŒØ—‘—‘ˆŒØˆŒØˆŒØˆŒàˆŒÜŸ™ˆŒð —.œSˆà ÐØ”:ÓØ,0 Ñ)Ø.B 
Ñ+Ø.5 
Ñ+Ø,> Ñ)Ø-4 	Ñ*Ø15Ð Ñ.Ø”:ÓØ,0 Ñ)Ø.B 
Ñ+Ø.5 
Ñ+Ø8<ÐÐ 4Ñ5Ø-4 	Ñ*Ø15Ð Ñ.ð ˆŒ
Ø×ÑÔô 0ØØ×!Ñ!ØØ 3ñ	
ˆÔð 	×ÑÔô �dÔ1×2Ñ2ØŒFØ�F‰F×Ñ˜dŸf™f fÔ-Ø!ˆDŒNØˆDŒKØˆDŒKÜ% n°v¸vÐ6FÓGˆLÙ!-°1¸1Ñ!=ˆDÕä˜�~‰~Ü%7ØØØØ(;ñ	&�Ô"ð ×+Ñ+×-Ñ-�”Ø!%�•ØœÓ#Ü%7ØØØØ×+Ñ+Ø(;ñ&�Ô"ð ×!Ñ!Ô#Ø×+Ñ+¨D¯F©F°t·v±vÐ+Ð>�”Ø!%�•ð $r   c                 óH   • U R                   U R                  R                  -   $ r,   )r‚   r„   r   ©r   s    r   r   ÚScalarFunction.nfevE  s   € à�z‰z˜D×.Ñ.×3Ñ3Ñ3Ð3r   c                 ó.   • U R                   R                  $ r,   )r„   r   r‘   s    r   r   ÚScalarFunction.ngevI  ó   € à×!Ñ!×&Ñ&Ð&r   c                 ó.   • U R                   R                  $ r,   )r‰   r>   r‘   s    r   r>   ÚScalarFunction.nhevM  r•   r   c                 ó¨  • [        U R                  [        5      (       a»  U R                  5         U R                  U l        U R                  U l        [        R                  " U R                  R                  U5      SU R                  S9nU R                  R                  X R                  5      U l        SU l        SU l        SU l        U R#                  5         g [        R                  " U R                  R                  U5      SU R                  S9nU R                  R                  X R                  5      U l        SU l        SU l        SU l        g ©Nr   r`   F)rD   ru   r   r…   r%   r‡   r'   rˆ   rm   rn   rb   rF   rw   rx   r{   r|   r}   Ú_update_hess©r   r%   r�   s      r   Ú	_update_xÚScalarFunction._update_xQ  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                 óî   • U R                   (       dd  U R                  U R                  5      nU =R                  S-  sl        XR                  :  a  U R                  U l        Xl        Xl        SU l         g g ©Nr   T)r{   rr   r%   r‚   r€   r~   Úf)r   Úfxs     r   rƒ   ÚScalarFunction._update_funh  sU   € Ø�~�~Ø×"Ñ" 4§6¡6Ó*ˆBØ�JŠJ˜!‰O�JØ—N‘NÓ"Ø!%§¡�”Ø!#”àŒFØ!ˆD�Nð r   c                 óÐ   • U R                   (       dU  U R                  [        ;   a  U R                  5         U R	                  U R
                  U R                  S9U l        SU l         g g ©NrJ   T)r|   rt   r$   rƒ   r„   r%   r    r'   r‘   s    r   r…   ÚScalarFunction._update_grads  sL   € Ø�~�~Ø�‰¤*Ó,Ø× Ñ Ô"Ø×'Ñ'¨¯©°4·6±6Ð'Ð:ˆDŒFØ!ˆD�Nð	 r   c                 ó  • U R                   (       dð  U R                  [        ;   a:  U R                  5         U R	                  U R
                  U R                  S9U l        Oš[        U R                  [        5      (       a[  U R                  5         U R                  R                  U R
                  U R                  -
  U R                  U R                  -
  5        O U R	                  U R
                  5      U l        SU l         g g r¤   )r}   ru   r$   r…   r‰   r%   r'   r?   rD   r   Úupdater‡   rˆ   r‘   s    r   rš   ÚScalarFunction._update_hessz  s¬   € Ø�~�~Ø�‰¤*Ó,Ø×!Ñ!Ô#Ø×+Ñ+¨D¯F©F°t·v±vÐ+Ð>�•Ü˜DŸO™OÔ-B×CÑCØ×!Ñ!Ô#Ø—‘—‘˜dŸf™f t§{¡{Ñ2°D·F±F¸T¿[¹[Ñ4HÕIà×+Ñ+¨D¯F©FÓ3�”à!ˆD�Nð r   c                 ó¦   • [         R                  " XR                  5      (       d  U R                  U5        U R	                  5         U R
                  $ r,   )r!   Úarray_equalr%   rœ   rƒ   r    ©r   r%   s     r   r   ÚScalarFunction.fun‡  s6   € Ü�~Š~˜a§¡×(Ñ(Ø�N‰N˜1ÔØ×ÑÔØ�v‰vˆr   c                 ó¦   • [         R                  " XR                  5      (       d  U R                  U5        U R	                  5         U R
                  $ r,   )r!   rª   r%   rœ   r…   r'   r«   s     r   r   ÚScalarFunction.grad�  ó6   € Ü�~Š~˜a§¡×(Ñ(Ø�N‰N˜1ÔØ×ÑÔØ�v‰vˆr   c                 ó¦   • [         R                  " XR                  5      (       d  U R                  U5        U R	                  5         U R
                  $ r,   )r!   rª   r%   rœ   rš   r?   r«   s     r   r=   ÚScalarFunction.hess“  r¯   r   c                 óÞ   • [         R                  " XR                  5      (       d  U R                  U5        U R	                  5         U R                  5         U R                  U R                  4$ r,   )r!   rª   r%   rœ   rƒ   r…   r    r'   r«   s     r   Úfun_and_gradÚScalarFunction.fun_and_grad™  sK   € Ü�~Š~˜a§¡×(Ñ(Ø�N‰N˜1ÔØ×ÑÔØ×ÑÔØ�v‰v�t—v‘vˆ~Ðr   )r?   r}   rv   r€   r~   r‚   rs   rt   ru   rr   r„   r‰   r    r{   r'   rˆ   r|   rz   r%   rx   r‡   rb   )r.   r/   r0   r1   r2   r!   r   r   Úpropertyr   r   r>   rœ   rƒ   r…   rš   r   r   r=   r³   r3   r4   r   r   r\   r\   €   s‘   † ñXðr HLØ&(§f¡f W¨b¯f©fÐ$5¸tÈTôi&ðV ñ4ó ð4ð ñ'ó ð'ð ñ'ó ð'ò#ò.	"ò"ò"òòòõr   r\   c                   ó    • \ rS rSrS rS rSrg)Ú_VectorFunWrapperi¡  c                 ó   • Xl         SU l        g r   ©r   r   )r   r   s     r   r   Ú_VectorFunWrapper.__init__¢  s   € ØŒØˆ�	r   c                 óv   • U =R                   S-  sl         [        R                  " U R                  U5      5      $ rT   )r   r!   r"   r   r«   s     r   r)   Ú_VectorFunWrapper.__call__¦  s&   € Ø�	Š	�Q‰�	Ü�}Š}˜TŸX™X a›[Ó)Ð)r   r¹   N)r.   r/   r0   r1   r   r)   r3   r4   r   r   r·   r·   ¡  s   † òõ*r   r·   c                   ó2   • \ rS rSrSr   SS jrSS jrSrg)	Ú_VectorJacWrapperi«  ú(
Wrapper class for Jacobian calculation
Nc                 óP   • X l         Xl        X0l        X@l        SU l        SU l        g r   )r   Újacr   Úsparse_jacobianÚnjevr   )r   rÁ   r   r   rÂ   s        r   r   Ú_VectorJacWrapper.__init__¯  s(   € ð ŒØŒØ#6Ô Ø.ÔàˆŒ	àˆ�	r   c                 ó$  • [        U R                  5      (       a'  U R                  U5      nU =R                  S-  sl        OQU R                  [        ;   a=  [	        U R
                  U4SU0U R                  D6u  pEU =R                  US   -  sl        U R                  (       a  [        R                  " W5      $ [        R                  " W5      (       a  UR                  5       $ [        U[        5      (       a  U$ [        R                   " U5      $ )Nr   r   r   )r    rÁ   rÃ   r$   r   r   r   r   rÂ   rA   rC   rB   ÚtoarrayrD   r   r!   rE   )r   r%   r   r&   ÚJr(   s         r   r)   Ú_VectorJacWrapper.__call__¿  sÏ   € ô �D—H‘H×ÑØ—‘˜“ˆAØ�IŠI˜‰NŽIØ�X‰XœÓ#Ü&Ø—‘Øñð ðð ×*Ñ*ñ	‰FˆAð �IŠI˜˜V™Ñ$�Ià××Ü—=’= Ó#Ð#Ü�\Š\˜!�_‰_Ø—9‘9“;ÐÜ˜œ>×*Ñ*ØˆHä—=’= Ó#Ð#r   )r   r   rÁ   r   rÃ   rÂ   r+   r,   r-   r4   r   r   r¾   r¾   «  s   † ñð Ø $Ø ô÷ $r   r¾   c                   óF   • \ rS rSrSr  S
S jrSS jrSS jrS rS r	S	r
g)Ú_VectorHessWrapperiØ  r¿   Nc                 óD   • X l         Xl        X0l        SU l        SU l        g r   )rÁ   r=   r   r>   rÃ   )r   r=   rÁ   r   s       r   r   Ú_VectorHessWrapper.__init__Ü  s"   € ð ŒØŒ	Ø#6Ô ØˆŒ	àˆ�	r   c                 óÌ   • [        U R                  5      (       a&  U =R                  S-  sl        U R                  X5      $ U R                  [        ;   a  U R                  XUS9$ g )Nr   ©ÚJ0)r    r=   r>   Ú_callable_hessr$   rN   )r   r%   ÚvrÏ   r&   s        r   r)   Ú_VectorHessWrapper.__call__é  sU   € ô �D—I‘I×ÑØ�IŠI˜‰N�IØ×&Ñ& qÓ,Ð,Ø�Y‰Yœ*Ó$Ø—=‘= ¨"�=Ð-Ð-ð %r   c                 óÔ   • Uc&  U R                  U5      nU =R                  S-  sl        [        U R                  U4UR                  R                  U5      U4S.U R                  D6nU$ )Nr   )r   r   )rÁ   rÃ   r   Ú	jac_dot_vÚTÚdotr   )r   r%   rÑ   rÏ   r?   s        r   rN   Ú_VectorHessWrapper._fd_hessò  se   € Ø‰:Ø—‘˜!“ˆBØ�IŠI˜‰N�Iô ˜dŸn™n¨að :Ø!#§¡§¡¨!£Ø$% 4ñ:ð !%× 8Ñ 8ñ:ˆð ˆr   c                 ó€   • U =R                   S-  sl         U R                  U5      R                  R                  U5      $ rT   )rÃ   rÁ   rÕ   rÖ   ©r   r%   rÑ   s      r   rÔ   Ú_VectorHessWrapper.jac_dot_vþ  s,   € Ø�	Š	�Q‰�	Ø�x‰x˜‹{�}‰}× Ñ  Ó#Ð#r   c                 ó  • U R                  X5      n[        R                  " U5      (       a  [        R                  " U5      $ [	        U[
        5      (       a  U$ [        R                  " [        R                  " U5      5      $ r,   )	r=   rA   rB   rC   rD   r   r!   rE   rF   )r   r%   rÑ   r?   s       r   rÐ   Ú!_VectorHessWrapper._callable_hess  sT   € Ø�I‰I�a‹Oˆä�<Š<˜�?‰?Ü—=’= Ó#Ð#Ü˜œ>×*Ñ*ØˆHä—=’=¤§¢¨A£Ó/Ð/r   )r   r=   rÁ   r>   rÃ   )NNr,   )r.   r/   r0   r1   r2   r   r)   rN   rÔ   rÐ   r3   r4   r   r   rÊ   rÊ   Ø  s(   † ñð Ø $ô	ô.ô
ò$õ0r   rÊ   c                   óº   • \ rS rSrSrSS\R                  * \R                  4SS4S jr\S 5       r	\S 5       r
\S 5       rS rS	 rS
 rS rS rS rS rS rSrg)ÚVectorFunctioni  aa  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.
Nc
                 ó”
  • [        U5      (       d  U[        ;  a  [        S[         S35      e[        U5      (       d2  U[        ;   d(  [        U[        5      (       d  [        S[         S35      eU[        ;   a  U[        ;   a  [        S5      e[        U5      =U l        n
[        R                  " U
R                  U5      SU
S9nU
R                  nU
R                  UR                  S5      (       a  UR                  nXl        X0l        X@l        U
R!                  X¼5      U l        XÀl        U R"                  R&                  U l        SU l        SU l        SU l        S	U l        S	U l        S	U l        U	=(       d    [6        n	0 nU[        ;   aO  X=S
'   X]S'   Ub  [9        U5      nUU4US'   X}S'   X�S'   SUS'   [:        R<                  " U R"                  5      U l        U[        ;   a2  XMS
'   X]S'   SUS'   [:        R<                  " U R"                  5      U l        U[        ;   a  U[        ;   a  [        S5      e[A        U5      U l!        U RE                  5         [:        RF                  " U RH                  5      U l%        U RJ                  R&                  U l&        [        U5      (       a=  U" [O        U R"                  5      5      U l(        SU l        U =R,                  S-  sl        O^U[        ;   aT  [S        U RB                  U R"                  4SU RH                  0UD6u  U l(        nSU l        U =R*                  US   -  sl        S	U l*        U(       d(  UcR  [V        RX                  " U RP                  5      (       a-  [V        RZ                  " U RP                  5      U l(        SU l*        OŠ[V        RX                  " U RP                  5      (       a   U RP                  R]                  5       U l(        OE[        U RP                  [^        5      (       a  O%[:        R`                  " U RP                  5      U l(        [c        UU RB                  UU RT                  S9U l2        [g        X@Rd                  US9U l4        [        U5      (       d
  U[        ;   ak  U Ri                  [O        U R"                  5      U RJ                  U RP                  S9U l5        SU l        [        U5      (       a  U =R.                  S-  sl        g g [        U[        5      (       aB  X@l5        U Rj                  Rm                  U R(                  S5        SU l        S U l7        S U l8        g g )Nz(`jac` must be either callable or one of r_   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   r`   rc   r   Frd   re   Úsparsityrg   rh   Tri   rj   r   r   )r   r   rÂ   )rÁ   r   rÎ   r=   )9r    r$   rl   rD   r   r	   rb   rm   rn   rF   ro   rp   rq   rs   Ú	_orig_jacru   rw   r%   rx   ry   rz   r‚   Ú_njevÚ_nhevr{   Ú	J_updatedr}   r�   r   r!   r#   Úx_diffr·   Úfun_wrappedrƒ   Ú
zeros_liker    rÑ   Úmr
   rÇ   r   rÂ   rA   rB   rC   rÆ   r   rE   r¾   Újac_wrappedrÊ   Úhess_wrappedr?   r†   r‡   ÚJ_prev)r   r   rG   rÁ   r=   rŠ   Úfinite_diff_jac_sparsityr‹   rÂ   rh   rb   r�   rŽ   r   Úsparsity_groupsr(   s                   r   r   ÚVectorFunction.__init__  sO  € ô ˜�}‰} ¬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Ñ0Ø—X‘XˆFð ŒØŒØŒð —‘˜2Ó&ˆŒØŒà—‘—‘ˆŒØˆŒ
ØˆŒ
ØˆŒ
ØˆŒØˆŒØˆŒð —.œSˆà ÐØ”*ÓØ,/ Ñ)Ø.B 
Ñ+Ø'Ñ3Ü"/Ð0HÓ"I�Ø3KØ3Bð3DÐ# JÑ/à,> Ñ)Ø-4 	Ñ*Ø15Ð Ñ.ÜŸ'š' $§&¡&›/ˆDŒKØ”:ÓØ,0 Ñ)Ø.B 
Ñ+Ø8<ÐÐ 4Ñ5ô
 Ÿ'š' $§&¡&›/ˆDŒKØ”*Ó ¬Ó!3Üð +ó ,ð ,ô
 -¨SÓ1ˆÔØ×ÑÔä—’˜tŸv™vÓ&ˆŒØ—‘—‘ˆŒô �C�=‰=Ùœ §¡›Ó)ˆDŒFØ!ˆDŒNØ�JŠJ˜!‰OŽJØ”JÓÜ+Ø× Ñ  $§&¡&ñØ-1¯V©VðØ7Jñ‰KˆDŒF�Cð "ˆDŒNØ�JŠJ˜#˜f™+Ñ%�Jà$ˆÔÞØÑ'¬C¯LªL¸¿¹×,@Ñ,@ô —]’] 4§6¡6Ó*ˆDŒFØ#'ˆDÕ Ü�\Š\˜$Ÿ&™&×!Ñ!Ø—V‘V—^‘^Ó%ˆD�FÜ˜Ÿ™¤×/Ñ/Øä—]’] 4§6¡6Ó*ˆDŒFä,ØØ× Ñ Ø 3Ø ×0Ñ0ñ	
ˆÔô /Ø×&Ñ&Ð<Oñ
ˆÔô
 �D�>‰>˜T¤ZÓ/Ø×&Ñ&¤w¨t¯v©v£¸¿¹À4Ç6Á6Ð&ÐJˆDŒFØ!ˆDŒNÜ˜�~‰~Ø—
’
˜a‘–
ð ä˜Ô3×4Ñ4ØŒFØ�F‰F×Ñ˜dŸf™f fÔ-Ø!ˆDŒNØˆDŒKØˆD�Kð 5r   c                 óH   • U R                   U R                  R                  -   $ r,   )r‚   ré   r   r‘   s    r   r   ÚVectorFunction.nfev�  s   € à�z‰z˜D×,Ñ,×1Ñ1Ñ1Ð1r   c                 óH   • U R                   U R                  R                  -   $ r,   )râ   rê   rÃ   r‘   s    r   rÃ   ÚVectorFunction.njev¡  s   € à�z‰z˜D×-Ñ-×2Ñ2Ñ2Ð2r   c                 ó   • U R                   $ r,   )rã   r‘   s    r   r>   ÚVectorFunction.nhev¥  s   € à�z‰zÐr   c                 ój   • [         R                  " XR                  5      (       d  Xl        SU l        g g )NF)r!   rª   rÑ   r}   )r   rÑ   s     r   Ú	_update_vÚVectorFunction._update_v©  s&   € Ü�~Š~˜a§¡×(Ñ(ØŒFØ"ˆD�Nð )r   c                 óö  • [         R                  " XR                  5      (       GdS  [        U R                  [
        5      (       a»  U R                  5         U R                  U l        U R                  U l	        [        R                  " U R                  R                  U5      SU R                  S9nU R                  R                  X R                  5      U l        SU l        SU l        SU l        U R'                  5         g [        R                  " U R                  R                  U5      SU R                  S9nU R                  R                  X R                  5      U l        SU l        SU l        SU l        g g r™   )r!   rª   r%   rD   ru   r   Ú_update_jacr‡   rÇ   rë   rm   rn   rb   rF   rw   rx   r{   rä   r}   rš   r›   s      r   rœ   ÚVectorFunction._update_x®  sú   € Ü�~Š~˜a§¡×(Ò(Ü˜$Ÿ/™/Ô+@×AÑAØ× Ñ Ô"Ø"Ÿf™f�”Ø"Ÿf™f�”Ü—^’^ D§G¡G§O¡O°AÓ$6¸QÀ4Ç7Á7ÑK�ØŸ™Ÿ™¨¯L©LÓ9�”Ø!&�”Ø!&�”Ø!&�”Ø×!Ñ!Õ#ä—^’^ D§G¡G§O¡O°AÓ$6¸QÀ4Ç7Á7ÑK�ØŸ™Ÿ™¨¯L©LÓ9�”Ø!&�”Ø!&�”Ø!&�•ð! )r   c                 ó²   • U R                   (       dF  U R                  [        U R                  5      5      U l        U =R
                  S-  sl        SU l         g g rŸ   )r{   ræ   r
   r%   r    r‚   r‘   s    r   rƒ   ÚVectorFunction._update_funÁ  s<   € Ø�~�~Ø×%Ñ%¤g¨d¯f©f£oÓ6ˆDŒFØ�JŠJ˜!‰O�JØ!ˆD�Nð r   c                 ó  • U R                   (       dt  U R                  [        ;   a  U R                  5         OU =R                  S-  sl        U R                  [        U R                  5      U R                  S9U l	        SU l         g g )Nr   rJ   T)
rä   rá   r$   rƒ   râ   ré   r
   r%   r    rÇ   r‘   s    r   rù   ÚVectorFunction._update_jacÇ  s]   € Ø�~�~Ø�~‰~¤Ó+à× Ñ Õ"à—
’
˜a‘•
à×%Ñ%¤g¨d¯f©f£o¸$¿&¹&Ð%ÐAˆDŒFØ!ˆD�Nð r   c                 ó~  • U R                   (       Gd«  [        U R                  5      (       aK  U R                  [	        U R
                  5      U R                  5      U l        U =R                  S-  sl        GO>U R                  [        ;   aN  U R                  5         U R                  [	        U R
                  5      U R                  U R                  S9U l        OÜ[        U R                  [        5      (       a½  U R                  5         U R                  b   U R                  b“  U R
                  U R                  -
  nU R                  R                   R#                  U R                  5      U R                  R                   R#                  U R                  5      -
  nU R                  R%                  X5        SU l         g g )Nr   rÎ   T)r}   r    ru   rê   r
   r%   rÑ   r?   rã   r$   rù   rÇ   rD   r   r‡   rë   rÕ   rÖ   r§   )r   Údelta_xÚdelta_gs      r   rš   ÚVectorFunction._update_hessÒ  s  € Ø�~�~ˆ~Ü˜Ÿ™×(Ñ(Ø×*Ñ*¬7°4·6±6«?¸D¿F¹FÓC�”Ø—
’
˜a‘—
Ø—‘¤JÓ.Ø× Ñ Ô"Ø×*Ñ*¬7°4·6±6«?¸D¿F¹FÀtÇvÁvÐ*ÐN�•Ü˜DŸO™OÔ-B×CÑCØ× Ñ Ô"ð —;‘;Ñ*¨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 'Ô3à!ˆD�Nð! r   c                 ón   • U R                  U5        U R                  5         [        U R                  5      $ r,   )rœ   rƒ   r
   r    r«   s     r   r   ÚVectorFunction.funå  s*   € Ø�‰�qÔØ×ÑÔô �t—v‘v‹Ðr   c                 óð   • U R                  U5        U R                  5         [        U R                  S5      (       a/  U R                  R	                  U R                  R
                  5      $ U R                  $ ©Nrw   )rœ   rù   ÚhasattrrÇ   rw   rq   r«   s     r   rÁ   ÚVectorFunction.jacì  sQ   € Ø�‰�qÔØ×ÑÔÜ�4—6‘6˜8×$Ñ$ð —6‘6—=‘= §¡§¡Ó.Ð.Ø�v‰vˆr   c                 ó  • U R                  U5        U R                  U5        U R                  5         [        U R                  S5      (       a/  U R                  R                  U R                  R                  5      $ U R                  $ r  )rö   rœ   rš   r  r?   rw   rq   rÙ   s      r   r=   ÚVectorFunction.hessõ  s]   € à�‰�qÔØ�‰�qÔØ×ÑÔÜ�4—6‘6˜8×$Ñ$ð —6‘6—=‘= §¡§¡Ó.Ð.Ø�v‰vˆr   )r?   r}   rÇ   rë   rä   r‚   rã   râ   rs   ru   rá   r    r{   ræ   rê   ré   rè   rz   rÂ   rÑ   r%   rå   rx   r‡   rb   )r.   r/   r0   r1   r2   r!   r   r   rµ   r   rÃ   r>   rö   rœ   rƒ   rù   rš   r   rÁ   r=   r3   r4   r   r   rÞ   rÞ     s�   † ñð" '+ÀTØ&(§f¡f W¨b¯f©fÐ$5ÀtØô}ð~ ñ2ó ð2ð ñ3ó ð3ð ñó ðò#ò
'ò&"ò	"ò"ò&òõ	r   rÞ   c                   ó6   • \ rS rSrSrS rS rS rS rS r	Sr
g	)
ÚLinearVectorFunctioni  zì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                 óâ  • U(       d  Uc>  [         R                  " U5      (       a#  [         R                  " U5      U l        SU l        On[         R                  " U5      (       a  UR                  5       U l        SU l        O6[        R                  " [        R                  " U5      5      U l        SU l        U R                  R                  u  U l
        U l        [        U5      =U l        n[        R                  " UR                  U5      SUS9nUR                   nUR#                  UR$                  S5      (       a  UR$                  nUR'                  XV5      U l        X`l        U R                  R-                  U R(                  5      U l        SU l        [        R2                  " U R                  [4        S9U l        [         R                  " U R                  U R                  45      U l        g )NTFr   r`   rc   )rq   )rA   rB   rC   rÇ   rÂ   rÆ   r!   rE   rF   Úshaperè   rz   r	   rb   rm   rn   ro   rp   rq   rw   r%   rx   rÖ   r    r{   ÚzerosÚfloatrÑ   r?   )r   ÚArG   rÂ   rb   r�   rŽ   s          r   r   ÚLinearVectorFunction.__init__  sB  € Þ˜oÑ5¼#¿,º,Àq¿/¹/Ü—]’] 1Ó%ˆ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Ñ0Ø—X‘XˆFð —‘˜2Ó&ˆŒØŒà—‘—‘˜DŸF™FÓ#ˆŒØˆŒä—’˜$Ÿ&™&¬Ñ.ˆŒÜ—’ §¡¨¯©Ð/Ó0ˆ�r   c                 ó$  • [         R                  " XR                  5      (       dk  [        R                  " U R
                  R                  U5      SU R
                  S9nU R
                  R                  X R                  5      U l        SU l	        g g r™   )
r!   rª   r%   rm   rn   rb   rF   rw   rx   r{   r›   s      r   rœ   ÚLinearVectorFunction._update_x&  s\   € Ü�~Š~˜a§¡×(Ñ(Ü—’ §¡§¡°Ó 2¸¸t¿w¹wÑGˆBØ—W‘W—^‘^ B¯©Ó5ˆDŒFØ"ˆD�Nð )r   c                 ó¬   • U R                  U5        U R                  (       d'  U R                  R                  U5      U l        SU l        U R                  $ )NT)rœ   r{   rÇ   rÖ   r    r«   s     r   r   ÚLinearVectorFunction.fun,  s8   € Ø�‰�qÔØ�~�~Ø—V‘V—Z‘Z “]ˆDŒFØ!ˆDŒNØ�v‰vˆr   c                 ó<   • U R                  U5        U R                  $ r,   )rœ   rÇ   r«   s     r   rÁ   ÚLinearVectorFunction.jac3  s   € Ø�‰�qÔØ�v‰vˆr   c                 óH   • U R                  U5        X l        U R                  $ r,   )rœ   rÑ   r?   rÙ   s      r   r=   ÚLinearVectorFunction.hess7  s   € Ø�‰�qÔØŒØ�v‰vˆr   )r?   rÇ   r    r{   rè   rz   rÂ   rÑ   r%   rx   rb   N)r.   r/   r0   r1   r2   r   rœ   r   rÁ   r=   r3   r4   r   r   r  r    s    † ñò1ò<#òòõr   r  c                   ó,   ^ • \ rS rSrSrU 4S jrSrU =r$ )ÚIdentityVectorFunctioni=  zî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                 ó°   >• [        U5      nU(       d  Uc  [        R                  " USS9nSnO[        R                  " U5      nSn[
        TU ]  XAU5        g )NÚcsr)ÚformatTF)ÚlenrA   Ú	eye_arrayr!   ÚeyeÚsuperr   )r   rG   rÂ   rz   r  Ú	__class__s        €r   r   ÚIdentityVectorFunction.__init__D  sJ   ø€ Ü�‹GˆÞ˜oÑ5Ü—’˜a¨Ñ.ˆAØ"‰Oä—’�q“	ˆAØ#ˆOÜ‰Ñ˜ Õ0r   r4   )r.   r/   r0   r1   r2   r   r3   Ú__classcell__)r$  s   @r   r  r  =  s   ø† ñ÷1ó 1r   r  ) Úcollectionsr   Únumpyr!   Úscipy.sparseÚsparserA   Ú_numdiffr   r   Ú_hessian_update_strategyr   Úscipy.sparse.linalgr   Úscipy._lib._array_apir	   r
   Ú
scipy._libr   rm   Úscipy._lib._utilr   r$   r   r6   r\   r·   r¾   rÊ   rÞ   r  r  r4   r   r   Ú<module>r1     s‘   ðÝ "ã Ý ß 6Ý ;Ý .ß :Ý -Ý 3ð *€
÷"ñ "÷JIñ I÷V^ñ ^÷B	*ñ *÷*$ñ *$÷Z20ñ 20÷jqñ q÷h9ñ 9ôx1Ð1õ 1r   