§
    fŠtjñ‹  ã                   óL  — d Z ddlZddlZddlmZ ddlmZ ddlm	Z	m
Z
mZmZmZ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„ Zej        d„ ¦   «         Zd„ Zd„ Zdd„Zddddej         ej        fddddddfd„Z d„ Z!d„ Z"d„ Z# G d„ d¦  «        Z$ej         ej        fddfd„Z%dS )z'Routines for numerical differentiation.é    N)Únorm)ÚLinearOperatoré   )ÚissparseÚ
isspmatrixÚfindÚ	csc_arrayÚ	csr_arrayÚ
csr_matrixé   )Úgroup_denseÚgroup_sparse)Úarray_namespace)Ú
MapWrapper)Úarray_api_extrac                 ó2  — |dk    rt          j        |t          ¬¦  «        }nE|dk    r0t          j        |¦  «        }t          j        |t          ¬¦  «        }nt          d¦  «        ‚t          j        |t           j         k    |t           j        k    z  ¦  «        r||fS ||z  }|                     ¦   «         }| |z
  }	|| z
  }
|dk    r‚| |z   }||k     ||k    z  }t          j        |¦  «        t          j	        |	|
¦  «        k    }|||z  xx         dz  cc<   |
|	k    | z  }|
|         |z  ||<   |
|	k     | z  }|	|          |z  ||<   nÊ|dk    rÄ|	|k    |
|k    z  }|
|	k    | z  }t          j
        ||         d|
|         z  |z  ¦  «        ||<   d||<   |
|	k     | z  }t          j
        ||         d|	|         z  |z  ¦  «         ||<   d||<   t          j
        |
|	¦  «        |z  }| t          j        |¦  «        |k    z  }||         ||<   d||<   ||fS )	a¨  Adjust final difference scheme to the presence of bounds.

    Parameters
    ----------
    x0 : ndarray, shape (n,)
        Point at which we wish to estimate derivative.
    h : ndarray, shape (n,)
        Desired absolute finite difference steps.
    num_steps : int
        Number of `h` steps in one direction required to implement finite
        difference scheme. For example, 2 means that we need to evaluate
        f(x0 + 2 * h) or f(x0 - 2 * h)
    scheme : {'1-sided', '2-sided'}
        Whether steps in one or both directions are required. In other
        words '1-sided' applies to forward and backward schemes, '2-sided'
        applies to center schemes.
    lb : ndarray, shape (n,)
        Lower bounds on independent variables.
    ub : ndarray, shape (n,)
        Upper bounds on independent variables.

    Returns
    -------
    h_adjusted : ndarray, shape (n,)
        Adjusted absolute step sizes. Step size decreases only if a sign flip
        or switching to one-sided scheme doesn't allow to take a full step.
    use_one_sided : ndarray of bool, shape (n,)
        Whether to switch to one-sided scheme. Informative only for
        ``scheme='2-sided'``.
    ú1-sided©Údtypeú2-sidedz(`scheme` must be '1-sided' or '2-sided'.éÿÿÿÿç      à?TF)ÚnpÚ	ones_likeÚboolÚabsÚ
zeros_likeÚ
ValueErrorÚallÚinfÚcopyÚmaximumÚminimum)Úx0ÚhÚ	num_stepsÚschemeÚlbÚubÚuse_one_sidedÚh_totalÚ
h_adjustedÚ
lower_distÚ
upper_distÚxÚviolatedÚfittingÚforwardÚbackwardÚcentralÚmin_distÚadjusted_centrals                      úU/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/scipy/optimize/_numdiff.pyÚ_adjust_scheme_to_boundsr8      s�  € ð> �ÒÐÝœ Q­dÐ3Ñ3Ô3ˆˆØ	�9Ò	Ð	ÝŒF�1‰IŒIˆÝœ a­tÐ4Ñ4Ô4ˆˆåÐCÑDÔDÐDå	„vˆr•b”f�WŠ} ¥r¤v¢Ñ.Ñ/Ô/ð  Ø�-ÐÐà�)‰m€GØ—’‘”€Jà�b‘€JØ�b‘€Jà�ÒÐØ�‰LˆØ˜’F˜q 2švÑ&ˆÝ”&˜‘/”/¥R¤Z°
¸JÑ%GÔ%GÒGˆØ�8˜gÑ%Ð&Ð&Ô&¨"Ñ,Ð&Ð&Ñ&à Ò+°¨xÑ7ˆØ(¨Ô1°IÑ=ˆ
�7ÑØ Ò+°¨xÑ7ˆØ *¨8Ô 4Ð4°yÑ@ˆ
�8ÑÐØ	�9Ò	Ð	Ø Ò(¨Z¸7Ò-BÑCˆà Ò+°¨xÑ7ˆÝ œjØˆgŒJ˜˜j¨Ô1Ñ1°IÑ=ñ?ô ?ˆ
�7Ñà!%ˆ�gÑà Ò+°¨xÑ7ˆÝ "¤
ØˆhŒK˜˜z¨(Ô3Ñ3°iÑ?ñ!Aô !Að  Aˆ
�8Ñà"&ˆ�hÑå”:˜j¨*Ñ5Ô5¸	ÑAˆØ$˜H­¬¨zÑ(:Ô(:¸hÒ(FÑGÐØ'/Ð0@Ô'Aˆ
Ð#Ñ$Ø*/ˆÐ&Ñ'à�}Ð$Ð$ó    c                 óæ  — t          j        t           j        ¦  «        j        }d}t          j        | t           j        ¦  «        r4t          j        | ¦  «        j        }t          j        | ¦  «        j        }d}t          j        |t           j        ¦  «        r:t          j        |¦  «        j        }|r||k     rt          j        |¦  «        j        }|dv r|dz  S |dv r|dz  S t          d¦  «        ‚)a¨  
    Calculates relative EPS step to use for a given data type
    and numdiff step method.

    Progressively smaller steps are used for larger floating point types.

    Parameters
    ----------
    f0_dtype: np.dtype
        dtype of function evaluation

    x0_dtype: np.dtype
        dtype of parameter vector

    method: {'2-point', '3-point', 'cs'}

    Returns
    -------
    EPS: float
        relative step size. May be np.float16, np.float32, np.float64

    Notes
    -----
    The default relative step will be np.float64. However, if x0 or f0 are
    smaller floating point types (np.float16, np.float32), then the smallest
    floating point type is chosen.
    FT)ú2-pointÚcsr   )ú3-pointgUUUUUUÕ?zBUnknown step method, should be one of {'2-point', '3-point', 'cs'})	r   ÚfinfoÚfloat64ÚepsÚ
