Ë
    âQ(hüO  ã                   óB  — d Z ddlmZ ddlZddlmZ ddlmZm	Z	m
Z
 ddlmZ ddlmZmZ  ej                   e«      j$                  Zd„ Z	 	 d"d	„Zd
„ Zd„ Zd#d„Zd$d„Zd%d„Zd„ Zd„ Zd&d„Zd&d„Zd„ Zd„ Z d„ Z!d„ Z"d„ Z#d„ Z$d„ Z%d%d„Z&d„ Z'd„ Z(d„ Z)d'd„Z*d'd„Z+d „ Z,d!„ Z-y)(z+Functions used by least-squares algorithms.é    )ÚcopysignN)Únorm)Ú
cho_factorÚ	cho_solveÚLinAlgError)Úissparse)ÚLinearOperatorÚaslinearoperatorc                 ó\  — t        j                  ||«      }|dk(  rt        d«      ‚t        j                  | |«      }t        j                  | | «      |dz  z
  }|dkD  rt        d«      ‚t        j                  ||z  ||z  z
  «      }|t	        ||«      z    }||z  }||z  }	||	k  r||	fS |	|fS )aq  Find the intersection of a line with the boundary of a trust region.

    This function solves the quadratic equation with respect to t
    ||(x + s*t)||**2 = Delta**2.

    Returns
    -------
    t_neg, t_pos : tuple of float
        Negative and positive roots.

    Raises
    ------
    ValueError
        If `s` is zero or `x` is not within the trust region.
    r   z`s` is zero.é   z#`x` is not within the trust region.)ÚnpÚdotÚ
ValueErrorÚsqrtr   )
ÚxÚsÚDeltaÚaÚbÚcÚdÚqÚt1Út2s
             úX/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/scipy/optimize/_lsq/common.pyÚintersect_trust_regionr      s¹   € ô  	�‰ˆq�!‹€AØˆA‚vÜ˜Ó(Ð(ä
�‰ˆq�!‹€Aä
�‰ˆq�!‹�u˜a‘xÑ€AØˆ1‚uÜÐ>Ó?Ð?ä
�‰��!‘�a˜‘c‘	Ó€Að Œh�q˜!‹nÑ
Ð€AØ	
ˆQ‰€BØ	
ˆQ‰€Bà	ˆB‚wØ�2ˆvˆà�2ˆvˆó    c	                 ó¢  — d„ }	||z  }
|| k\  rt         |z  |d   z  }|d   |kD  }nd}|r(|j                  ||z  «       }t        |«      |k  r|ddfS t        |
«      |z  }|r |	d|
||«      \  }}| |z  }nd}|�|s|dk(  rt        d|z  ||z  dz  «      }n|}t	        |«      D ]u  }||k  s||kD  rt        d|z  ||z  dz  «      } |	||
||«      \  }}|dk  r|}||z  }t        |||z
  «      }|||z   |z  |z  z  }t        j                  |«      ||z  k  sŒu n |j                  |
|dz  |z   z  «       }||t        |«      z  z  }||d	z   fS )
aÁ  Solve a trust-region problem arising in least-squares minimization.

    This function implements a method described by J. J. More [1]_ and used
    in MINPACK, but it relies on a single SVD of Jacobian instead of series
    of Cholesky decompositions. Before running this function, compute:
    ``U, s, VT = svd(J, full_matrices=False)``.

    Parameters
    ----------
    n : int
        Number of variables.
    m : int
        Number of residuals.
    uf : ndarray
        Computed as U.T.dot(f).
    s : ndarray
        Singular values of J.
    V : ndarray
        Transpose of VT.
    Delta : float
        Radius of a trust region.
    initial_alpha : float, optional
        Initial guess for alpha, which might be available from a previous
        iteration. If None, determined automatically.
    rtol : float, optional
        Stopping tolerance for the root-finding procedure. Namely, the
        solution ``p`` will satisfy ``abs(norm(p) - Delta) < rtol * Delta``.
    max_iter : int, optional
        Maximum allowed number of iterations for the root-finding procedure.

    Returns
    -------
    p : ndarray, shape (n,)
        Found solution of a trust-region problem.
    alpha : float
        Positive value such that (J.T*J + alpha*I)*p = -J.T*f.
        Sometimes called Levenberg-Marquardt parameter.
    n_iter : int
        Number of iterations made by root-finding procedure. Zero means
        that Gauss-Newton step was selected as the solution.

    References
    ----------
    .. [1] More, J. J., "The Levenberg-Marquardt Algorithm: Implementation
           and Theory," Numerical Analysis, ed. G. A. Watson, Lecture Notes
           in Mathematics 630, Springer Verlag, pp. 105-116, 1977.
    c                 ó„   — |dz  | z   }t        ||z  «      }||z
  }t        j                  |dz  |dz  z  «       |z  }||fS )z Function of which to find zero.

        It is defined as "norm of regularized (by alpha) least-squares
        solution minus `Delta`". Refer to [1]_.
        r   é   )r   r   Úsum)ÚalphaÚsufr   r   ÚdenomÚp_normÚphiÚ	phi_primes           r   Úphi_and_derivativez2solve_lsq_trust_region.<locals>.phi_and_derivativej   sU   € ð �1‘�u‘ˆÜ�c˜E‘kÓ"ˆØ�u‰nˆÜ—V‘V˜C 1™H u¨a¡xÑ/Ó0Ð0°6Ñ9ˆ	Ø�Iˆ~Ðr   r   éÿÿÿÿFg        gü©ñÒMbP?ç      à?r   é   )ÚEPSr   r   ÚmaxÚranger   Úabs)ÚnÚmÚufr   ÚVr   Úinitial_alphaÚrtolÚmax_iterr(   r#   Ú	thresholdÚ	full_rankÚpÚalpha_upperr&   r'   Úalpha_lowerr"   ÚitÚratios                        r   Úsolve_lsq_trust_regionr>   9   s½  € òb
