403Webshell
Server IP : 217.160.0.135  /  Your IP : 216.73.217.85
Web Server : Apache
System : Linux www 6.18.52-i1-ampere #1203 SMP Mon Sep 14 18:29:59 CEST 2026 aarch64
User : sws1074145052 ( 1074145052)
PHP Version : 8.3.32
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /usr/lib/python3/dist-packages/scipy/optimize/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /usr/lib/python3/dist-packages/scipy/optimize/__pycache__/_numdiff.cpython-311.pyc
�

d�cyn�	��dZddlZddlZddlmZddlmZddlm	Z	m
Z
mZmZm
Z
ddlmZmZd	�Zej��d
���Zd�Zd�Zdd
�Zddddejejfdddif	d�Zd�Zd�Zd�Zejejfdifd�ZdS)z'Routines for numerical differentiation.�N)�norm)�LinearOperator�)�issparse�
csc_matrix�
csr_matrix�
coo_matrix�find�)�group_dense�group_sparsec�2�|dkrtj|t���}nE|dkr0tj|��}tj|t���}ntd���tj|tjk|tjkz��r||fS||z}|���}||z
}	||z
}
|dkr�||z}||k||kz}tj|��tj	|	|
��k}
|||
zxxdzcc<|
|	k|
z}|
||z||<|
|	k|
z}|	||z||<n�|dkr�|	|k|
|kz}|
|	k|z}tj
||d|
|z|z��||<d||<|
|	k|z}tj
||d|	|z|z��||<d||<tj
|
|	��|z}|tj|��|kz}||||<d||<||fS)	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                   �9/usr/lib/python3/dist-packages/scipy/optimize/_numdiff.py�_adjust_scheme_to_boundsr4s���>������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���tjtj��j}d}tj|tj��r4tj|��j}tj|��j}d}tj|tj��r:tj|��j}|r||krtj|��j}|dvr|dzS|dvr|dzStd���)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       r3�_eps_for_methodrHZs���<
�(�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���:�;�;�	;r5c
��|dk�t��dzdz
}t|j|j|��}|�.||zt	jdt	j|����z}ng||zt	j|��z}||z|z
}t	j|dk||zt	jdt	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.
    rrrN��?)�astype�floatrHrrrr�where)�rel_stepr �f0rC�sign_x0�rstep�abs_step�dxs        r3�_compute_absolute_steprT�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�$�&�&���Or5c��d�|D��\}}|jdkrtj||j��}|jdkrtj||j��}||fS)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�D�g|]}tj|t�����S)r)r�asarrayrL)�.0�bs  r3�
<listcomp>z#_prepare_bounds.<locals>.<listcomp>�s'��
9�
9�
9�Q�b�j��%�(�(�(�
9�
9�
9r5r)�ndimr�resize�shape)�boundsr r$r%s    r3�_prepare_boundsr_�s`��:�
9�&�
9�
9�
9�F�B��	�w�!�|�|�
�Y�r�2�8�
$�
$��	�w�!�|�|�
�Y�r�2�8�
$�
$��
�r�6�Mr5c��t|��rt|��}n7tj|��}|dk�tj��}|jdkrtd���|j\}}|�tj	|��r5tj
�|��}|�|��}n/tj
|��}|j|fkrtd���|dd�|f}t|��rt|||j|j��}nt#|||��}|���||<|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 matrix, 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.
    rrz`A` must be 2-dimensional.Nz`order` has incorrect shape.)rrr�
atleast_2drK�int32r[rr]�isscalar�random�RandomState�permutationrWr
�indices�indptrrr)�A�order�m�n�rng�groupss      r3�
group_columnsro�s1��<��{�{�&��q�M�M����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��Mr5r9F�c
�6��	�
�|dvrtd|z���tj|��}|jdkrtd���t	||��\}}|j|jks|j|jkrtd���|r[tjtj|����r&tjtj|����std����	��
fd�}
|�|
|��}n.tj|��}|jdkrtd	���tj||k||kz��rtd
���|r0|�t|j
|j
|��}t|
||||��S|�t||||��}n�|dk�
t��dzdz
}|}||z|z
}tj|dkt|j
|j
|��|ztjd
tj|����z|��}|dkrt%||dd||��\}}n&|dkrt%||dd||��\}}n|dkrd}|�t'|
|||||��St)|��st+|��dkr|\}}n|}t-|��}t)|��rt/|��}ntj|��}tj|��}t3|
|||||||��S)aJCompute 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 matrix, 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 matrix 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 matrix 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 matrix 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)``.

    Returns
    -------
    J : {ndarray, sparse matrix, 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
        matrix 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_matrix with shape (m, n).
        For sparse matrices 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,).

    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.])
    )r7r9r8zUnknown method '%s'. rz#`x0` must have at most 1 dimension.z,Inconsistent shapes between bounds and `x0`.z7Bounds not supported when `as_linear_operator` is True.c�x��tj�|g��Ri�����}|jdkrtd���|S)Nrz-`fun` return value has more than 1 dimension.)r�
atleast_1dr[r@)r+�f�args�fun�kwargss  ���r3�fun_wrappedz&approx_derivative.<locals>.fun_wrapped�sS����M�#�#�a�1�$�1�1�1�&�1�1�2�2���6�A�:�:�� 8�9�9�
9��r5Nz&`f0` passed has more than 1 dimension.z `x0` violates bound constraints.rrrJr7rr9rr8F)rrrsr[r_r]r�isinf�anyrHr�_linear_operator_differencerTrKrLrMrrr4�_dense_differencer�lenrorra�_sparse_difference)rvr rCrNrRrOr^�sparsity�as_linear_operatorrurwr$r%rxr!rPrSr&�	structurerns`        ``         r3�approx_derivativer�s������F�1�1�1��0�6�9�:�:�:�	��r�	�	�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�:�:�	:��������
�z�
�[��_�_���
�]�2�
�
��
�7�Q�;�;��E�F�F�F�	�v�r�B�w�2��7�#�$�$�=��;�<�<�<��26���&�r�x���6�B�B�H�*�;��+-�x��A�A�	A���&�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���$�[�"�b�!�%2�F�<�<�
<��H�%�%�
1�#�h�-�-�1�*<�*<�$,�!�	�6�6�$�	�&�x�0�0���	�"�"�
5�&�y�1�1�	�	��M�)�4�4�	��]�6�*�*�F�%�k�2�r�1�&3�Y�&,�f�6�6�
6r5c���������j��j}|dkr
�����fd�}n-|dkr	����fd�}n|dkr	����fd�}ntd���t�|f|��S)Nr7c����tj|tj|����rtj���S�t	|��z}�||zz}�|���z
}||zS)N�r�array_equalr�zerosr)	�prSr+�dfrOrvr!rkr s	    �����r3�matvecz+_linear_operator_difference.<locals>.matvecse����~�a���q�!1�!1�2�2�
#��x��{�{�"��T�!�W�W��B��R��T�	�A���Q���"��B���7�Nr5r9c���tj|tj|����rtj�	��Sd�zt	|��z}�
|dz|zz
}�
|dz|zz}�|��}�|��}||z
}||zS)Nrr�)r�rS�x1�x2�f1�f2r�rvr!rkr s       ����r3r�z+_linear_operator_difference.<locals>.matvecs�����~�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�Nr5r8c����tj|tj|����rtj���S�t	|��z}�||zdzz}�|��}|j}||zS)N��?)rr�rr�r�imag)	r�rSr+r�r�rvr!rkr s	     ����r3r�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�Nr5�Never be here.)�sizer@r)rvr rOr!rCrlr�rks````   @r3r{r{
s��������
��A�
��A�
����	�	�	�	�	�	�	�	�	�	�
�9�	�	�		�		�		�		�		�		�		�		�		�
�4���	�	�	�	�	�	�	�	�	��+�,�,�,��1�a�&�&�)�)�)r5c�0�|j}|j}tj||f��}tj|��}	t	|j��D�](}
|dkr+||	|
z}||
||
z
}||��|z
}
n�|dkrW||
rO||	|
z}|d|	|
zz}||
||
z
}||��}||��}d|zd|zz|z
}
n�|dkrK||
sC||	|
z
}||	|
z}||
||
z
}||��}||��}||z
}
n>|dkr)|||	|
dzz��}|j}
|	|
|
f}nt
d���|
|z||
<��*|d	krtj|��}|jS)
Nr7r9rg��r8r�r�r)	r�r�empty�diag�ranger�r@�ravel�T)rvr rOr!r&rCrkrl�J_transposed�h_vecs�ir+rSr�r�r�r�r�s                  r3r|r|6s���
��A�
��A��8�Q��F�#�#�L�
�W�Q�Z�Z�F�
�1�6�]�]�"�"���Y����V�A�Y��A��1���1���B���Q���"��B�B�
�y�
 �
 �]�1�%5�
 ��f�Q�i��B��a�&��)�m�#�B��A���A���B���R���B���R���B����Q��V�#�b�(�B�B�
�y�
 �
 ��q�)9�
 ��f�Q�i��B��f�Q�i��B��A���A���B���R���B���R���B��b��B�B�
�t�^�^���R�&��)�C�-�'�(�(�B���B���1���B�B��/�0�0�0��r�'��Q����A�v�v��x��-�-���>�r5c��|j}|j}	g}
g}g}tj|��dz}
t|
��D�]�}tj||��}||z}|dkrU||z}||z
}||��|z
}tj|��\}t
|dd�|f��\}}}||}�n�|dk�r�|���}|���}||z}||xx||z
cc<||xxd||zz
cc<||z}||xx||zcc<||xx||z
cc<tj|	��}||||z
||<||||z
||<||��}||��}tj|��\}t
|dd�|f��\}}}||}||}tj	|��}||}d||zd||zz||z
||<||}||||z
||<nk|dkrV|||dzz��}|j
}|}tj|��\}t
|dd�|f��\}}}||}ntd	���|
�|��|�|��|�||||z�����tj
|
��}
tj
|��}tj
|��}t||
|ff||	f�
��} t| ��S)Nrr7r9r���r�r8r�r�)r])r�r�maxr��equal�nonzeror
rr�r�r�r�append�hstackr	r)!rvr rOr!r&r�rnrCrkrl�row_indices�col_indices�	fractions�n_groups�group�e�h_vecr+rSr��colsr��j�_r�r��mask_1�mask_2r�r��mask�rows�Js!                                 r3r~r~^s���
��A�
��A��K��K��I��v�f�~�~��!�H��x���>(�>(���H�U�F�#�#���A����Y����U�
�A��R��B���Q���"��B��J�q�M�M�E�D��9�Q�Q�Q��W�-�.�.�G�A�q�!��Q��A�A�
�y�
 �
 ������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���!���B��F��b��j�0�B�v�J��F��b��j�0�B�v�J���R���B���R���B��J�q�M�M�E�D��9�Q�Q�Q��W�-�.�.�G�A�q�!��Q��A� ��#�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�^�^���R�%��)�^�$�$�B���B��B��J�q�M�M�E�D��9�Q�Q�Q��W�-�.�.�G�A�q�!��Q��A�A��-�.�.�.�	���1�������1��������A���A���'�'�'�'��)�K�(�(�K��)�K�(�(�K��	�)�$�$�I��I��[�9�:�1�a�&�I�I�I�A��a�=�=�r5c	�v�||g|�Ri|��}t|��r�t||||||���}t|��}||z
}t|��\}	}
}t	j||	|
f�����}t	jt	j|��t	j	dt	j|����z��St|||||���}t	j||z
��}t	j|t	j	dt	j|����z��S)aT	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 matrix 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
    )r^rrurwr)r^rurw)
rr�rr
rrWr�r�rr)
rv�jacr r^rurw�	J_to_test�J_diff�abs_errr�r��abs_err_data�J_diff_datas
             r3�check_derivativer��s=��z��B�(��(�(�(��(�(�I��	���
?�"�3��6�I�(,�V�=�=�=���y�)�)�	��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� =� =�=�>�>�>r5)r)�__doc__�	functools�numpyr�numpy.linalgr�scipy.sparse.linalgr�sparserrrr	r
�_group_columnsrr
r4�	lru_cacherHrTr_rorr�r{r|r~r�rpr5r3�<module>r�s���-�-���������������.�.�.�.�.�.�G�G�G�G�G�G�G�G�G�G�G�G�G�G�5�5�5�5�5�5�5�5�L%�L%�L%�^�����2;�2;���2;�j.�.�.�b���*:�:�:�:�z'0�$�����w���&7�$�).�R��w6�w6�w6�w6�t&*�&*�&*�R%�%�%�PM�M�M�`-/�F�7�B�F�*;�"��K?�K?�K?�K?�K?�K?r5

Youez - 2016 - github.com/yon3zu
LinuXploit