issubdtypeÚinexactr   ÚitemsizeÚRuntimeError)Úx0_dtypeÚf0_dtypeÚmethodÚEPSÚx0_is_fpÚx0_itemsizeÚf0_itemsizes          r7   Ú_eps_for_methodrL   ]   sé   € õ< Œ(•2”:Ñ
Ô
Ô
"€Cà€HÝ	„}�X�rœzÑ*Ô*ð åŒh�xÑ Ô Ô$ˆÝ”h˜xÑ(Ô(Ô1ˆØˆå	„}�X�rœzÑ*Ô*ð )Ý”h˜xÑ(Ô(Ô1ˆàð 	)˜ kÒ1Ð1Ý”(˜8Ñ$Ô$Ô(ˆCàÐ"Ð"Ð"Ø�C‰xˆØ	�;Ð	Ð	Ø�S‰zÐåð :ñ ;ô ;ð 	;r9   c           
      ó²  — |dk                          t          ¦  «        dz  dz
  }t          |j        |j        |¦  «        }| €.||z  t	          j        dt	          j        |¦  «        ¦  «        z  }ng| |z  t	          j        |¦  «        z  }||z   |z
  }t	          j        |dk    ||z  t	          j        dt	          j        |¦  «        ¦  «        z  |¦  «        }|S )az  
    Computes an absolute step from a relative step for finite difference
    calculation.

    Parameters
    ----------
    rel_step: None or array-like
        Relative step for the finite difference calculation
    x0 : np.ndarray
        Parameter vector
    f0 : np.ndarray or scalar
    method : {'2-point', '3-point', 'cs'}

    Returns
    -------
    h : float
        The absolute step size

    Notes
    -----
    `h` will always be np.float64. However, if `x0` or `f0` are
    smaller floating point dtypes (e.g. np.float32), then the absolute
    step size will be calculated from the smallest floating point size.
    r   r   r   Nç      ð?)ÚastypeÚfloatrL   r   r   r"   r   Úwhere)Úrel_stepr$   Úf0rG   Úsign_x0ÚrstepÚabs_stepÚdxs           r7   Ú_compute_absolute_steprX   “   sÎ   € ð6 �QŠw×Ò�uÑ%Ô%¨Ñ)¨AÑ-€Gå˜BœH b¤h°Ñ7Ô7€EàÐØ˜7‘?¥R¤Z°µR´V¸B±Z´ZÑ%@Ô%@Ñ@ˆˆð
 ˜gÑ%­¬¨r©
¬
Ñ2ˆð �H‰} Ñ"ˆÝ”8˜B !šGØ! G™O­b¬j¸½b¼fÀR¹j¼jÑ.IÔ.IÑIØ$ñ&ô &ˆð €Or9   c                 ó¼   — d„ | D ¦   «         \  }}|j         dk    rt          j        ||j        ¦  «        }|j         dk    rt          j        ||j        ¦  «        }||fS )aa  
    Prepares new-style bounds from a two-tuple specifying the lower and upper
    limits for values in x0. If a value is not bound then the lower/upper bound
    will be expected to be -np.inf/np.inf.

    Examples
    --------
    >>> _prepare_bounds([(0, 1, 2), (1, 2, np.inf)], [0.5, 1.5, 2.5])
    (array([0., 1., 2.]), array([ 1.,  2., inf]))
    c              3   óL   K  — | ]}t          j        |t          ¬ ¦  «        V — Œ dS )r   N)r   ÚasarrayrP   )Ú.0Úbs     r7   ú	<genexpr>z"_prepare_bounds.<locals>.<genexpr>Ï   s1   è è € Ð9Ð9¨Q�bŒj˜¥%Ð(Ñ(Ô(Ð9Ð9Ð9Ð9Ð9Ð9r9   r   )Úndimr   ÚresizeÚshape)Úboundsr$   r(   r)   s       r7   Ú_prepare_boundsrc   Ä   s`   € ð :Ð9°&Ð9Ñ9Ô9�F€BˆØ	„w�!‚|€|ÝŒY�r˜2œ8Ñ$Ô$ˆà	„w�!‚|€|ÝŒY�r˜2œ8Ñ$Ô$ˆàˆrˆ6€Mr9   c                 ó®  — t          | ¦  «        rt          | ¦  «        } n7t          j        | ¦  «        } | dk                         t          j        ¦  «        } | j        dk    rt          d¦  «        ‚| j        \  }}|�t          j	        |¦  «        r5t          j
                             |¦  «        }|                     |¦  «        }n/t          j        |¦  «        }|j        |fk    rt          d¦  «        ‚| dd…|f         } t          | ¦  «        rt          ||| j        | j        ¦  «        }nt#          ||| ¦  «        }|                     ¦   «         ||<   |S )aÉ  Group columns of a 2-D matrix for sparse finite differencing [1]_.

    Two columns are in the same group if in each row at least one of them
    has zero. A greedy sequential algorithm is used to construct groups.

    Parameters
    ----------
    A : array_like or sparse array, shape (m, n)
        Matrix of which to group columns.
    order : int, iterable of int with shape (n,) or None
        Permutation array which defines the order of columns enumeration.
        If int or None, a random permutation is used with `order` used as
        a random seed. Default is 0, that is use a random permutation but
        guarantee repeatability.

    Returns
    -------
    groups : ndarray of int, shape (n,)
        Contains values from 0 to n_groups-1, where n_groups is the number
        of found groups. Each value ``groups[i]`` is an index of a group to
        which ith column assigned. The procedure was helpful only if
        n_groups is significantly less than n.

    References
    ----------
    .. [1] A. Curtis, M. J. D. Powell, and J. Reid, "On the estimation of
           sparse Jacobian matrices", Journal of the Institute of Mathematics
           and its Applications, 13 (1974), pp. 117-120.
    r   r   z`A` must be 2-dimensional.Nz`order` has incorrect shape.)r   r	   r   Ú