ð ˆb‰&€Cð 	ˆA‚vÜ˜!‘G˜a ™d‘Nˆ	Ø�b‘E˜IÑ%‰	àˆ	áØ�U‰U�2˜‘6‹]ˆNˆÜ�‹7�eÒØ�c˜1�9Ðä�s“)˜eÑ#€KáÙ+¨C°°a¸Ó?‰ˆˆYØ�d˜YÑ&‰àˆàÐ¡I°-À1Ò2DÜ�E˜KÑ'¨+¸Ñ*CÀcÑ)IÓJ‰àˆä�H‹oò ˆØ�;Ò %¨+Ò"5Ü˜ Ñ+¨k¸KÑ.GÈ#Ñ-MÓNˆEá+¨E°3¸¸5ÓA‰ˆˆYà�Š7ØˆKà�i‘ˆÜ˜+ u¨u¡}Ó5ˆØ�#˜‘+ Ñ&¨Ñ.Ñ.ˆä�6‰6�#‹;˜ ™Ó%Ùðð  
�‰ˆs�a˜‘d˜U‘lÑ#Ó	$Ð$€Að
 ˆ”�a“‰Ñ€Aàˆe�R˜!‘VÐÐr   c                 ó&  — 	 t        | «      \  }}t        ||f|«       }t        j                  ||«      |dz  k  r|dfS 	 | d   |dz  z  }| d   |dz  z  }| d   |dz  z  }|d   |z  }	|d   |z  }
t        j
                  | |	z   d||z
  |
z   z  d|z  d| |z   |
z   z  | |	z
  g«      }t        j                  |«      }t        j                  |t        j                  |«         «      }|t        j                  d|z  d|dz  z   z  d|dz  z
  d|dz  z   z  f«      z  }d	t        j                  || j                  |«      z  d¬
«      z  t        j                  ||«      z   }t        j                  |«      }|dd…|f   }|dfS # t        $ r Y �ŒOw xY w)az  Solve a general trust-region problem in 2 dimensions.

    The problem is reformulated as a 4th order algebraic equation,
    the solution of which is found by numpy.roots.

    Parameters
    ----------
    B : ndarray, shape (2, 2)
        Symmetric matrix, defines a quadratic term of the function.
    g : ndarray, shape (2,)
        Defines a linear term of the function.
    Delta : float
        Radius of a trust region.

    Returns
    -------
    p : ndarray, shape (2,)
        Found solution.
    newton_step : bool
        Whether the returned solution is the Newton step which lies within
        the trust region.
    r   T)r   r   )r   r+   )r+   r+   r   r+   é   r*   ©ÚaxisNF)r   r   r   r   r   ÚarrayÚrootsÚrealÚisrealÚvstackr!   Úargmin)ÚBÚgr   ÚRÚlowerr9   r   r   r   r   ÚfÚcoeffsÚtÚvalueÚis                  r   Úsolve_trust_region_2drR   «   s³  € ð.Ü˜a“=‰ˆˆ5Ü˜˜5�z 1Ó%Ð%ˆÜ�6‰6�!�Q‹<˜5 !™8Ò#Ø�d�7ˆNð $ð
 	
