+
    /iu                     0   ^ RI Ht ^ RIt^ RIHt ^RIHtH	t	 ^RI
Ht ^ RIHt ^ RIHtHt ^ RIHt ^ RIHt Rt ! R	 R
4      t ! R R4      t ! R R4      t ! R R4      t ! R R4      t ! R R4      t ! R R4      t ! R R4      t ! R R]4      tR# )    )
namedtupleN)approx_derivativegroup_columns)HessianUpdateStrategy)LinearOperator)array_namespacexp_copy)array_api_extra)_ScalarFunctionWrapperc                   8   a  ] tR t^t o RtRR ltRR ltRtV tR# )_ScalarGradWrapperz(
Wrapper class for gradient calculation
Nc                `    W n         Wn        Vf   . MTV n        W@n        ^ V n        ^ V n        R # N)fungradargsfinite_diff_optionsngevnfev)selfr   r   r   r   s   &&&&&f/var/www/html/photoedit/myenv/lib/python3.14/site-packages/scipy/optimize/_differentiable_functions.py__init___ScalarGradWrapper.__init__   s/     	,BD	#6 		    c                   \        V P                  4      '       dH   \        P                  ! V P                  ! \        P                  ! V4      .V P
                  O5!  4      pMZV P                  \        9   dF   \        V P                  V3R V/V P                  B w  rEV ;P                  VR,          ,          un
        V ;P                  ^,          un        X# f0r   )callabler   np
atleast_1dcopyr   
FD_METHODSr   r   r   r   r   )r   xr   kwdsgdcts   &&&,  r   __call___ScalarGradWrapper.__call__#   s     DIIdii
?TYY?@AYY*$&  **	FA IIV$I		Q	r   )r   r   r   r   r   r   NNNr   	__name__
__module____qualname____firstlineno____doc__r   r'   __static_attributes____classdictcell____classdict__s   @r   r   r      s      r   r   c                   T   a  ] tR t^5t o RtR
R ltRR ltRR ltR tR t	R t
R	tV tR# )_ScalarHessWrapperz;
Wrapper class for hess calculation via finite differences
Nc                   Wn         W0n        Vf   . MTV n        WPn        ^ V n        ^ V n        R V n        R V n        \        V4      '       d   V! \        P                  ! V4      .VO5!  V n        V ;P
                  ^,          un        \        P                  ! V P                  4      '       d/   RV n        \        P                  ! V P                  4      V n        R # \        V P                  \        4      '       d
   RV n        R # RV n        \        P                   ! \        P"                  ! V P                  4      4      V n        R # V\$        9   d
   RV n        R # R # )N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     		,BD	#6 		D>>"''"+--DFIINI||DFF##"3tvv.DFFN33"; #3rzz$&&'9:Z"+  r   c                    V P                   ;R 8X  d    V P                  pM<;R8X  d    V P                  pM';R8X  d    V P                  pMR8X  d   V P                  pX! \
        P                  ! V4      VR7      # )r7   r8   r9   r:   r   )r>   _sparse_callable_linearoperator_callable_dense_callable_fd_hessr   r!   )r   r#   r   r$   _hs   &&&, r   r'   _ScalarHessWrapper.__call__[   sT    oo"***22!))]]"''!*$$r   c                    \        V P                  V3R V/V P                  B w  V n        pV ;P                  VR,          ,          un        V P                  # r   )r   r   r   r=   r   )r   r#   r   r$   r&   s   &&&, r   rL   _ScalarHessWrapper._fd_hessh   sN    'IIq

#'#;#;
 			S[ 	vvr   c                    V ;P                   ^,          un         \        P                  ! V P                  ! V.V P                  O5!  4      V n        V P
                  #    )r<   r?   rA   r;   r   r=   r   r#   r$   s   &&,r   rI   #_ScalarHessWrapper._sparse_callableo   s:    		Q	tyy7TYY78vvr   c                    V ;P                   ^,          un         \        P                  ! \        P                  ! V P                  ! V.V P
                  O5!  4      4      V n        V P                  # rR   )r<   r   rC   rD   r;   r   r=   rT   s   &&,r   rK   "_ScalarHessWrapper._dense_callablet   sH    		Q	JJtyy/TYY/0
 vvr   c                    V ;P                   ^,          un         V P                  ! V.V P                  O5!  V n        V P                  # rR   )r<   r;   r   r=   rT   s   &&,r   rJ   +_ScalarHessWrapper._linearoperator_callable{   s1    		Q	1)tyy)vvr   )r=   r>   r   r   r   r;   r   r<   )NNNNr   )r+   r,   r-   r.   r/   r   r'   rL   rI   rK   rJ   r0   r1   r2   s   @r   r5   r5   5   s.      ,D%
 r   r5   c                      a  ] tR t^t o RtR]P                  ) ]P                  3RR3R lt]R 4       t	]R 4       t
]R 4       tR tR tR	 tR
 tR tR tR tR tRtV tR# )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.
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
                   \        V4      '       g   V\        9  d   \        R \         R24      h\        V4      '       g5   V\        9   g*   \        V\        4      '       g   \        R\         R24      hV\        9   d   V\        9   d   \        R4      h\        V4      ;V n        p
\        P                  ! V
P                  V4      ^V
R7      pV
P                  pV
P                  VP                  R4      '       d   VP                  p\        W4      V n        Wn        W@n        WPn        W0n        V
P'                  W4      V n        Wn        V P(                  P,                  V n        RV n        RV n        RV n        RV n        \8        P:                  V n        T	;'       g    \>        p	/ pV\        9   d   WMR&   WmR	&   WR
&   W}R&   WR&   RVR&   V\        9   d   W]R&   WmR	&   WR
&   RVR&   WR&   RVR&   ^ V n         V PC                  4        \E        VV P                  VVR7      V n#        V PI                  4        \        V\        4      '       da   WPn%        V PJ                  PM                  V P.                  R4       RV n        RV n'        RV n(        \S        RRR.4      pV! ^ ^ R7      V n*        R# \        V4      '       d9   \W        VVVVR7      V n*        V PT                  PJ                  V n%        RV n        R# V\        9   de   \W        VVVV PF                  VR7      V n*        V PI                  4        V PU                  V P(                  V PX                  R7      V n%        RV n        R# R# )z)`grad` must be either callable or one of .z@`hess` must be either callable, HessianUpdateStrategy or one of zWhenever the gradient is estimated via finite-differences, we require the Hessian to be estimated using one of the quasi-Newton strategies.ndimxpreal floatingFNmethodrel_stepabs_stepboundsworkersTfull_outputas_linear_operator)r   r   r   r;   _FakeCounterr   r<   )r   r<   )rE   r   r   )rE   r   r   r   rH   )-r   r"   
ValueErrorrB   r   r   r`   xpx
atleast_ndrD   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_hessr5   r%   )r   r   rE   r   r   r;   finite_diff_rel_stepfinite_diff_boundsepsilonrf   r`   _x_dtyper   ri   s   &&&&&&&&&&     r   r   ScalarFunction.__init__   s&    ~~$j"8;J<qI  $*"4d$9::(\, 
 :$*"4 8 9 9 'r**"^^BJJrNr:::bhh00XXF 33=
 2& ..S :,0).B
+.5
+,>)-4	*15.:,0).B
+.5
+8< 45-4	*15. 
 0!! 3	
 	 d122FFFdfff-!DNDKDK%nvv6FGL!-11!=D~~%7(;	&" ++--!%#%7++(;&" !!#++DFFtvv+>!% $r   c                P    V P                   V P                  P                  ,           # r   )r   r   r   r   s   &r   r   ScalarFunction.nfevE  s    zzD..3333r   c                .    V P                   P                  # r   )r   r   r   s   &r   r   ScalarFunction.ngevI      !!&&&r   c                .    V P                   P                  # r   )r   r<   r   s   &r   r<   ScalarFunction.nhevM  r   r   c                   \        V P                  \        4      '       d   V P                  4        V P                  V n        V P                  V n        \        P                  ! V P                  P                  V4      ^V P                  R7      pV P                  P                  W P                  4      V n        RV n        RV n        RV n        V P#                  4        R# \        P                  ! V P                  P                  V4      ^V P                  R7      pV P                  P                  W P                  4      V n        RV n        RV n        RV n        R# rS   r^   FN)rB   rs   r   r   r#   r   r%   r   rk   rl   r`   rD   ru   rv   ry   rz   r{   _update_hessr   r#   r   s   && r   	_update_xScalarFunction._update_xQ  s    doo'<==&&DK&&DK  2twwGBWW^^B5DF"DN"DN"DN  2twwGBWW^^B5DF"DN"DN"DNr   c                    V P                   '       gk   V P                  V P                  4      pV ;P                  ^,          un        WP                  8  d   V P                  V n        Wn        Wn        RV n         R# R# rS   TN)ry   rp   r#   r   r~   r|   f)r   fxs   & r   r   ScalarFunction._update_funh  sW    ~~~""466*BJJ!OJNN"!%!#F!DN r   c                    V P                   '       g[   V P                  \        9   d   V P                  4        V P	                  V P
                  V P                  R 7      V n        RV n         R# R# rH   TN)rz   rr   r"   r   r   r#   r   r%   r   s   &r   r   ScalarFunction._update_grads  sN    ~~~*,  "''466':DF!DN	 r   c                &   V P                   '       g   V P                  \        9   d>   V P                  4        V P	                  V P
                  V P                  R 7      V n        M\        V P                  \        4      '       dd   V P                  4        V P                  P                  V P
                  V P                  ,
          V P                  V P                  ,
          4       M V P	                  V P
                  4      V n        RV n         R# R# r   )r{   rs   r"   r   r   r#   r%   r=   rB   r   updater   r   r   s   &r   r   ScalarFunction._update_hessz  s    ~~~*,!!#++DFFtvv+>DOO-BCC!!#dfft{{2DFFT[[4HI++DFF3!DN r   c                    \         P                  ! WP                  4      '       g   V P                  V4       V P	                  4        V P
                  # r   )r   array_equalr#   r   r   r   r   r#   s   &&r   r   ScalarFunction.fun  s6    ~~a((NN1vvr   c                    \         P                  ! WP                  4      '       g   V P                  V4       V P	                  4        V P
                  # r   )r   r   r#   r   r   r%   r   s   &&r   r   ScalarFunction.grad  6    ~~a((NN1vvr   c                    \         P                  ! WP                  4      '       g   V P                  V4       V P	                  4        V P
                  # r   )r   r   r#   r   r   r=   r   s   &&r   r;   ScalarFunction.hess  r   r   c                    \         P                  ! WP                  4      '       g   V P                  V4       V P	                  4        V P                  4        V P                  V P                  3# r   )r   r   r#   r   r   r   r   r%   r   s   &&r   fun_and_gradScalarFunction.fun_and_grad  sK    ~~a((NN1vvtvv~r   )r=   r{   rt   r~   r|   r   rq   rr   rs   rp   r   r   r   ry   r%   r   rz   rx   r#   rv   r   r`   )r+   r,   r-   r.   r/   r   r}   r   propertyr   r   r<   r   r   r   r   r   r   r;   r   r0   r1   r2   s   @r   r[   r[      s     Xr HL&(ffWbff$5tTi&V 4 4 ' ' ' '#.	""" r   r[   c                   ,   a  ] tR tRt o R tR tRtV tR# )_VectorFunWrapperi  c                     Wn         ^ V n        R# r   Nr   r   )r   r   s   &&r   r   _VectorFunWrapper.__init__  s    	r   c                ~    V ;P                   ^,          un         \        P                  ! V P                  V4      4      # rR   )r   r   r    r   r   s   &&r   r'   _VectorFunWrapper.__call__  s&    		Q	}}TXXa[))r   r   N)r+   r,   r-   r.   r   r'   r0   r1   r2   s   @r   r   r     s     * *r   r   c                   8   a  ] tR tRt o RtRR ltRR ltRtV tR# )	_VectorJacWrapperi  (
Wrapper class for Jacobian calculation
Nc                R    W n         Wn        W0n        W@n        ^ V n        ^ V n        R# r   )r   jacr   sparse_jacobiannjevr   )r   r   r   r   r   s   &&&&&r   r   _VectorJacWrapper.__init__  s(     #6 .		r   c                F   \        V P                  4      '       d,   V P                  V4      pV ;P                  ^,          un        MZV P                  \        9   dF   \	        V P
                  V3RV/V P                  B w  rEV ;P                  VR,          ,          un        V P                  '       d   \        P                  ! X4      # \        P                  ! X4      '       d   VP                  4       # \        V\        4      '       d   V# \        P                   ! V4      # )rS   r   r   )r   r   r   r"   r   r   r   r   r   r?   rA   r@   toarrayrB   r   r   rC   )r   r#   r   r$   Jr&   s   &&&,  r   r'   _VectorJacWrapper.__call__  s     DHHAIINIXX#&  **	FA IIV$I==##\\!__99;>**H==##r   )r   r   r   r   r   r   r)   r   r*   r2   s   @r   r   r     s      $ $r   r   c                   N   a  ] tR tRt o RtR
R ltRR ltRR ltR tR t	R	t
V tR# )_VectorHessWrapperi  r   Nc                F    W n         Wn        W0n        ^ V n        ^ V n        R# r   )r   r;   r   r<   r   )r   r;   r   r   s   &&&&r   r   _VectorHessWrapper.__init__  s"     	#6 		r   c                    \        V P                  4      '       d+   V ;P                  ^,          un        V P                  W4      # V P                  \        9   d   V P                  WVR7      # R# )rS   J0N)r   r;   r<   _callable_hessr"   rL   )r   r#   vr   r$   s   &&&&,r   r'   _VectorHessWrapper.__call__  sU     DIIIINI&&q,,YY*$=="=-- %r   c                    Vf+   V P                  V4      pV ;P                  ^,          un        \        V P                  V3RVP                  P                  V4      RV3/V P                  B pV# )Nr   r   )r   r   r   	jac_dot_vTdotr   )r   r#   r   r   r=   s   &&&& r   rL   _VectorHessWrapper._fd_hess  sj    :!BIINI dnna :!#!:$%4: !% 8 8: r   c                    V ;P                   ^,          un         V P                  V4      P                  P                  V4      # rR   )r   r   r   r   r   r#   r   s   &&&r   r   _VectorHessWrapper.jac_dot_v  s,    		Q	xx{}}  ##r   c                   V P                  W4      p\        P                  ! V4      '       d   \        P                  ! V4      # \	        V\
        4      '       d   V# \        P                  ! \        P                  ! V4      4      # r   )	r;   r?   r@   rA   rB   r   r   rC   rD   )r   r#   r   r=   s   &&& r   r   !_VectorHessWrapper._callable_hess  sT    IIaO<<??==##>**H==A//r   )r   r;   r   r<   r   )NNr   )r+   r,   r-   r.   r/   r   r'   rL   r   r   r0   r1   r2   s   @r   r   r     s(     .
$0 0r   r   c                      a  ] tR tRt o RtRR]P                  ) ]P                  3RR3R lt]R 4       t	]R 4       t
]R 4       tR tR	 tR
 tR tR tR tR tR tRtV tR# )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
                   \        V4      '       g   V\        9  d   \        R \         R24      h\        V4      '       g5   V\        9   g*   \        V\        4      '       g   \        R\         R24      hV\        9   d   V\        9   d   \        R4      h\        V4      ;V n        p