atleast_2drO   Úint32r_   r   ra   ÚisscalarÚrandomÚRandomStateÚpermutationr[   r   ÚindicesÚindptrr   r!   )ÚAÚorderÚmÚnÚrngÚgroupss         r7   Úgroup_columnsrs   Ù   s1  € õ< ��{„{ð &Ý�a‰LŒLˆˆåŒM˜!ÑÔˆØ�!ŠV�OŠO�BœHÑ%Ô%ˆà„v�‚{€{ÝÐ5Ñ6Ô6Ð6àŒ7�D€A€qà€}�œ EÑ*Ô*€}ÝŒi×#Ò# EÑ*Ô*ˆØ—’ Ñ"Ô"ˆˆå”
˜5Ñ!Ô!ˆØŒ;˜1˜$ÒÐÝÐ;Ñ<Ô<Ð<à	ˆ!ˆ!ˆ!ˆUˆ(Œ€Aå��{„{ð &Ý˜a  A¤I¨q¬xÑ8Ô8ˆˆå˜Q  1Ñ%Ô%ˆà—K’K‘M”M€Fˆ5�Mà€Mr9   r=   F© c                 óÖ  — |dvrt          d|› d�¦  «        ‚ddi}t          |¦  «        }t          j        |                     |¦  «        d|¬¦  «        }|j        }|                     |j        d¦  «        r|j        }|                     ||¦  «        }|j	        dk    rt          d	¦  «        ‚t          ||¦  «        \  }}|j        |j        k    s|j        |j        k    rt          d
¦  «        ‚|r[t          j        t          j        |¦  «        ¦  «        r&t          j        t          j        |¦  «        ¦  «        st          d¦  «        ‚|
€i }
t          | ||	|
¦  «        }dx}}|€ ||¦  «        }d}n.t          j        |¦  «        }|j	        dk    rt          d¦  «        ‚t          j        ||k     ||k    z  ¦  «        rt          d¦  «        ‚|r5|€t%          |j        |j        |¦  «        }t'          |||||¦  «        \  }}�nÏ|€t)          ||||¦  «        }nŒ|dk                         t*          ¦  «        dz  dz
  }|}||z   |z
  }t          j        |dk    t%          |j        |j        |¦  «        |z  t          j        dt          j        |¦  «        ¦  «        z  |¦  «        }|dk    rt3          ||dd||¦  «        \  }}n&|dk    rt3          ||dd||¦  «        \  }}n|dk    rd}|pt4          }t7          |¦  «        5 }|€t9          |||||||¦  «        \  }}nŸt;          |¦  «        st=          |¦  «        dk    r|\  }}n|}t?          |¦  «        }t;          |¦  «        r|                      ¦   «         }nt          j!        |¦  «        }t          j        |¦  «        }tE          |||||||||¦	  «	        \  }}ddd¦  «         n# 1 swxY w Y   |r||z  }||d<   ||fS |S )uZ*  Compute finite difference approximation of the derivatives of a
    vector-valued function.

    If a function maps from R^n to R^m, its derivatives form m-by-n matrix
    called the Jacobian, where an element (i, j) is a partial derivative of
    f[i] with respect to x[j].

    Parameters
    ----------
    fun : callable
        Function of which to estimate the derivatives. The argument x
        passed to this function is ndarray of shape (n,) (never a scalar
        even if n=1). It must return 1-D array_like of shape (m,) or a scalar.
    x0 : array_like of shape (n,) or float
        Point at which to estimate the derivatives. Float will be converted
        to a 1-D array.
    method : {'3-point', '2-point', 'cs'}, optional
        Finite difference method to use:
            - '2-point' - use the first order accuracy forward or backward
                          difference.
            - '3-point' - use central difference in interior points and the
                          second order accuracy forward or backward difference
                          near the boundary.
            - 'cs' - use a complex-step finite difference scheme. This assumes
                     that the user function is real-valued and can be
                     analytically continued to the complex plane. Otherwise,
                     produces bogus results.
    rel_step : None or array_like, optional
        Relative step size to use. If None (default) the absolute step size is
        computed as ``h = rel_step * sign(x0) * max(1, abs(x0))``, with
        `rel_step` being selected automatically, see Notes. Otherwise
        ``h = rel_step * sign(x0) * abs(x0)``. For ``method='3-point'`` the
        sign of `h` is ignored. The calculated step size is possibly adjusted
        to fit into the bounds.
    abs_step : array_like, optional
        Absolute step size to use, possibly adjusted to fit into the bounds.
        For ``method='3-point'`` the sign of `abs_step` is ignored. By default
        relative steps are used, only if ``abs_step is not None`` are absolute
        steps used.
    f0 : None or array_like, optional
        If not None it is assumed to be equal to ``fun(x0)``, in this case
        the ``fun(x0)`` is not called. Default is None.
    bounds : tuple of array_like, optional
        Lower and upper bounds on independent variables. Defaults to no bounds.
        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. Bounds checking is not implemented
        when `as_linear_operator` is True.
    sparsity : {None, array_like, sparse array, 2-tuple}, optional
        Defines a sparsity structure of the Jacobian matrix. If the Jacobian
        matrix is known to have only few non-zero elements in each row, then
        it's possible to estimate its several columns by a single function
        evaluation [3]_. To perform such economic computations two ingredients
        are required:

        * structure : array_like or sparse array of shape (m, n). A zero
          element means that a corresponding element of the Jacobian
          identically equals to zero.
        * groups : array_like of shape (n,). A column grouping for a given
          sparsity structure, use `group_columns` to obtain it.

        A single array or a sparse array is interpreted as a sparsity
        structure, and groups are computed inside the function. A tuple is
        interpreted as (structure, groups). If None (default), a standard
        dense differencing will be used.

        Note, that sparse differencing makes sense only for large Jacobian
        matrices where each row contains few non-zero elements.
    as_linear_operator : bool, optional
        When True the function returns an `scipy.sparse.linalg.LinearOperator`.
        Otherwise it returns a dense array or a sparse array depending on
        `sparsity`. The linear operator provides an efficient way of computing
        ``J.dot(p)`` for any vector ``p`` of shape (n,), but does not allow
        direct access to individual elements of the matrix. By default
        `as_linear_operator` is False.
    args, kwargs : tuple and dict, optional
        Additional arguments passed to `fun`. Both empty by default.
        The calling signature is ``fun(x, *args, **kwargs)``.
    full_output : bool, optional
        If True then the function also returns a dictionary with extra information
        about the calculation.
    workers : int or map-like callable, optional
        Supply a map-like callable, such as
        `multiprocessing.Pool.map` for evaluating the population in parallel.
        This evaluation is carried out as ``workers(fun, iterable)``.
        Alternatively, if `workers` is an int the task is subdivided into `workers`
        sections and the fun 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.

    Returns
    -------
    J : {ndarray, sparse array, LinearOperator}
        Finite difference approximation of the Jacobian matrix.
        If `as_linear_operator` is True returns a LinearOperator
        with shape (m, n). Otherwise it returns a dense array or sparse
        array depending on how `sparsity` is defined. If `sparsity`
        is None then a ndarray with shape (m, n) is returned. If
        `sparsity` is not None returns a csr_array or csr_matrix with
        shape (m, n) following the array/matrix type of the incoming structure.
        For sparse arrays and linear operators it is always returned as
        a 2-D structure. For ndarrays, if m=1 it is returned
        as a 1-D gradient array with shape (n,).

    info_dict : dict
        Dictionary containing extra information about the calculation. The
        keys include:

        - `nfev`, number of function evaluations. If `as_linear_operator` is True
           then `fun` is expected to track the number of evaluations itself.
           This is because multiple calls may be made to the linear operator which
           are not trackable here.

    See Also
    --------
    check_derivative : Check correctness of a function computing derivatives.

    Notes
    -----
    If `rel_step` is not provided, it assigned as ``EPS**(1/s)``, where EPS is
    determined from the smallest floating point dtype of `x0` or `fun(x0)`,
    ``np.finfo(x0.dtype).eps``, s=2 for '2-point' method and
    s=3 for '3-point' method. Such relative step approximately minimizes a sum
    of truncation and round-off errors, see [1]_. Relative steps are used by
    default. However, absolute steps are used when ``abs_step is not None``.
    If any of the absolute or relative steps produces an indistinguishable
    difference from the original `x0`, ``(x0 + dx) - x0 == 0``, then a
    automatic step size is substituted for that particular entry.

    A finite difference scheme for '3-point' method is selected automatically.
    The well-known central difference scheme is used for points sufficiently
    far from the boundary, and 3-point forward or backward scheme is used for
    points near the boundary. Both schemes have the second-order accuracy in
    terms of Taylor expansion. Refer to [2]_ for the formulas of 3-point
    forward and backward difference schemes.

    For dense differencing when m=1 Jacobian is returned with a shape (n,),
    on the other hand when n=1 Jacobian is returned with a shape (m, 1).
    Our motivation is the following: a) It handles a case of gradient
    computation (m=1) in a conventional way. b) It clearly separates these two
    different cases. b) In all cases np.atleast_2d can be called to get 2-D
    Jacobian with correct dimensions.

    References
    ----------
    .. [1] W. H. Press et. al. "Numerical Recipes. The Art of Scientific
           Computing. 3rd edition", sec. 5.7.

    .. [2] A. Curtis, M. J. D. Powell, and J. Reid, "On the estimation of
           sparse Jacobian matrices", Journal of the Institute of Mathematics
           and its Applications, 13 (1974), pp. 117-120.

    .. [3] B. Fornberg, "Generation of Finite Difference Formulas on
           Arbitrarily Spaced Grids", Mathematics of Computation 51, 1988.

    Examples
    --------
    >>> import numpy as np
    >>> from scipy.optimize._numdiff import approx_derivative
    >>>
    >>> def f(x, c1, c2):
    ...     return np.array([x[0] * np.sin(c1 * x[1]),
    ...                      x[0] * np.cos(c2 * x[1])])
    ...
    >>> x0 = np.array([1.0, 0.5 * np.pi])
    >>> approx_derivative(f, x0, args=(1, 2))
    array([[ 1.,  0.],
           [-1.,  0.]])

    Bounds can be used to limit the region of function evaluation.
    In the example below we compute left and right derivative at point 1.0.

    >>> def g(x):
    ...     return x**2 if x >= 1 else x
    ...
    >>> x0 = 1.0
    >>> approx_derivative(g, x0, bounds=(-np.inf, 1.0))
    array([ 1.])
    >>> approx_derivative(g, x0, bounds=(1.0, np.inf))
    array([ 2.])

    We can also parallelize the derivative calculation using the workers
    keyword.

    >>> from multiprocessing import Pool
    >>> import time
    >>> def fun2(x):       # import from an external file for use with multiprocessing
    ...     time.sleep(0.002)
    ...     return rosen(x)

    >>> rng = np.random.default_rng()
    >>> x0 = rng.uniform(high=10, size=(2000,))
    >>> f0 = rosen(x0)

    >>> %timeit approx_derivative(fun2, x0, f0=f0)     # may vary
    10.5 s Â± 5.91 ms per loop (mean Â± std. dev. of 7 runs, 1 loop each)

    >>> elapsed = []
    >>> with Pool() as workers:
    ...     for i in range(10):
    ...         t = time.perf_counter()
    ...         approx_derivative(fun2, x0, workers=workers.map, f0=f0)
    ...         et = time.perf_counter()
    ...         elapsed.append(et - t)
    >>> np.mean(elapsed)    # may vary
    np.float64(1.442545195999901)

    Create a map-like vectorized version. `x` is a generator, so first of all
    a 2-D array, `xx`, is reconstituted. Here `xx` has shape `(Y, N)` where `Y`
    is the number of function evaluations to perform and `N` is the dimensionality
    of the objective function. The underlying objective function is `rosen`, which
    requires `xx` to have shape `(N, Y)`, so a transpose is required.

    >>> def fun(f, x, *args, **kwds):
    ...     xx = np.r_[[xs for xs in x]]
    ...     return f(xx.T)
    >>> %timeit approx_derivative(fun2, x0, workers=fun, f0=f0)    # may vary
    91.8 ms Â± 755 Î¼s per loop (mean Â± std. dev. of 7 runs, 10 loops each)

    )r;   r=   r<   zUnknown method 'z'. ÚnfevNr   )r_   Úxpúreal floatingz#`x0` must have at most 1 dimension.z,Inconsistent shapes between bounds and `x0`.z7Bounds not supported when `as_linear_operator` is True.r   z&`f0` passed has more than 1 dimension.z `x0` violates bound constraints.r   rN   r;   r   r=   r   r<   F)#r   r   ÚxpxÚ