ˆ$‰�%˜‘(Ñ€AØ	ˆ$‰�%˜‘(Ñ€AØ	ˆ$‰�%˜‘(Ñ€Aà	ˆ!‰ˆu‰€AØ	ˆ!‰ˆu‰€Aä�X‰XØ
ˆˆa‰��a˜!‘e˜a‘i‘ ! a¡%¨¨q¨b°1©f°q©jÑ)9¸A¸2À¹6ÐBóD€Fä
�‰�Ó€AÜ
�‰�”"—)‘)˜A“,‘Ó €Aà”—	‘	˜1˜q™5 A¨¨1©¡HÑ-°°A°q±D±¸QÀÀAÁ¹XÑ/FÐGÓHÑH€AØ”"—&‘&˜˜QŸU™U 1›X™¨AÔ.Ñ.´·±¸¸1³Ñ=€EÜ
�	‰	�%Ó€AØ	Š!ˆQˆ$‰€Aàˆeˆ8€Oøô) ò Úðús   ‚<F Æ	FÆFc                 óz   — |dkD  r||z  }n||cxk(  rdk(  rn nd}nd}|dk  r	d|z  } | |fS |dkD  r|r| dz  } | |fS )zÍUpdate the radius of a trust region based on the cost reduction.

    Returns
    -------
    Delta : float
        New radius.
    ratio : float
        Ratio between actual and predicted reductions.
    r   r+   ç      Ð?g      è?g       @© )r   Úactual_reductionÚpredicted_reductionÚ	step_normÚ	bound_hitr=   s         r   Úupdate_tr_radiusrZ   Þ   sj   € ð ˜QÒØ Ð#6Ñ6‰Ø	Ð 0Ô	5°AÕ	5Ø‰àˆàˆt‚|Ø�yÑ ˆð �%ˆ<Ðð 
�Š™)Ø�‰ˆà�%ˆ<Ðr   c                 ó  — | j                  |«      }t        j                   ||«      }|�|t        j                   ||z  |«      z  }|dz  }t        j                   ||«      }|�œ| j                  |«      }|t        j                   ||«      z  }dt        j                   ||«      z  t        j                   ||«      z   }	|�;|t        j                   ||z  |«      z  }|	dt        j                   ||z  |«      z  z  }	|||	fS ||fS )a­  Parameterize a multivariate quadratic function along a line.

    The resulting univariate quadratic function is given as follows::

        f(t) = 0.5 * (s0 + s*t).T * (J.T*J + diag) * (s0 + s*t) +
               g.T * (s0 + s*t)

    Parameters
    ----------
    J : ndarray, sparse matrix or LinearOperator shape (m, n)
        Jacobian matrix, affects the quadratic term.
    g : ndarray, shape (n,)
        Gradient, defines the linear term.
    s : ndarray, shape (n,)
        Direction vector of a line.
    diag : None or ndarray with shape (n,), optional
        Addition diagonal part, affects the quadratic term.
        If None, assumed to be 0.
    s0 : None or ndarray with shape (n,), optional
        Initial point. If None, assumed to be 0.

    Returns
    -------
    a : float
        Coefficient for t**2.
    b : float
        Coefficient for t.
    c : float
        Free term. Returned only if `s0` is provided.
    r*   )r   r   )
ÚJrJ   r   ÚdiagÚs0Úvr   r   Úur   s
             r   Úbuild_quadratic_1dra   û   sñ   € ð> 	
�‰ˆa‹€AÜ
�‰ˆq�!‹€AØÐØ	ŒR�V‰V�A˜‘H˜aÓ Ñ ˆØˆ�H€Aä
�‰ˆq�!‹€Aà	€~Ø�E‰E�"‹IˆØ	ŒR�V‰V�A�q‹\ÑˆØ”"—&‘&˜˜A“,Ñ¤§¡¨¨2£Ñ.ˆØÐØ”—‘˜˜T™	 1Ó%Ñ%ˆAØ�”r—v‘v˜b 4™i¨Ó,Ñ,Ñ,ˆAØ�!�Qˆwˆà�!ˆtˆr   c                 óæ   — ||g}| dk7  r'd|z  | z  }||cxk  r|k  rn n|j                  |«       t        j                  |«      }|| |z  |z   z  |z   }t        j                  |«      }||   ||   fS )zÛMinimize a 1-D quadratic function subject to bounds.

    The free term `c` is 0 by default. Bounds must be finite.

    Returns
    -------
    t : float
        Minimum point.
    y : float
        Minimum value.
    r   g      à¿)Úappendr   ÚasarrayrH   )	r   r   ÚlbÚubr   rO   ÚextremumÚyÚ	min_indexs	            r   Úminimize_quadratic_1drj   .  s}   € ð 