\        P                  ! V
P                  V4      ^V
R7      pV
P                  pV
P                  VP                  R4      '       d   VP                  pWn        W0n        W@n        V
P!                  W4      V n        Wn        V P"                  P&                  V n        ^ V n        ^ V n        ^ V n        RV n        RV n        RV n        T	;'       g    \6        p	/ pV\        9   dQ   W=R&   W]R&   Ve   \9        V4      pVV3VR
&   W}R&   WR&   RVR&   \:        P<                  ! V P"                  4      V n        V\        9   d3   WMR&   W]R&   RVR&   \:        P<                  ! V P"                  4      V n        V\        9   d   V\        9   d   \        R4      h\A        V4      V n!        V PE                  4        \:        PF                  ! V PH                  4      V n%        V PJ                  P&                  V n&        \        V4      '       dB   V! \O        V P"                  4      4      V n(        RV n        V ;P,                  ^,          un        MgV\        9   d]   \S        V PB                  V P"                  3RV PH                  /VB w  V n(        pRV n        V ;P*                  VR,          ,          un        RV n*        V'       g+   VfT   \V        PX                  ! V PP                  4      '       d.   \V        PZ                  ! V PP                  4      V n(        RV n*        M\V        PX                  ! V PP                  4      '       d!   V PP                  P]                  4       V n(        MF\        V PP                  \^        4      '       d   M%\:        P`                  ! V PP                  4      V n(        \c        VV PB                  VV PT                  R7      V n2        \g        W@Pd                  VR7      V n4        \        V4      '       g   V\        9   dv   V Pi                  \O        V P"                  4      V PJ                  V PP                  R7      V n5        RV n        \        V4      '       d   V ;P.                  ^,          un        R	# R	# \        V\        4      '       dD   W@n5        V Pj                  Pm                  V P(                  R4       RV n        R	V n7        R	V n8        R	# R	# )z(`jac` must be either callable or one of r]   z?`hess` must be either callable,HessianUpdateStrategy or one of zWhenever the Jacobian is estimated via finite-differences, we require the Hessian to be estimated using one of the quasi-Newton strategies.r^   ra   Frb   rc   Nsparsityre   rf   Trg   rh   r   r   )r   r   r   )r   r   r   r;   )9r   r"   rj   rB   r   r   r`   rk   rl   rD   rm   rn   ro   rq   	_orig_jacrs   ru   r#   rv   rw   rx   r   _njev_nhevry   	J_updatedr{   r   r   r   r!   x_diffr   fun_wrappedr   
zeros_liker   r   mr	   r   r   r   r?   r@   rA   r   r   rC   r   jac_wrappedr   hess_wrappedr=   r   r   J_prev)r   r   rE   r   r;   r   finite_diff_jac_sparsityr   r   rf   r`   r   r   r   sparsity_groupsr&   s   &&&&&&&&&&      r   r   VectorFunction.__init__  sQ    }}J!6G
|STUVV$*"4d$9:: @@J|1N O O *!3 + , ,
 'r**"^^BJJrNr:::bhh00XXF  2&


 ..S *,/).B