atleast_ndr[   r?   Úisdtyper   rO   r_   rc   ra   r   r   ÚisinfÚ_Fun_WrapperÚ
atleast_1dÚanyrL   Ú_linear_operator_differencerX   rP   rQ   r"   r   r8   Úmapr   Ú_dense_differencer   Úlenrs   Útocscre   Ú_sparse_difference)Úfunr$   rG   rR   rV   rS   rb   ÚsparsityÚas_linear_operatorÚargsÚkwargsÚfull_outputÚworkersÚ	info_dictrw   Ú_xÚ_dtyper(   r)   Úfun_wrappedrv   Ú_nfevÚJÚ_r%   rT   rW   r*   ÚmfÚ	structurerr   s                                  r7   Úapprox_derivativer–     s³  € ðF Ð1Ð1Ð1ÝÐ7¨FÐ7Ð7Ð7Ñ8Ô8Ð8à˜�€Iå	˜Ñ	Ô	€BÝ	Œ˜Ÿ
š
 2™œ¨Q°2Ð	6Ñ	6Ô	6€BØŒZ€FØ	‡z‚z�"”(˜OÑ,Ô,ð Ø”ˆð 
�Š�2�vÑ	Ô	€Bà	„w�‚{€{ÝÐ>Ñ?Ô?Ð?å˜V RÑ(Ô(�F€Bˆà	„x�2”8ÒÐ˜rœx¨2¬8Ò3Ð3ÝÐGÑHÔHÐHàð :¥2¤6­"¬(°2©,¬,Ñ#7Ô#7ð :Ý')¤v­b¬h°r©l¬lÑ';Ô';ð:åð 9ñ :ô :ð 	:ð €~Øˆå˜s B¨¨fÑ5Ô5€Kð Ð€Dˆ5à	€zØˆ[˜‰_Œ_ˆØˆˆåŒ]˜2ÑÔˆØŒ7�QŠ;ˆ;ÝÐEÑFÔFÐFå	„vˆr�BŠw˜2 š7Ñ#Ñ$Ô$ð =ÝÐ;Ñ<Ô<Ð<àð 5AØÐÝ& r¤x°´¸6ÑBÔBˆHå*¨;¸Ø+-¨x¸ñAô A‰ˆˆ1‰1ð ÐÝ& x°°R¸Ñ@Ô@ˆAˆAð ˜Q’w×&Ò&¥uÑ-Ô-°Ñ1°AÑ5ˆGØˆAð ˜‘6˜R‘-ˆBÝ”˜˜qšÝ(¨¬°2´8¸VÑDÔDØ ñ!Ý#%¤:¨cµ2´6¸"±:´:Ñ#>Ô#>ñ?àñô ˆAð
 �YÒÐÝ7Ø�A�q˜) R¨ñ -ô  -ÑˆAˆ}ˆ}à�yÒ Ð Ý7Ø�A�q˜) R¨ñ -ô  -ÑˆAˆ}ˆ}à�tŠ^ˆ^Ø!ˆMð �.�SˆÝ˜Ñ Ô ð 	A BØÐÝ,¨[¸"¸bÀ!Ø)6¸Ø)+ñ-ô -‘��5�5õ   Ñ)Ô)ð 5­c°(©m¬m¸qÒ.@Ð.@Ø(0Ñ%�I˜v˜và (�IÝ*¨8Ñ4Ô4�Få˜IÑ&Ô&ð 9Ø )§¢Ñ 1Ô 1�I�Iå "¤¨iÑ 8Ô 8�IÝœ vÑ.Ô.�Ý-¨k¸2¸rÀ1Ø-:¸IØ-3°V¸RñAô A‘��5ð#	Að 	Að 	Añ 	Aô 	Að 	Að 	Að 	Að 	Að 	Að 	Aøøøð 	Að 	Að 	Að 	Að* ð Ø�‰ˆØ ˆ	�&ÑØ�)ˆ|Ðàˆs   ÌB;OÏOÏOc                 óÊ   ‡ ‡‡‡‡— ‰j         Š‰j         }|dk    r
ˆˆ ˆˆˆfd„}n-|dk    r	ˆ ˆˆˆfd„}n|dk    r	ˆ ˆˆˆfd„}nt          d¦  «        ‚t          ‰|f|¦  «        dfS )	Nr;   c                 óÔ   •— t          j        | t          j        | ¦  «        ¦  «        rt          j        ‰¦  «        S ‰t	          | ¦  «        z  }‰|| z  z   } ‰|¦  «        ‰z
  }||z  S ©N©r   Úarray_equalr   Úzerosr   )	ÚprW   r/   ÚdfrS   r†   r%   ro   r$   s	       €€€€€r7   Úmatvecz+_linear_operator_difference.<locals>.matvecr  se   ø€ ÝŒ~˜a¥¤¨qÑ!1Ô!1Ñ2Ô2ð #Ý”x ‘{”{Ð"Ø•T˜!‘W”W‘ˆBØ�R˜‘T‘	ˆAØ��Q‘”˜"‘ˆBØ˜‘7ˆNr9   r=   c                 ó  •— t          j        | t          j        | ¦  «        ¦  «        rt          j        ‰	¦  «        S d‰z  t	          | ¦  «        z  }‰