ˆRˆ€AØˆA‚vØ˜!‘8˜a‘<ˆØ�Ô˜2ÕØ�H‰H�XÔÜ
�
‰
�1‹€AØ	ˆQ�‰U�Q‰Y‰˜!Ñ€AÜ—	‘	˜!“€IØˆY‰<˜˜9™Ð%Ð%r   c                 ó–  — |j                   dk(  rF| j                  |«      }t        j                  ||«      }|�t|t        j                  ||z  |«      z  }nW| j                  |j                  «      }t        j                  |dz  d¬«      }|� |t        j                  ||dz  z  d¬«      z  }t        j                  ||«      }d|z  |z   S )aì  Compute values of a quadratic function arising in least squares.

    The function is 0.5 * s.T * (J.T * J + diag) * s + g.T * s.

    Parameters
    ----------
    J : ndarray, sparse matrix or LinearOperator, shape (m, n)
        Jacobian matrix, affects the quadratic term.
    g : ndarray, shape (n,)
        Gradient, defines the linear term.
    s : ndarray, shape (k, n) or (n,)
        Array containing steps as rows.
    diag : ndarray, shape (n,), optional
        Addition diagonal part, affects the quadratic term.
        If None, assumed to be 0.

    Returns
    -------
    values : ndarray with shape (k,) or float
        Values of the function. If `s` was 2-D, then ndarray is
        returned, otherwise, float is returned.
    r+   r   r   rA   r*   )Úndimr   r   ÚTr!   )r\   rJ   r   r]   ÚJsr   Úls          r   Úevaluate_quadraticrp   E  s¯   € ð. 	‡v�v�‚{Ø�U‰U�1‹XˆÜ�F‰F�2�r‹NˆØÐØ”—‘˜˜D™ !Ó$Ñ$‰Aà�U‰U�1—3‘3‹ZˆÜ�F‰F�2�q‘5˜qÔ!ˆØÐØ”—‘˜˜q !™t™¨!Ô,Ñ,ˆAä
�‰ˆq�!‹€Aà�‰7�Q‰;Ðr   c                 ó>   — t        j                  | |k\  | |k  z  «      S )z$Check if a point lies within bounds.)r   Úall)r   re   rf   s      r   Ú	in_boundsrs   o  s   € ä�6‰6�1˜‘7˜q B™wÑ'Ó(Ð(r   c                 óö  — t        j                  |«      }||   }t        j                  | «      }|j                  t         j                  «       t        j
                  d¬«      5  t        j                  || z
  |   |z  || z
  |   |z  «      ||<   ddd«       t        j                  |«      }|t        j                  ||«      t        j                  |«      j                  t        «      z  fS # 1 sw Y   Œ_xY w)að  Compute a min_step size required to reach a bound.

    The function computes a positive scalar t, such that x + s * t is on
    the bound.

    Returns
    -------
    step : float
        Computed step. Non-negative value.
    hits : ndarray of int with shape of x
        Each element indicates whether a corresponding variable reaches the
        bound:

             *  0 - the bound was not hit.
             * -1 - the lower bound was hit.
             *  1 - the upper bound was hit.
    Úignore)ÚoverN)r   ÚnonzeroÚ
empty_likeÚfillÚinfÚerrstateÚmaximumÚminÚequalÚsignÚastypeÚint)r   r   re   rf   Únon_zeroÚ
s_non_zeroÚstepsÚmin_steps           r   Ústep_size_to_boundr†   t  sÎ   € ô$ �z‰z˜!‹}€HØ�8‘€JÜ�M‰M˜!Ó€EØ	‡J�JŒr�v‰vÔÜ	�‰˜(Ô	#ñ FÜŸ*™* b¨1¡f¨hÑ%7¸*Ñ%DØ&(¨1¡f¨hÑ%7¸*Ñ%DóFˆˆh‰÷Fô �v‰v�e‹}€HØ”R—X‘X˜e XÓ.´·±¸³×1BÑ1BÄ3Ó1GÑGÐGÐG÷	Fð Fús   Á%,C/Ã/C8c                 óþ  — t        j                  | t        ¬«      }|dk(  rd|| |k  <   d|| |k\  <   |S | |z
  }|| z
  }|t        j                  dt        j                  |«      «      z  }|t        j                  dt        j                  |«      «      z  }t        j
                  |«      |t        j                  ||«      k  z  }	d||	<   t        j
                  |«      |t        j                  ||«      k  z  }
