
    ^MhZa                         d dl Zd dlmZ ddlmZmZ ddlm	Z	 d dl
mZ d dlmZ d dlmZ dZdd
ZddZddZ G d d          Z G d d          Z G d d          Z G d de          ZdS )    N   )approx_derivativegroup_columns)HessianUpdateStrategy)LinearOperator)array_namespace)array_api_extra)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      h/var/www/html/test/jupyter/venv/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;    SF        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    1IIINIII=bgajj!84!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    1IIINIII$Q !4  r   N)callable
FD_METHODS)r$   r   r   r(   r   r)   r   s   ````  @r   _wrapper_gradr-   #   s    SF~~  	: 	: 	: 	: 	: 	: 	: 				 	 	 	 	 	 	 	  
	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			~dd271::&=&=&=&=>>>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>.wrappedD   s8    q			Q			tBGAJJ.....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>.wrappedI   sL    q			Q			}RZRWQZZ0G$0G0G0G%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>.wrapped1S   s/    $a "5  r   r*   )r+   r   r   r0   issparser1   
isinstancer   r6   r   r,   )	r3   r$   x0r   r(   Hr   r)   r   s	   `` ``   @r   _wrapper_hessr=   7   sW   ~~  &D$t$$$<?? 	-? ? ? ? ? ? ? q!!AA>** 
	-/ / / / / / / /
J J J J J J J bjmm,,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	                 h   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          j        |		                    |          d|	          }
|	j
        }|	                    |
j        d          r|
j        }t          ||          \  | _        | _        || _        || _        || _        || _        |	                    |
|          | _        || _        | j        j        | _        d	| _        d	| _        d	| _        d | _        t:          j        | _        i }|t          v r||d
<   ||d<   ||d<   ||d<   |t          v r||d
<   ||d<   ||d<   d|d<   |                                   tC          || j        ||          \  | _"        | _#        | $                                 t          |          r.tK          |||          \  | _&        | _'        | _(        d| _        d S |t          v rntK          || 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 zWhenever the gradient is estimated via finite-differences, we require the Hessian to be estimated using one of the quasi-Newton strategies.r   ndimxpreal floating)r   Fmethodrel_stepabs_stepboundsTas_linear_operator)r   r   r(   )r;   r   )r$   r;   r(   r&   r3   r   )-r+   r,   r   r:   r   r   rD   xpx
atleast_ndr   float64isdtypedtyper   _wrapped_fun_nfev	_orig_fun
_orig_grad
_orig_hess_argsastyper   x_dtypesizen	f_updated	g_updated	H_updated	_lowest_xr   inf	_lowest_f_update_funr-   _wrapped_grad_ngev_update_gradr=   _wrapped_hess_nhevr<   g
initializex_prevg_prev)selfr   r;   r   r$   r3   finite_diff_rel_stepfinite_diff_boundsepsilonrD   _x_dtyper(   s                r   __init__zScalarFunction.__init__   s   ~~ 	$j"8"8IJIII    	$*"4"4d$9:: #5,(, , ,  
 :$*"4"4 8 9 9 9
 'r***"^BJJrNNr:::::bh00 	XF )5St(D(D(D%4:
 2v&& :,0).B
+.5
+,>):,0).B
+.5
+8< 45 	 *7! 3	*
 *
 *