|dz  | z  z
  }‰
|dz  | z  z   } ‰|¦  «        } ‰|¦  «        }||z
  }||z  S ©Nr   rš   )r�   rW   Úx1Úx2Úf1Úf2rž   r†   r%   ro   r$   s          €€€€r7   rŸ   z+_linear_operator_difference.<locals>.matvec|  s�   ø€ ÝŒ~˜a¥¤¨qÑ!1Ô!1Ñ2Ô2ð #Ý”x ‘{”{Ð"Ø�1‘•t˜A‘w”w‘ˆBØ�r˜!‘t˜Q‘h‘ˆBØ�r˜!‘t˜Q‘h‘ˆBØ��R‘”ˆBØ��R‘”ˆBØ�b‘ˆBØ˜‘7ˆNr9   r<   c                 óâ   •— t          j        | t          j        | ¦  «        ¦  «        rt          j        ‰¦  «        S ‰t	          | ¦  «        z  }‰|| z  dz  z   } ‰|¦  «        }|j        }||z  S ©Nù              ð?)r   r›   r   rœ   r   Úimag)	r�   rW   r/   r¤   rž   r†   r%   ro   r$   s	        €€€€r7   rŸ   z+_linear_operator_difference.<locals>.matvec‰  sl   ø€ ÝŒ~˜a¥¤¨qÑ!1Ô!1Ñ2Ô2ð #Ý”x ‘{”{Ð"Ø•T˜!‘W”W‘ˆBØ�R˜‘T˜#‘X‘ˆAØ��Q‘”ˆBØ”ˆBØ˜‘7ˆNr9   úNever be here.r   )ÚsizerD   r   )r†   r$   rS   r%   rG   rp   rŸ   ro   s   ````   @r7   r€   r€   l  sî   øøøøø€ Ø
Œ€AØ
Œ€Aà�ÒÐð	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 
�9Ò	Ð	ð		ð 		ð 		ð 		ð 		ð 		ð 		ð 		ð 		ð 
�4Šˆð	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	õ Ð+Ñ,Ô,Ð,å˜1˜a˜& &Ñ)Ô)¨1Ð,Ð,r9   c           
      óN  ‡‡‡‡— ‰j         }‰j         Št          j        ‰|f¦  «        }d}	|dk    rsˆfd„}
 ||  |
‰‰¦  «        ¦  «        }ˆˆfd„t          ‰¦  «        D ¦   «         }ˆfd„|D ¦   «         }d„ t	          ||¦  «        D ¦   «         }|	t          |¦  «        z  }	�nÆ|dk    �rUd„ }t           ||  |‰‰|¦  «        ¦  «        ¦  «        } |‰‰|¦  «        }t          ¦   «         }t          ¦   «         }t          |¦  «        D ]Å\  }}t          |¦  «        }t          |¦  «        }t          |¦  «        }t          |¦  «        }|rF| 
                    ||         ‰|         z
  ¦  «         | 
                    d	‰z  d
|z  z   |z
  ¦  «         Œ‰| 
                    ||         ||         z
  ¦  «         | 
                    ||z
  ¦  «         ŒÆd„ t	          ||¦  «        D ¦   «         }|	dt          |¦  «        z  z  }	nj|dk    rUˆfd„}t           ||  |‰‰¦  «        ¦  «        ¦  «        }d„ t	          |‰¦  «        D ¦   «         }|	t          |¦  «        z  }	nt          d¦  «        ‚t          |¦  «        D ]
\  }}|||<   Œ|dk    rt          j        |¦  «        }|j        |	fS )Nr   r;   c              3   óˆ   •K  — t          ‰¦  «        D ].}t          j        | ¦  «        }| |         ||         z   ||<   |V — Œ/d S r™   )Úranger   r!   )r$   r%   Úir¢   rp   s       €r7   Úx_generator2z'_dense_difference.<locals>.x_generator2ž  sU   øè è € Ý˜1‘X”Xð 	ð 	�õ ”W˜R‘[”[�Ø˜1œ  !¤™��1‘Ø����ð	ð 	r9   c                 óD   •— g | ]}‰|         ‰|         z   ‰|         z
  ‘ŒS rt   rt   )r\   r¯   r%   r$   s     €€r7   ú