d||
<   |S )a·  Determine which constraints are active in a given point.

    The threshold is computed using `rtol` and the absolute value of the
    closest bound.

    Returns
    -------
    active : ndarray of int with shape of x
        Each component shows whether the corresponding constraint is active:

             *  0 - a constraint is not active.
             * -1 - a lower bound is active.
             *  1 - a upper bound is active.
    ©Údtyper   r)   r+   )r   Ú
zeros_liker�   r|   r/   ÚisfiniteÚminimum)r   re   rf   r5   ÚactiveÚ
lower_distÚ
upper_distÚlower_thresholdÚupper_thresholdÚlower_activeÚupper_actives              r   Úfind_active_constraintsr”   ‘  së   € ô �]‰]˜1¤CÔ(€Fàˆq‚yØˆˆq�B‰w‰Øˆˆq�B‰w‰Øˆà�R‘€JØ�a‘€JàœRŸZ™Z¨¬2¯6©6°"«:Ó6Ñ6€OØœRŸZ™Z¨¬2¯6©6°"«:Ó6Ñ6€Oä—K‘K “OØ¤2§:¡:¨j¸/Ó#JÑJñL€Là€Fˆ<Ñä—K‘K “OØ¤2§:¡:¨j¸/Ó#JÑJñL€Là€Fˆ<Ñà€Mr   c           	      ó:  — | j                  «       }t        | |||«      }t        j                  |d«      }t        j                  |d«      }|dk(  r?t        j                  ||   ||   «      ||<   t        j                  ||   ||   «      ||<   np||   |t        j
                  dt        j                  ||   «      «      z  z   ||<   ||   |t        j
                  dt        j                  ||   «      «      z  z
  ||<   ||k  ||kD  z  }d||   ||   z   z  ||<   |S )zÔShift a point to the interior of a feasible region.

    Each element of the returned vector is at least at a relative distance
    `rstep` from the closest bound. If ``rstep=0`` then `np.nextafter` is used.
    r)   r+   r   r*   )Úcopyr”   r   r~   Ú	nextafterr|   r/   )	r   re   rf   ÚrstepÚx_newr�   Ú
lower_maskÚ
upper_maskÚtight_boundss	            r   Úmake_strictly_feasibler�   ¸  s  € ð �F‰F‹H€Eä$ Q¨¨B°Ó6€FÜ—‘˜& "Ó%€JÜ—‘˜& !Ó$€Jà�‚zÜŸL™L¨¨J©¸¸J¹ÓHˆˆjÑÜŸL™L¨¨J©¸¸J¹ÓHˆˆjÒà 
™^Ø"¤R§Z¡Z°´2·6±6¸"¸Z¹.Ó3IÓ%JÑJñKˆˆjÑà 
™^Ø"¤R§Z¡Z°´2·6±6¸"¸Z¹.Ó3IÓ%JÑJñKˆˆjÑð ˜B‘J 5¨2¡:Ñ.€LØ  LÑ!1°B°|Ñ4DÑ!DÑE€Eˆ,Ñà€Lr   c                 ó  — t        j                  | «      }t        j                  | «      }|dk  t        j                  |«      z  }||   | |   z
  ||<   d||<   |dkD  t        j                  |«      z  }| |   ||   z
  ||<   d||<   ||fS )a4  Compute Coleman-Li scaling vector and its derivatives.

    Components of a vector v are defined as follows::

               | ub[i] - x[i], if g[i] < 0 and ub[i] < np.inf
        v[i] = | x[i] - lb[i], if g[i] > 0 and lb[i] > -np.inf
               | 1,           otherwise

    According to this definition v[i] >= 0 for all i. It differs from the
    definition in paper [1]_ (eq. (2.2)), where the absolute value of v is
    used. Both definitions are equivalent down the line.
    Derivatives of v with respect to x take value 1, -1 or 0 depending on a
    case.

    Returns
    -------
    v : ndarray with shape of x
        Scaling vector.
    dv : ndarray with shape of x
        Derivatives of v[i] with respect to x[i], diagonal elements of v's
        Jacobian.

    References
    ----------
    .. [1] M.A. Branch, T.F. Coleman, and Y. Li, "A Subspace, Interior,
           and Conjugate Gradient Method for Large-Scale Bound-Constrained
           Minimization Problems," SIAM Journal on Scientific Computing,
           Vol. 21, Number 1, pp 1-23, 1999.
    r   r)   r+   )r   Ú	ones_likerŠ   r‹   )r   rJ   re   rf   r_   ÚdvÚmasks          r   ÚCL_scaling_vectorr¢   Ó  s’   € ô< 	�‰�Q‹€AÜ	�‰�qÓ	€Bà�‰E”R—[‘[ “_Ñ$€DØ�‰h˜˜4™Ñ €A€d�GØ€B€t�Hà�‰E”R—[‘[ “_Ñ$€DØ�‰g˜˜4™Ñ €A€d�GØ€B€t�Hàˆbˆ5€Lr   c                 óä  — t        | ||«      r| t        j                  | «      fS t        j                  |«      }t        j                  |«      }| j	                  «       }t        j
                  | t        ¬«      }|| z  }t        j                  | |   d||   z  | |   z
  «      ||<   | |   ||   k  ||<   | |z  }t        j                  | |   d||   z  | |   z
  «      ||<   | |   ||   kD  ||<   ||z  }||z
  }t        j                  | |   ||   z
  d||   z  «      }	||   t        j                  |	d||   z  |	z
  «      z   ||<   |	||   kD  ||<   t        j                  | «      }