&DJ 	 D>> 	5B$6 6 62D
DF "DNNNZ5B'$7	6 6 62D
DF ''46'::DF!DNNN344 	DFFdff---!DNDKDKDJJJ	 	r   c                     | j         d         S Nr   )rR   rk   s    r   nfevzScalarFunction.nfev      z!}r   c                     | j         d         S rs   )rc   rt   s    r   ngevzScalarFunction.ngev  rv   r   c                     | j         d         S rs   )rf   rt   s    r   nhevzScalarFunction.nhev
  rv   r   c                 v   t          | j        t                    r|                                  | j        | _        | j        | _        t          j	        | j
                            |          d| j
                  }| j
                            || j                  | _        d| _        d| _        d| _        |                                  d S t          j	        | j
                            |          d| j
                  }| j
                            || j                  | _        d| _        d| _        d| _        d S Nr   rB   F)r:   rU   r   rd   r   ri   rg   rj   rL   rM   rD   r   rW   rX   r[   r\   r]   _update_hessrk   r   ro   s      r   	_update_xzScalarFunction._update_x  s   do'<== 	#&DK&DK  2 2twGGGBW^^B55DF"DN"DN"DN  2 2twGGGBW^^B55DF"DN"DN"DNNNr   c                     | j         sH|                     | j                  }|| j        k     r| j        | _        || _        || _        d| _         d S d S NT)r[   rQ   r   r`   r^   f)rk   r   s     r   ra   zScalarFunction._update_fun%  sZ    ~ 	"""46**BDN""!%!#DF!DNNN	" 	"r   c                     | j         sQ| j        t          v r|                                  |                     | j        | j                  | _        d| _         d S d S NrK   T)r\   rT   r,   ra   rb   r   r   rg   rt   s    r   rd   zScalarFunction._update_grad/  s^    ~ 	"*,,  """''46'::DF!DNNN		" 	"r   c                    | j         s| j        t          v r;|                                  |                     | j        | j                  | _        nt          | j        t                    rJ|                                  | j        
                    | j        | j        z
  | j        | j        z
             n|                     | j                  | _        d| _         d S d S r   )r]   rU   r,   rd   re   r   rg   r<   r:   r   updateri   rj   rt   s    r   r}   zScalarFunction._update_hess6  s    ~ 
	"*,,!!###++DFtv+>>DO-BCC 4!!###dft{2DFT[4HIIII++DF33!DNNN
	" 
	"r   c                     t          j        || j                  s|                     |           |                                  | j        S r*   )r   array_equalr   r   ra   r   rk   r   s     r   r   zScalarFunction.funC  sC    ~a(( 	NN1vr   c                     t          j        || j                  s|                     |           |                                  | j        S r*   )r   r   r   r   rd   rg   r   s     r   r$   zScalarFunction.gradI  C    ~a(( 	NN1vr   c                     t          j        || j                  s|                     |           |                                  | j        S r*   )r   r   r   r   r}   r<   r   s     r   r3   zScalarFunction.hessO  r   r   c                     t          j        || j                  s|                     |           |                                  |                                  | j        | j        fS r*   )r   r   r   r   ra   rd   r   rg   r   s     r   fun_and_gradzScalarFunction.fun_and_gradU  s\    ~a(( 	NN1vtv~r   r*   )__name__
__module____qualname____doc__rq   propertyru   rx   rz   r   ra   rd   r}   r   r$   r3   r   r   r   r   r?   r?   [   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	                     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          j        |		                    |          d|	          }
|	j
        }|	                    |