<listcomp>z%_dense_difference.<locals>.<listcomp>­  s.   ø€ Ð7Ð7Ð7¨ˆr�!Œu�q˜”t‰|˜r !œuÑ$Ð7Ð7Ð7r9   c                 ó   •— g | ]}|‰z
  ‘ŒS rt   rt   )r\   Úf_evalrS   s     €r7   r²   z%_dense_difference.<locals>.<listcomp>®  s   ø€ Ð0Ð0Ð0˜fˆf�r‰kÐ0Ð0Ð0r9   c                 ó   — g | ]
\  }}||z  ‘ŒS rt   rt   ©r\   ÚdelfÚdelxs      r7   r²   z%_dense_difference.<locals>.<listcomp>¯  ó    € Ð;Ð;Ð;¡  t�˜‘Ð;Ð;Ð;r9   r=   c              3   ó@  K  — t          |¦  «        D ]‹\  }}t          j        | ¦  «        }t          j        | ¦  «        }|r,| |         ||         z   ||<   | |         d||         z  z   ||<   n(| |         ||         z
  ||<   | |         ||         z   ||<   |V — |V — ŒŒd S r¡   )Ú	enumerater   r!   )r$   r%   r*   r¯   Ú	one_sidedr¢   r£   s          r7   Úx_generator3z'_dense_difference.<locals>.x_generator3³  s»   è è € Ý )¨-Ñ 8Ô 8ð 
ð 
‘��9Ý”W˜R‘[”[�Ý”W˜R‘[”[�Øð )Ø˜qœE A a¤D™L�B�q‘EØ˜qœE A a¨¤d¡F™N�B�q‘E�Eà˜qœE A a¤D™L�B�q‘EØ˜qœE A a¤D™L�B�q‘EØ���Ø����ð
ð 
r9   g      Àé   c                 ó   — g | ]
\  }}||z  ‘ŒS rt   rt   r¶   s      r7   r²   z%_dense_difference.<locals>.<listcomp>Ò  r¹   r9   r   r<   c              3   ó¢   •K  — t          ‰¦  «        D ];}|                      t          d¬¦  «        }||xx         ||         dz  z  cc<   |V — Œ<d S )NT©r!   r¨   )r®   rO   Úcomplex)r$   r%   r¯   Úxcrp   s       €r7   Úx_generator_csz)_dense_difference.<locals>.x_generator_csÕ  sd   øè è € Ý˜1‘X”Xð ð �Ø—Y’Y�w¨T�YÑ2Ô2�Ø�1��”˜˜1œ ™Ñ#��‘Ø����ðð r9   c                 ó(   — g | ]\  }}|j         |z  ‘ŒS rt   )r©   )r\   r¤   Úhis      r7   r²   z%_dense_difference.<locals>.<listcomp>Ü  s"   € Ð<Ð<Ð<¡& " b�”˜2‘Ð<Ð<Ð<r9   rª   r   )r«   r   Úemptyr®   Úziprƒ   ÚiterÚlistr»   ÚnextÚappendrD   ÚravelÚT)r†   r$   rS   r%   r*   rG   rŒ   ro   ÚJ_transposedrv   r°   Úf_evalsrW   rž   Údf_dxr½   Úgenr¯   r¼   ÚlÚur¤   r¥   rÄ   Úvrp   s    ```                     @r7   r‚   r‚   —  s  øøøø€ Ø
Œ€AØ
Œ€AÝ”8˜Q ˜FÑ#Ô#€LØ€Dà�ÒÐð
	ð 
	ð 
	ð 
	ð 
	ð �'˜#˜|˜|¨B°Ñ2Ô2Ñ3Ô3ˆØ7Ð7Ð7Ð7Ð7­e°A©h¬hÐ7Ñ7Ô7ˆØ0Ð0Ð0Ð0¨Ð0Ñ0Ô0ˆØ;Ð;­s°2°r©{¬{Ð;Ñ;Ô;ˆØ•�E‘
”
Ñˆ‰à	�9Ò	Ñ	ð	ð 	ð 	õ �w�w˜s L L°°Q¸Ñ$FÔ$FÑGÔGÑHÔHˆØˆl˜2˜q -Ñ0Ô0ˆÝ‰VŒVˆÝ‰VŒVˆÝ% mÑ4Ô4ð 	#ð 	#‰LˆAˆyÝ�S‘	”	ˆAÝ�S‘	”	ˆAå�g‘”ˆBÝ�g‘”ˆBØð #Ø—	’	˜!˜Aœ$  A¤™,Ñ'Ô'Ð'Ø—	’	˜$ ™) a¨"¡fÑ,¨rÑ1Ñ2Ô2Ð2Ð2à—	’	˜!˜Aœ$  1¤™+Ñ&Ô&Ð&Ø—	’	˜"˜r™'Ñ"Ô"Ð"Ð"Ø;Ð;­s°2°r©{¬{Ð;Ñ;Ô;ˆØ�•C˜‘J”J‘ÑˆˆØ	�4Šˆð	ð 	ð 	ð 	ð 	õ �w�w˜s N N°2°qÑ$9Ô$9Ñ:Ô:Ñ;Ô;ˆØ<Ð<­C°¸©O¬OÐ<Ñ<Ô<ˆØ•�E‘
”
ÑˆˆåÐ+Ñ,Ô,Ð,å˜%Ñ Ô ð ð ‰ˆˆ1Øˆ�Q‰ˆàˆA‚v€vÝ”x Ñ-Ô-ˆàŒ>˜4ÐÐr9   c	                 ó”  ‡‡‡‡‡#‡$— |j         }	‰j         }
g }g }g }t          j        ‰¦  «        dz   Š$d}ˆˆ$fd„Š#ˆ#ˆˆfd„}ˆ#ˆˆˆfd„}ˆ#ˆˆfd„}|dk    r,t           ||  |¦   «         ¦  «        ¦  «        } |¦   «         }nY|dk    r,t           ||  |¦   «         ¦  «        ¦  «        } |¦   «         }n'|d	k    r!t           ||  |¦   «         ¦  «        ¦  «        } ‰#¦   «         D �]æ}t          j        |¦  «        \  }t          |d d …|f         ¦  «        \  }}}||         }|dk    r+t          |¦  «        ‰z
  }t          |¦  «        |z
  }|dz  }�n)|dk    rít          |¦  «        }t          |¦  «        }‰|z  }‰ |z  }t          j        |
¦  «        }||         ‰|         z
  ||<   ||         ||         z
  ||<   t          |¦  «        }t          |¦  «        } |d