d|
|<   ||
fS )z3Compute reflective transformation and its gradient.rˆ   r   r)   )
rs   r   rŸ   r‹   r–   rŠ   Úboolr|   rŒ   Ú	remainder)rh   re   rf   Ú	lb_finiteÚ	ub_finiter   Ú
g_negativer¡   r   rO   rJ   s              r   Úreflective_transformationr©   ÿ  s€  € ä��B˜ÔØ”"—,‘,˜q“/Ð!Ð!ä—‘˜B“€IÜ—‘˜B“€Ià	�‰‹€AÜ—‘˜q¬Ô-€Jà˜	�zÑ!€DÜ�j‰j˜˜4™ ! b¨¡h¡,°°4±Ñ"8Ó9€A€d�GØ˜‘w  D¡Ñ)€JˆtÑàˆ:˜	Ñ!€DÜ�j‰j˜˜4™ ! b¨¡h¡,°°4±Ñ"8Ó9€A€d�GØ˜‘w  D¡Ñ)€JˆtÑà�yÑ €DØ
ˆR‰€AÜ
�‰�Q�t‘W˜r $™xÑ'¨¨Q¨t©W©Ó5€AØ�‰hœŸ™ A q¨1¨T©7¡{°Q¡Ó7Ñ7€A€d�GØ˜1˜T™7‘{€JˆtÑä
�‰�Q‹€AØ€A€j�Màˆaˆ4€Kr   c            
      óB   — t        dj                  dddddd«      «       y )Nz${:^15}{:^15}{:^15}{:^15}{:^15}{:^15}Ú	Iterationz