j        d          r|
j        }|	                    |
|           _        | _         j        j         _        d _        d _        d _        d	 _        d	 _        d	 _        i t          v rEd
<   |d<   |t1          |          }||fd<   |d<   t3          j         j                   _        t          v r-d
<   |d<   dd<   t3          j         j                   _        t          v rt          v rt          d           fd fd}| _         |             t3          j         j                   _         j        j         _         t                    r  j                   _!        d _         xj        dz  c_        |s|EtE          j#         j!                  r, fdtE          j$         j!                   _!        d _%        nptE          j#         j!                  r, fd j!        &                                 _!        d	 _%        n+ fdt3          j'         j!                   _!        d	 _%         fd}nt          v rtQ           j        fd j        i _!        d _        |s|FtE          j#         j!                  r- fd}tE          j$         j!                   _!        d _%        nrtE          j#         j!                  r- fd} j!        &                                 _!        d	 _%        n, fd}t3          j'         j!                   _!        d	 _%        | _)        t                    r  j         j                   _*        d _         xj        dz  c_        tE          j#         j*                  r% fdtE          j$         j*                   _*        nWt           j*        tV                    r fdn6 fdt3          j'        t3          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#}| _0        d S )$Nz(`jac` must be either callable or one of rA   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   rB   rE   r   FrF   rG   sparsityrI   TrJ   c                 ^    xj         dz  c_         t          j         |                     S Nr   )ru   r   r"   )r   r   rk   s    r   fun_wrappedz,VectorFunction.__init__.<locals>.fun_wrapped  s*    IINII=Q(((r   c                  2      j                   _        d S r*   )r   r   )r   rk   s   r   
update_funz+VectorFunction.__init__.<locals>.update_fun  s     [((DFFFr   c                 ^    xj         dz  c_         t          j         |                     S r   )njevr0   r1   r   jacrk   s    r   jac_wrappedz,VectorFunction.__init__.<locals>.jac_wrapped  s*    IINII>##a&&111r   c                 ^    xj         dz  c_          |                                           S r   )r   toarrayr   s    r   r   z,VectorFunction.__init__.<locals>.jac_wrapped  s*    IINII3q66>>+++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*    IINII=Q000r   c                  2      j                   _        d S r*   )r   J)r   rk   s   r   
update_jacz+VectorFunction.__init__.<locals>.update_jac  s    $TV,,r   r&   c                                                        t          j        t          j        fdj        i           _        d S r8   )ra   r0   r1   r   r   r   r   r(   r   rk   s   r   r   z+VectorFunction.__init__.<locals>.update_jac  s\    $$&&& ^)+tv A A$& A,?A AB BDFFFr   c                                                        t          j        fdj        i                                 _        d S r8   )ra   r   r   r   r   r   r   s   r   r   z+VectorFunction.__init__.<locals>.update_jac  sW    $$&&&.{DF F Ftv F1DF FFMgii FFFr   c                                                        t          j        t          j        fdj        i           _        d S r8   )ra   r   r6   r   r   r   r   r   s   r   r   z+VectorFunction.__init__.<locals>.update_jac  s\    $$&&&])+tv A A$& A,?A AB BDFFFr   c                 `    xj         dz  c_         t          j         | |                    S r   )rz   r0   r1   r   vr3   rk   s     r   hess_wrappedz-VectorFunction.__init__.<locals>.hess_wrapped  s,    IINII>$$q!**555r   c                 <    xj         dz  c_          | |          S r   )rz   r   s     r   r   z-VectorFunction.__init__.<locals>.hess_wrapped  s"    IINII41::%r   c                     xj         dz  c_         t          j        t          j         | |                              S r   )rz   r   r6   r   r   s     r   r   z-VectorFunction.__init__.<locals>.hess_wrapped  s6    IINII=DDAJJ)?)?@@@r   c                  >      j         j                  _        d S r*   )r   r   r<   )r   rk   s   r   update_hessz,VectorFunction.__init__.<locals>.update_hess  s    %dfdf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   rk   s   r   r   z,VectorFunction.__init__.<locals>.update_hess  sf      """*9df B.2fhll46.B.B15	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   ri   J_prevr   r   r   r   r   r<   r   )delta_xdelta_grk   s     r   r   z,VectorFunction.__init__.<locals>.update_hess!  s      """ ;*t{/F"ft{2G"fhll4622T[]5F5Ftv5N5NNGFMM'733333 +*/F/Fr   c                 d                                     j        _        j        _        t          j        j                            |           dj                  }j        	                    |j
                  _        d_        d_        d_                                         d S r|   )r   r   ri   r   r   rL   rM   rD   r   rW   rX   r[   	J_updatedr]   r}   r   ro   rk   s     r   update_xz)VectorFunction.__init__.<locals>.update_x-  s      """"f"f^DGOOA$6$6Q47KKKDL99!&!&!&!!#####r   c                     t          j        j                            |           dj                  }j                            |j                  _        d_        d_        d_	        d S r|   )
rL   rM   rD   r   rW   rX   r   r[   r   r]   r   s     r   r   z)VectorFunction.__init__.<locals>.update_x8  s[    ^DGOOA$6$6Q47KKKDL99!&!&!&r   )1r+   r,   r   r:   r   r   rD   rL   rM   r   rN   rO   rP   rW   r   rX   rY   rZ   ru   r   rz   r[   r   r]   r   r   r   x_diff_update_fun_impl
zeros_liker   r   mr   r0   r9   r1   sparse_jacobianr   r6   r   _update_jac_implr<   r   rh   ri   r   _update_hess_impl_update_x_impl)rk   r   r;   r   r3   rl   finite_diff_jac_sparsityrm   r   rD   ro   rp   sparsity_groupsr   r   r   r   r(   r   r   r   r   s   `` ``            @@@@@r   rq   zVectorFunction.__init__n  s    }} 	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***"^BJJrNNr:::::bh00 	XF 2v&&			 *,/).B
+'3"/0H"I"I3K3B3D#J/,>)'$&//DK:,0).B
+8< 45'$&//DK*!3!3 + , , ,	) 	) 	) 	) 	) 	)	) 	) 	) 	) 	) 	) !+
tv&& C== <	-S[[DF!DNIINII -#+TV0D0D+2 2 2 2 2 2 //'+$$df%% -, , , , , , ))',$$1 1 1 1 1 1 tv..',$- - - - - - - J&{DF > >tv >)<> >DF!DN -#+TV0D0D+B B B B B B B
 //'+$$df%% -P P P P P P P ))',$$B B B B B B B
 tv..',$ * D>> 2	4T$&$&))DF!DNIINII|DF## ;6 6 6 6 6 6 //DFN33 	;& & & & & & &
A A A A A A rz$&'9'9::6 6 6 6 6 6 6Z/ / / / /B B B B B B B KMMM!DNN344 	4DFFdff---!DNDKDK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]   )rk   r   s     r   	_update_vzVectorFunction._update_vA  s4    ~a(( 	#DF"DNNN	# 	#r   c                 h    t          j        || j                  s|                     |           d S d S r*   )r   r   r   r   r   s     r   r   zVectorFunction._update_xF  s<    ~a(( 	#"""""	# 	#r   c                 N    | j         s|                                  d| _         d S d S r   )r[   r   rt   s    r   ra   zVectorFunction._update_funJ  3    ~ 	"!!###!DNNN	" 	"r   c                 N    | j         s|                                  d| _         d S d S r   )r   r   rt   s    r   r   zVectorFunction._update_jacO  r   r   c                 N    | j         s|                                  d| _         d S d S r   )r]   r   rt   s    r   r}   zVectorFunction._update_hessT  s3    ~ 	"""$$$!DNNN	" 	"r   c                 b    |                      |           |                                  | j        S r*   )r   ra   r   r   s     r   r   zVectorFunction.funY  -    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<   rk   r   r   s      r   r3   zVectorFunction.hessc  s?    qqvr   N)r   r   r   r   rq   r   r   ra   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 )LinearVectorFunctionzLinear 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                 x   |s|5t          j        |          r!t          j        |          | _        d| _        ngt          j        |          r!|                                | _        d| _        n2t          j        t          j        |                    | _        d| _        | j        j	        \  | _
        | _        t          |          x| _        }t          j        |                    |          d|          }|j        }|                    |j        d          r|j        }|                    ||          | _        || _        | j                            | j                  | _        d| _        t          j        | j
        t4                    | _        t          j        | j        | j        f          | _        d S )NTFr   rB   rE   )rP   )r0   r9   r1   r   r   r   r   r6   r   shaper   rZ   r   rD   rL   rM   rN   rO   rP   rW   r   rX   r   r   r[   zerosfloatr   r<   )rk   Ar;   r   rD   ro   rp   s          r   rq   zLinearVectorFunction.__init__r  sb    		)o5#,q//5^A&&DF#'D  \!__ 	)YY[[DF#(D   ]2:a==11DF#(D &r***"^BJJrNNr:::::bh00 	XF 2v&&DF##$&... 011r   c                     t          j        || j                  sbt          j        | j                            |          d| j                  }| j                            || j                  | _        d| _	        d S d S r|   )
r   r   r   rL   rM   rD   r   rW   rX   r[   r~   s      r   r   zLinearVectorFunction._update_x  sl    ~a(( 	# 2 2twGGGBW^^B55DF"DNNN	# 	#r   c                     |                      |           | j        s&| j                            |          | _        d| _        | j        S r   )r   r[   r   r   r   r   s     r   r   zLinearVectorFunction.fun  s?    q~ 	"VZZ]]DF!DN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   rq   r   r   r   r3   r   r   r   r   r   k  si         2 2 2<# # #        r   r   c                   "     e Zd ZdZ fdZ xZS )IdentityVectorFunctionzIdentity 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   superrq   )rk   r;   r   rZ   r   	__class__s        r   rq   zIdentityVectorFunction.__init__  sj    GG 	$o5%(((A"OOq		A#OB00000r   )r   r   r   r   rq   __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   
scipy._libr	   rL   r,   r   r-   r=   r?   r   r   r   r   r   r   <module>r      s             6 6 6 6 6 6 6 6 ; ; ; ; ; ; . . . . . . 1 1 1 1 1 1 - - - - - - *
   ,       (!& !& !& !&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   