z  }‰|         }!t          j        |	¦  «        }||!         }"d||"         z  d||"         z  z   | |"         z
  ||"<   ||!          }"| |"         ||"         z
  ||"<   n6|d	k    r!t          |¦  «        }|dz  }|j	        }‰|z  }nt          d¦  «        ‚|                     |¦  «         |                     |¦  «         |                     ||         ||         z  ¦  «         �Œèt          j        |¦  «        }t          j        |¦  «        }t          j        |¦  «        }t          |¦  «        rt          |||ff|	|
f¬¦  «        |fS t          |||ff|	|
f¬¦  «        |fS )Nr   r   c               3   ó^   •K  — t          ‰¦  «        D ]} t          j        | ‰¦  «        V — Œd S r™   )r®   r   Úequal)Úgrouprr   Ún_groupss    €€r7   Úe_generatorz'_sparse_difference.<locals>.e_generatorõ  sA   øè è € å˜8‘_”_ð 	*ð 	*ˆEÝ”(˜5 &Ñ)Ô)Ð)Ð)Ð)Ð)ð	*ð 	*r9   c               3   óF   •K  —  ‰¦   «         } | D ]}‰|z  }‰|z   }|V — Œd S r™   rt   )Úe_genÚeÚh_vecr/   rÛ   r%   r$   s       €€€r7   r°   z(_sparse_difference.<locals>.x_generator2ú  sH   øè è € Ø�‘”ˆØð 	ð 	ˆAØ˜‘EˆEØ�U‘
ˆAØˆGˆGˆGˆGð	ð 	r9   c               3   ó`  •K  —  ‰¦   «         } | D ]�}‰|z  }‰
                      ¦   «         }‰
                      ¦   «         }‰	|z  }||xx         ||         z  cc<   ||xx         d||         z  z  cc<   ‰	 |z  }||xx         ||         z  cc<   ||xx         ||         z  cc<   |V — |V — Œžd S r¡   rÁ   )rÝ   rÞ   rß   r¢   r£   Úmask_1Úmask_2rÛ   r%   r*   r$   s          €€€€r7   r½   z(_sparse_difference.<locals>.x_generator3  så   øè è € Ø�‘”ˆØð 	ð 	ˆAØ˜‘EˆEØ—’‘”ˆBØ—’‘”ˆBà" QÑ&ˆFØˆvˆJˆJŒJ˜% œ-Ñ'ˆJˆJ‰JØˆvˆJˆJŒJ˜!˜e FœmÑ+Ñ+ˆJˆJ‰Jà#�^ aÑ'ˆFØˆvˆJˆJŒJ˜% œ-Ñ'ˆJˆJ‰JØˆvˆJˆJŒJ˜% œ-Ñ'ˆJˆJ‰JØˆHˆHˆHØˆHˆHˆHˆHð	ð 	r9   c               3   óH   •K  —  ‰¦   «         } | D ]}‰|z  }‰|dz  z   V — Œd S r§   rt   )rÝ   rÞ   rß   rÛ   r%   r$   s      €€€r7   rÄ   z*_sparse_difference.<locals>.x_generator_cs  sL   øè è € Ø�‘”ˆØð 	#ð 	#ˆAØ˜‘EˆEØ�u˜s‘{Ñ"Ð"Ð"Ð"Ð"ð	#ð 	#r9   r;   r=   r<   r   éýÿÿÿr¾   rª   )ra   )r«   r   ÚmaxrÉ   Únonzeror   rË   rœ   rÇ   r©   r   rÌ   Úhstackr   r   r
   )%r†   r$   rS   r%   r*   r•   rr   rG   rŒ   ro   rp   Úrow_indicesÚcol_indicesÚ	fractionsrv   r°   r½   rÄ   rÐ   ÚxsrÞ   Úcolsr¯   Újr“   rW   rž   r¢   r£   rá   râ   r¤   r¥   ÚmaskÚrowsrÛ   rÚ   s%    ` `` `                            @@r7   r…   r…   ê  s÷  øøøøøø€ à
Œ€AØ
Œ€AØ€KØ€KØ€IåŒv�f‰~Œ~ Ñ!€HØ€Dð*ð *ð *ð *ð *ð *ð
ð ð ð ð ð ð ðð ð ð ð ð ð ð ð"#ð #ð #ð #ð #ð #ð #ð �ÒÐÝ�w�w˜s L L¡N¤NÑ3Ô3Ñ4Ô4ˆØˆ\‰^Œ^ˆˆØ	�9Ò	Ð	Ý�w�w˜s L L¡N¤NÑ3Ô3Ñ4Ô4ˆØˆ\‰^Œ^ˆˆØ	�4ŠˆÝ�w�w˜s N NÑ$4Ô$4Ñ5Ô5Ñ6Ô6ˆàˆ[‰]Œ]ð 2(ñ 2(ˆõ ”
˜1‘”‰ˆå�y    D Ô)Ñ*Ô*‰ˆˆ1ˆaà�ŒGˆà�YÒÐÝ�b‘”˜B‘ˆBÝ�g‘” Ñ#ˆBØ�A‰IˆD‰DØ�yÒ Ð õ �b‘”ˆBÝ�b‘”ˆBà" QÑ&ˆFØ#�^ aÑ'ˆFå”˜!‘”ˆBØ˜Fœ b¨¤jÑ0ˆBˆv‰JØ˜Fœ b¨¤jÑ0ˆBˆv‰Jå�g‘”ˆBÝ�g‘”ˆBØ�A‰IˆDà  Ô#ˆDÝ”˜!‘”ˆBà�T”7ˆDØ˜B˜tœH‘} q¨2¨d¬8¡|Ñ3°b¸´hÑ>ˆBˆt‰Hà�d�U”8ˆDØ˜$”x " T¤(Ñ*ˆBˆt‰HˆHØ�tŠ^ˆ^Ý�g‘”ˆBØ�A‰IˆDØ”ˆBØ�Q‘ˆBˆBåÐ-Ñ.Ô.Ð.ð 	×Ò˜1ÑÔÐØ×Ò˜1ÑÔÐØ×Ò˜˜Aœ  A¤™Ñ'Ô'Ð'Ñ'å”)˜KÑ(Ô(€KÝ”)˜KÑ(Ô(€KÝ”	˜)Ñ$Ô$€Iå�)ÑÔð WÝ˜9 {°KÐ&@ÐAÈ!ÈQÈÐPÑPÔPÐRVÐVÐVÝ�i +¨{Ð!;Ð<ÀQÈÀFÐKÑKÔKÈTÐQÐQr9   c                   ó   — e Zd Zd„ Zd„ ZdS )r}   c                 ó>   — || _         || _        || _        || _        d S r™   )r†   r$   r‰   rŠ   )Úselfr†   r$   r‰   rŠ   s        r7   Ú__init__z_Fun_Wrapper.__init__a  s"   € ØˆŒØˆŒØˆŒ	ØˆŒˆˆr9   c                 ó2  — t          | j        ¦  «        }|                     |j        d¦  «        r |                     || j        j        ¦  «        }t          j         | j        |g| j        ¢R i | j	        ¤Ž¦  «        }|j
        dk    rt          d¦  «        ‚|S )Nrx   r   z-`fun` return value has more than 1 dimension.)r   r$   r{   r   rO   r   r~   r†   r‰   rŠ   r_   rD   )rò   r/   rw   Úfs       r7   Ú__call__z_Fun_Wrapper.__call__g  s˜   € õ ˜TœWÑ%Ô%ˆà�:Š:�a”g˜Ñ/Ô/ð 	,Ø—	’	˜!˜TœWœ]Ñ+Ô+ˆAåŒM˜(˜$œ( 1Ð@ t¤yÐ@Ð@Ð@°D´KÐ@Ð@ÑAÔAˆØŒ6�AŠ:ˆ:Ýð  8ñ 9ô 9ð 9àˆr9   N)Ú__name__Ú
__module__Ú__qualname__ró   rö   rt   r9   r7   r}   r}   _  s2   € € € € € ðð ð ðð ð ð ð r9   r}   c           	      ó~  — |€i } ||g|¢R i |¤Ž}t          |¦  «        r¸t          | |||||¬¦  «        }t          |¦  «        }||z
  }t          |¦  «        \  }	}
}t	          j        ||	|
f         ¦  «                             ¦   «         }t	          j        t	          j        |¦  «        t	          j	        dt	          j        |¦  «        ¦  «        z  ¦  «        S t          | ||||¬¦  «        }t	          j        ||z
  ¦  «        }t	          j        |t	          j	        dt	          j        |¦  «        ¦  «        z  ¦  «        S )aS	  Check correctness of a function computing derivatives (Jacobian or
    gradient) by comparison with a finite difference approximation.

    Parameters
    ----------
    fun : callable
        Function of which to estimate the derivatives. The argument x
        passed to this function is ndarray of shape (n,) (never a scalar
        even if n=1). It must return 1-D array_like of shape (m,) or a scalar.
    jac : callable
        Function which computes Jacobian matrix of `fun`. It must work with
        argument x the same way as `fun`. The return value must be array_like
        or sparse array with an appropriate shape.
    x0 : array_like of shape (n,) or float
        Point at which to estimate the derivatives. Float will be converted
        to 1-D array.
    bounds : 2-tuple of array_like, optional
        Lower and upper bounds on independent variables. Defaults to no bounds.
        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.
    args, kwargs : tuple and dict, optional
        Additional arguments passed to `fun` and `jac`. Both empty by default.
        The calling signature is ``fun(x, *args, **kwargs)`` and the same
        for `jac`.

    Returns
    -------
    accuracy : float
        The maximum among all relative errors for elements with absolute values
        higher than 1 and absolute errors for elements with absolute values
        less or equal than 1. If `accuracy` is on the order of 1e-6 or lower,
        then it is likely that your `jac` implementation is correct.

    See Also
    --------
    approx_derivative : Compute finite difference approximation of derivative.

    Examples
    --------
    >>> import numpy as np
    >>> from scipy.optimize._numdiff import check_derivative
    >>>
    >>>
    >>> def f(x, c1, c2):
    ...     return np.array([x[0] * np.sin(c1 * x[1]),
    ...                      x[0] * np.cos(c2 * x[1])])
    ...
    >>> def jac(x, c1, c2):
    ...     return np.array([
    ...         [np.sin(c1 * x[1]),  c1 * x[0] * np.cos(c1 * x[1])],
    ...         [np.cos(c2 * x[1]), -c2 * x[0] * np.sin(c2 * x[1])]
    ...     ])
    ...
    >>>
    >>> x0 = np.array([1.0, 0.5 * np.pi])
    >>> check_derivative(f, jac, x0, args=(1, 2))
    2.4492935982947064e-16
    N)rb   r‡   r‰   rŠ   r   )rb   r‰   rŠ   )
r   r–   r
   r   r   r[   rÍ   rå   r   r"   )r†   Újacr$   rb   r‰   rŠ   Ú	J_to_testÚJ_diffÚabs_errr¯   rí   Úabs_err_dataÚJ_diff_datas                r7   Úcheck_derivativer  v  sG  € ðz €~ØˆØ��BÐ(˜Ð(Ð(Ð( Ð(Ð(€IÝ�	ÑÔð ?Ý" 3¨°6ÀIØ(,°Vð=ñ =ô =ˆå˜iÑ(Ô(ˆ	Ø˜fÑ$ˆÝ! '™]œ]Ñˆˆ1ˆlÝ”j ¨¨1¨¤Ñ.Ô.×4Ò4Ñ6Ô6ˆÝŒv•b”f˜\Ñ*Ô*Ý”j ¥B¤F¨;Ñ$7Ô$7Ñ8Ô8ñ9ñ :ô :ð 	:õ # 3¨°6Ø(,°Vð=ñ =ô =ˆå”&˜ VÑ+Ñ,Ô,ˆÝŒv�g¥¤
¨1­b¬f°V©n¬nÑ =Ô =Ñ=Ñ>Ô>Ð>r9   )r   )&Ú__doc__Ú	functoolsÚnumpyr   Únumpy.linalgr   Úscipy.sparse.linalgr   Úsparser   r   r   r	   r
   r   Ú_group_columnsr   r   Úscipy._lib._array_apir   Úscipy._lib._utilr   Ú
scipy._libr   ry   r8   Ú	lru_cacherL   rX   rc   rs   r    r–   r€   r‚   r…   r}   r  rt   r9   r7   ú<module>r     s  ðØ -Ð -Ø Ð Ð Ð Ø Ð Ð Ð Ø Ð Ð Ð Ð Ð à .Ð .Ð .Ð .Ð .Ð .Ø QÐ QÐ QÐ QÐ QÐ QÐ QÐ QÐ QÐ QÐ QÐ QÐ QÐ QÐ QÐ QØ 5Ð 5Ð 5Ð 5Ð 5Ð 5Ð 5Ð 5Ø 1Ð 1Ð 1Ð 1Ð 1Ð 1Ø 'Ð 'Ð 'Ð 'Ð 'Ð 'Ø -Ð -Ð -Ð -Ð -Ð -ðL%ð L%ð L%ð^ Ôð2;ð 2;ñ Ôð2;ðj.ð .ð .ðbð ð ð*:ð :ð :ð :ðz '0¸$ÈØ¨¬ w°´Ð&7À$Ø).°RÀØ"'°ðSð Sð Sð Sðl
(-ð (-ð (-ðVP ð P ð P ðfrRð rRð rRðjð ð ð ð ñ ô ð ð. -/¬F¨7°B´FÐ*;À"Ø ðM?ð M?ð M?ð M?ð M?ð M?r9   