+'3"/0H"I3K3B3D#J/,>)-4	*15.''$&&/DK:,0).B
+8< 45
 ''$&&/DK*!3 + , ,
 -S1tvv& C==)DF!DNJJ!OJJ+  $&&-1VV7JKDFC "DNJJ#f+%J$'CLL,@,@ ]]466*DF#'D \\$&&!!VV^^%DF//]]466*DF,   3 00	
 /&&<O

 D>>TZ/&&wtvv466&JDF!DN~~

a
 344FFFdfff-!DNDKDK 5r   c                P    V P                   V P                  P                  ,           # r   )r   r   r   r   s   &r   r   VectorFunction.nfev  s    zzD,,1111r   c                P    V P                   V P                  P                  ,           # r   )r   r   r   r   s   &r   r   VectorFunction.njev  s    zzD--2222r   c                    V P                   # r   )r   r   s   &r   r<   VectorFunction.nhev  s    zzr   c                p    \         P                  ! WP                  4      '       g   Wn        R V n        R# R# )FN)r   r   r   r{   )r   r   s   &&r   	_update_vVectorFunction._update_v  s&    ~~a((F"DN )r   c                   \         P                  ! WP                  4      '       Eg]   \        V P                  \
        4      '       d   V P                  4        V P                  V n        V P                  V n	        \        P                  ! V P                  P                  V4      ^V P                  R7      pV P                  P                  W P                  4      V n        RV n        RV n        RV n        V P'                  4        R# \        P                  ! V P                  P                  V4      ^V P                  R7      pV P                  P                  W P                  4      V n        RV n        RV n        RV n        R# R# r   )r   r   r#   rB   rs   r   _update_jacr   r   r   rk   rl   r`   rD   ru   rv   ry   r   r{   r   r   s   && r   r   VectorFunction._update_x  s    ~~a(($//+@AA  ""ff"ff^^DGGOOA$6Q477KLL9!&!&!&!!#^^DGGOOA$6Q477KLL9!&!&!&! )r   c                    V P                   '       gL   V P                  \        V P                  4      4      V n        V ;P
                  ^,          un        RV n         R# R# r   )ry   r   r	   r#   r   r   r   s   &r   r   VectorFunction._update_fun  s>    ~~~%%gdffo6DFJJ!OJ!DN r   c                $   V P                   '       g~   V P                  \        9   d   V P                  4        MV ;P                  ^,          un        V P                  \        V P                  4      V P                  R7      V n	        RV n         R# R# )rS   rH   TN)