Total nfevÚCostúCost reductionú	Step normÚ
Optimality©ÚprintÚformatrU   r   r   Úprint_header_nonlinearr³   !  s%   € Ü	Ð
0ß‰6�+˜|¨VÐ5EØ˜|ó-õ.r   c           	      ó^   — |€d}n|d›}|€d}n|d›}t        | d›|d›|d›|› |› |d›�«       y ©Nz               z^15.2ez^15z^15.4e©r±   )Ú	iterationÚnfevÚcostÚcost_reductionrX   Ú
optimalitys         r   Úprint_iteration_nonlinearr¼   '  sX   € àÐØ!‰à*¨6Ð2ˆàÐØ‰	à  Ð(ˆ	ä	ˆY�sˆO˜D ˜: d¨6 ]°>Ð2BÀ9À+ÈjÐY_ÐM`Ð
aÕbr   c            	      ó@   — t        dj                  ddddd«      «       y )Nz{:^15}{:^15}{:^15}{:^15}{:^15}r«   r¬   r­   r®   r¯   r°   rU   r   r   Úprint_header_linearr¾   6  s#   € Ü	Ð
*ß‰6�+˜vÐ'7¸Øó õ!r   c                 óX   — |€d}n|d›}|€d}n|d›}t        | d›|d›|› |› |d›�«       y rµ   r¶   )r·   r¹   rº   rX   r»   s        r   Úprint_iteration_linearrÀ   <  sQ   € àÐØ!‰à*¨6Ð2ˆàÐØ‰	à  Ð(ˆ	ä	ˆY�sˆO˜D ˜=¨Ð(8¸¸ÀJÈvÐCVÐ
WÕXr   c                 óz   — t        | t        «      r| j                  |«      S | j                  j	                  |«      S )z4Compute gradient of the least-squares cost function.)Ú
isinstancer	   Úrmatvecrm   r   )r\   rM   s     r   Úcompute_gradrÄ   N  s,   € ä�!”^Ô$Ø�y‰y˜‹|Ðà�s‰s�w‰w�q‹zÐr   c                 ó.  — t        | «      rFt        j                  | j                  d«      j	                  d¬«      «      j                  «       dz  }nt        j                  | dz  d¬«      dz  }|€	d||dk(  <   nt        j                  ||«      }d|z  |fS )z5Compute variables scale based on the Jacobian matrix.r   r   rA   r*   r+   )r   r   rd   Úpowerr!   Úravelr|   )r\   Úscale_inv_oldÚ	scale_invs      r   Úcompute_jac_scalerÊ   V  s„   € ä�„{Ü—J‘J˜qŸw™w q›zŸ~™~°1˜~Ó5Ó6×<Ñ<Ó>ÀÑC‰	ä—F‘F˜1˜a™4 aÔ(¨#Ñ-ˆ	àÐØ$%ˆ	�)˜q‘.Ò!ä—J‘J˜y¨-Ó8ˆ	àˆy‰=˜)Ð#Ð#r   c                 ór   ‡ ‡— t        ‰ «      Š ˆ ˆfd„}ˆ ˆfd„}ˆ ˆfd„}t        ‰ j                  |||¬«      S )z#Return diag(d) J as LinearOperator.c                 ó,   •— ‰‰j                  | «      z  S ©N)Úmatvec©r   r\   r   s    €€r   rÎ   z(left_multiplied_operator.<locals>.matveci  s   ø€ Ø�1—8‘8˜A“;‰Ðr   c                 óV   •— ‰d d …t         j                  f   ‰j                  | «      z  S rÍ   )r   ÚnewaxisÚmatmat©ÚXr\   r   s    €€r   rÒ   z(left_multiplied_operator.<locals>.matmatl  s#   ø€ Ø’”B—J‘J�Ñ !§(¡(¨1£+Ñ-Ð-r   c                 óH   •— ‰j                  | j                  «       ‰z  «      S rÍ   )rÃ   rÇ   rÏ   s    €€r   rÃ   z)left_multiplied_operator.<locals>.rmatveco  s   ø€ Ø�y‰y˜Ÿ™› Q™Ó'Ð'r   ©rÎ   rÒ   rÃ   ©r
   r	   Úshape©r\   r   rÎ   rÒ   rÃ   s   ``   r   Úleft_multiplied_operatorrÚ   e  s8   ù€ ä˜Ó€Aõõ.õ(ô ˜!Ÿ'™'¨&¸Ø")ô+ð +r   c                 ór   ‡ ‡— t        ‰ «      Š ˆ ˆfd„}ˆ ˆfd„}ˆ ˆfd„}t        ‰ j                  |||¬«      S )z#Return J diag(d) as LinearOperator.c                 óR   •— ‰j                  t        j                  | «      ‰z  «      S rÍ   )rÎ   r   rÇ   rÏ   s    €€r   rÎ   z)right_multiplied_operator.<locals>.matvecz  s   ø€ Ø�x‰xœŸ™ › a™Ó(Ð(r   c                 óV   •— ‰j                  | ‰d d …t        j                  f   z  «      S rÍ   )rÒ   r   rÑ   rÓ   s    €€r   rÒ   z)right_multiplied_operator.<locals>.matmat}  s$   ø€ Ø�x‰x˜˜Aša¤§¡˜mÑ,Ñ,Ó-Ð-r   c                 ó,   •— ‰‰j                  | «      z  S rÍ   ©rÃ   rÏ   s    €€r   rÃ   z*right_multiplied_operator.<locals>.rmatvec€  s   ø€ Ø�1—9‘9˜Q“<ÑÐr   rÖ   r×   rÙ   s   ``   r   Úright_multiplied_operatorrà   v  s8   ù€ ä˜Ó€Aõ)õ.õ ô ˜!Ÿ'™'¨&¸Ø")ô+ð +r   c                 ó|   ‡ ‡‡— t        ‰ «      Š ‰ j                  \  Š}ˆ ˆfd„}ˆ ˆˆfd„}t        ‰|z   |f||¬«      S )zµReturn a matrix arising in regularized least squares as LinearOperator.

    The matrix is
        [ J ]
        [ D ]
    where D is diagonal matrix with elements from `diag`.
    c                 óV   •— t        j                  ‰j                  | «      ‰| z  f«      S rÍ   )r   ÚhstackrÎ   )r   r\   r]   s    €€r   rÎ   z(regularized_lsq_operator.<locals>.matvec’  s#   ø€ Ü�y‰y˜!Ÿ(™( 1›+ t¨a¡xÐ0Ó1Ð1r   c                 óF   •— | d ‰ }| ‰d  }‰j                  |«      ‰|z  z   S rÍ   rß   )r   Úx1Úx2r\   r]   r1   s      €€€r   rÃ   z)regularized_lsq_operator.<locals>.rmatvec•  s0   ø€ Øˆr�ˆUˆØˆqˆrˆUˆØ�y‰y˜‹}˜t b™yÑ(Ð(r   )rÎ   rÃ   )r
   rØ   r	   )r\   r]   r0   rÎ   rÃ   r1   s   ``   @r   Úregularized_lsq_operatorrç   ‡  s?   ú€ ô 	˜Ó€AØ�7‰7�D€A€qõ2ö)ô
 ˜1˜q™5 !˜*¨V¸WÔEÐEr   c                 ó
  — |r t        | t        «      s| j                  «       } t        | «      r2| xj                  |j                  | j                  d¬«      z  c_        | S t        | t        «      rt        | |«      } | S | |z  } | S )zhCompute J diag(d).

    If `copy` is False, `J` is modified in place (unless being LinearOperator).
    Úclip)Úmode)rÂ   r	   r–   r   ÚdataÚtakeÚindicesrà   ©r\   r   r–   s      r   Úright_multiplyrï   �  sw   € ñ
 ”J˜q¤.Ô1Ø�F‰F‹Hˆä�„{Ø	�Š�!—&‘&˜Ÿ™¨�&Ó0Ñ0�ð €Hô 
�A”~Ô	&Ü% a¨Ó+ˆð €Hð 	
ˆQ‰ˆà€Hr   c                 ó`  — |r t        | t        «      s| j                  «       } t        | «      rH| xj                  t        j                  |t        j                  | j                  «      «      z  c_        | S t        | t        «      rt        | |«      } | S | |dd…t
        j                  f   z  } | S )zhCompute diag(d) J.

    If `copy` is False, `J` is modified in place (unless being LinearOperator).
    N)rÂ   r	   r–   r   rë   r   ÚrepeatÚdiffÚindptrrÚ   rÑ   rî   s      r   Úleft_multiplyrô   ¯  sŒ   € ñ
 ”J˜q¤.Ô1Ø�F‰F‹Hˆä�„{Ø	�Š”"—)‘)˜AœrŸw™w q§x¡xÓ0Ó1Ñ1�ð €Hô 
�A”~Ô	&Ü$ Q¨Ó*ˆð €Hð 	
ˆQŠq”"—*‘*ˆ}ÑÑˆà€Hr   c                 óN   — | ||z  k  xr |dkD  }||||z   z  k  }|r|ry|ry|ryy)z8Check termination condition for nonlinear least squares.rT   é   r   r    NrU   )	ÚdFÚFÚdx_normÚx_normr=   ÚftolÚxtolÚftol_satisfiedÚxtol_satisfieds	            r   Úcheck_terminationrÿ   Á  sB   € à˜$ ™(‘]Ò3 u¨t¡|€NØ˜t t¨f¡}Ñ5Ñ5€Ná™.ØÙ	ØÙ	Øàr   c                 óŠ   — |d   d|d   z  |dz  z  z   }t         ||t         k  <   |dz  }||d   |z  z  }t        | |d¬«      |fS )z`Scale Jacobian and residuals for a robust loss function.

    Arrays are modified in place.
    r+   r   r*   F)r–   )r,   rô   )r\   rM   ÚrhoÚJ_scales       r   Úscale_for_robust_loss_functionr  Ð  sa   € ð
 �!‰f�q˜3˜q™6‘z A q¡DÑ(Ñ(€GÜ €GˆG”c‰MÑØ��O€GàˆˆQ‰�'Ñ	Ñ€Aä˜˜G¨%Ô0°!Ð3Ð3r   )Ng{®Gáz„?é
   )NN)r   rÍ   )g»½×Ùß|Û=)T).Ú__doc__Úmathr   Únumpyr   Únumpy.linalgr   Úscipy.linalgr   r   r   Úscipy.sparser   Úscipy.sparse.linalgr	   r
   ÚfinfoÚfloatÚepsr,   r   r>   rR   rZ   ra   rj   rp   rs   r†   r”   r�   r¢   r©   r³   r¼   r¾   rÀ   rÄ   rÊ   rÚ   rà   rç   rï   rô   rÿ   r  rU   r   r   ú<module>r     sÍ   ðÙ 1Ý ã Ý ç ;Ñ ;Ý !ß @ð €b‡h�hˆuƒo×Ñ€ò$ðN AEØ/1óoòd0òfó:0óf&ó.$òT)ò
Hó:$óNò6)òXòD.òcò!òYò$ó$ò+ò"+ò"Fó,ó$ò$ó4r   