r   r   r"   r   r   r   r	   r#   r   r   r   s   &r   r   VectorFunction._update_jac  s_    ~~~~~+  "

a
%%gdffo$&&%ADF!DN r   c                   V P                   '       Eg   \        V P                  4      '       dP   V P                  \	        V P
                  4      V P                  4      V n        V ;P                  ^,          un        EMMV P                  \        9   dR   V P                  4        V P                  \	        V P
                  4      V P                  V P                  R7      V n        M\        V P                  \        4      '       d   V P                  4        V P                  e   V P                  e   V P
                  V P                  ,
          pV P                  P                   P#                  V P                  4      V P                  P                   P#                  V P                  4      ,
          pV P                  P%                  W4       RV n         R# R# )rS   r   NT)r{   r   rs   r   r	   r#   r   r=   r   r"   r   r   rB   r   r   r   r   r   r   )r   delta_xdelta_gs   &  r   r   VectorFunction._update_hess  s   ~~~((**7466?DFFC

a
J.  "**7466?DFFtvv*NDOO-BCC  " ;;*t{{/F"fft{{2G"ffhhll4662T[[]]5F5Ftvv5NNGFFMM'3!DN! r   c                n    V P                  V4       V P                  4        \        V P                  4      # r   )r   r   r	   r   r   s   &&r   r   VectorFunction.fun  s*    q tvvr   c                    V P                  V4       V P                  4        \        V P                  R 4      '       d0   V P                  P	                  V P                  P
                  4      # V P                  # ru   )r   r   hasattrr   ru   ro   r   s   &&r   r   VectorFunction.jac  sQ    q4668$$ 66==..vvr   c                   V P                  V4       V P                  V4       V P                  4        \        V P                  R 4      '       d0   V P                  P                  V P                  P                  4      # V P                  # r  )r   r   r   r  r=   ru   ro   r   s   &&&r   r;   VectorFunction.hess  s]    qq4668$$ 66==..vvr   )r=   r{   r   r   r   r   r   r   rq   rs   r   r   ry   r   r   r   r   rx   r   r   r#   r   rv   r   r`   )r+   r,   r-   r.   r/   r   r}   r   r   r   r   r<   r   r   r   r   r   r   r   r;   r0   r1   r2   s   @r   r   r     s     " '+T&(ffWbff$5t}~ 2 2 3 3  #
'&"	""&	 	r   r   c                   B   a  ] tR tRt o RtR tR tR tR tR t	Rt
V tR	# )
LinearVectorFunctioni  zLinear 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                   V'       g!   Vf@   \         P                  ! V4      '       d$   \         P                  ! V4      V n        RV n        Mo\         P                  ! V4      '       d   VP                  4       V n        RV n        M6\        P                  ! \        P                  ! V4      4      V n        RV n        V P                  P                  w  V n
        V n        \        V4      ;V n        p\        P                  ! VP                  V4      ^VR7      pVP                   pVP#                  VP$                  R4      '       d   VP$                  pVP'                  WV4      V n        W`n        V P                  P-                  V P(                  4      V n        RV n        \        P2                  ! V P                  \4        R7      V n        \         P                  ! V P                  V P                  34      V n        R # )NTFr^   ra   )ro   )r?   r@   rA   r   r   r   r   rC   rD   shaper   rx   r   r`   rk   rl   rm   rn   ro   ru   r#   rv   r   r   ry   zerosfloatr   r=   )r   ArE   r   r`   r   r   s   &&&&   r   r   LinearVectorFunction.__init__  sB   o5#,,q//]]1%DF#'D \\!__YY[DF#(D  ]]2::a=1DF#(D &r**"^^BJJrNr:::bhh00XXF 2&DFF#$&&./0r   c                0   \         P                  ! WP                  4      '       gp   \        P                  ! V P
                  P                  V4      ^V P
                  R7      pV P
                  P                  W P                  4      V n        RV n	        R# R# r   )
r   r   r#   rk   rl   r`   rD   ru   rv   ry   r   s   && r   r   LinearVectorFunction._update_x&  s\    ~~a(( 2twwGBWW^^B5DF"DN )r   c                    V P                  V4       V P                  '       g(   V P                  P                  V4      V n        R V n        V P                  # )T)r   ry   r   r   r   r   s   &&r   r   LinearVectorFunction.fun,  s:    q~~~VVZZ]DF!DNvvr   c                <    V P                  V4       V P                  # r   )r   r   r   s   &&r   r   LinearVectorFunction.jac3  s    qvvr   c                H    V P                  V4       W n        V P                  # r   )r   r   r=   r   s   &&&r   r;   LinearVectorFunction.hess7  s    qvvr   )r=   r   r   ry   r   rx   r   r   r#   rv   r`   N)r+   r,   r-   r.   r/   r   r   r   r   r;   r0   r1   r2   s   @r   r  r    s(     1<# r   r  c                   6   a a ] tR tRt oRtV 3R ltRtVtV ;t# )IdentityVectorFunctioni=  zIdentity 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                   < \        V4      pV'       g   Vf   \        P                  ! VRR7      pRpM\        P                  ! V4      pRp\
        SV `  WAV4       R # )Ncsr)formatTF)lenr?   	eye_arrayr   eyesuperr   )r   rE   r   rx   r  	__class__s   &&&  r   r   IdentityVectorFunction.__init__D  sJ    Go5a.A"Oq	A#O0r    )	r+   r,   r-   r.   r/   r   r0   r1   __classcell__)r#  r3   s   @@r   r  r  =  s     1 1r   r  )z2-pointz3-pointcs) collectionsr   numpyr   scipy.sparsesparser?   _numdiffr   r   _hessian_update_strategyr   scipy.sparse.linalgr   scipy._lib._array_apir   r	   
scipy._libr
   rk   scipy._lib._utilr   r"   r   r5   r[   r   r   r   r   r  r  r%  r   r   <module>r2     s    "   6 ; . : - 3 *
" "JI IV^ ^B	* **$ *$Z20 20jq qh9 9x11 1r   