§
    ¡éUgl  ã                   óB   — d dl Zd dlmZmZ d dlZdgZdddœd„Zdd„ZdS )	é    N)ÚsolveÚLinAlgWarningÚnnls)Úatolc                óø  — t          j        | ¦  «        } t          j        |¦  «        }t          | j        ¦  «        dk    rt	          dd| j        › �z   ¦  «        ‚t          |j        ¦  «        dk    rt	          dd|j        › �z   ¦  «        ‚| j        \  }}||j        d         k    r$t	          dd	|› d
|j        d         f› �z   ¦  «        ‚t          | |||¬¦  «        \  }}}|dk    rt          d¦  «        ‚||fS )aÛ  
    Solve ``argmin_x || Ax - b ||_2`` for ``x>=0``.

    This problem, often called as NonNegative Least Squares, is a convex
    optimization problem with convex constraints. It typically arises when
    the ``x`` models quantities for which only nonnegative values are
    attainable; weight of ingredients, component costs and so on.

    Parameters
    ----------
    A : (m, n) ndarray
        Coefficient array
    b : (m,) ndarray, float
        Right-hand side vector.
    maxiter: int, optional
        Maximum number of iterations, optional. Default value is ``3 * n``.
    atol: float
        Tolerance value used in the algorithm to assess closeness to zero in
        the projected residual ``(A.T @ (A x - b)`` entries. Increasing this
        value relaxes the solution constraints. A typical relaxation value can
        be selected as ``max(m, n) * np.linalg.norm(a, 1) * np.spacing(1.)``.
        This value is not set as default since the norm operation becomes
        expensive for large problems hence can be used only when necessary.

    Returns
    -------
    x : ndarray
        Solution vector.
    rnorm : float
        The 2-norm of the residual, ``|| Ax-b ||_2``.

    See Also
    --------
    lsq_linear : Linear least squares with bounds on the variables

    Notes
    -----
    The code is based on [2]_ which is an improved version of the classical
    algorithm of [1]_. It utilizes an active set method and solves the KKT
    (Karush-Kuhn-Tucker) conditions for the non-negative least squares problem.

    References
    ----------
    .. [1] : Lawson C., Hanson R.J., "Solving Least Squares Problems", SIAM,
       1995, :doi:`10.1137/1.9781611971217`
    .. [2] : Bro, Rasmus and de Jong, Sijmen, "A Fast Non-Negativity-
       Constrained Least Squares Algorithm", Journal Of Chemometrics, 1997,
       :doi:`10.1002/(SICI)1099-128X(199709/10)11:5<393::AID-CEM483>3.0.CO;2-L`

     Examples
    --------
    >>> import numpy as np
    >>> from scipy.optimize import nnls
    ...
    >>> A = np.array([[1, 0], [1, 0], [0, 1]])
    >>> b = np.array([2, 1, 1])
    >>> nnls(A, b)
    (array([1.5, 1. ]), 0.7071067811865475)

    >>> b = np.array([-1, -1, -1])
    >>> nnls(A, b)
    (array([0., 0.]), 1.7320508075688772)

    é   z)Expected a two-dimensional array (matrix)z, but the shape of A is é   z)Expected a one-dimensional array (vector)z, but the shape of b is r   z0Incompatible dimensions. The first dimension of zA is z, while the shape of b is )Útolz%Maximum number of iterations reached.)ÚnpÚasarray_chkfiniteÚlenÚshapeÚ
ValueErrorÚ_nnlsÚRuntimeError)	ÚAÚbÚmaxiterr   ÚmÚnÚxÚrnormÚmodes	            úS/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/scipy/optimize/_nnls.pyr   r      s-  € õD 	Ô˜QÑÔ€AÝ
Ô˜QÑÔ€Aå
ˆ1Œ7�|„|�qÒÐÝÐDØ=°A´GÐ=Ð=ñ>ñ ?ô ?ð 	?å
ˆ1Œ7�|„|�qÒÐÝÐDØ=°A´GÐ=Ð=ñ>ñ ?ô ?ð 	?ð Œ7�D€A€qàˆAŒG�AŒJ‚€ÝØBØE˜ÐEÐE°a´g¸a´j°^ÐEÐEñFñGô Gð 	Gõ ˜1˜a ¨dÐ3Ñ3Ô3�N€A€uˆdØˆq‚y€yÝÐBÑCÔCÐCàˆeˆ8€Oó    c                 óž  — | j         \  }}| j        | z  }|| z  }|sd|z  }|€(dt          ||¦  «        z  t          j        d¦  «        z  }t          j        |t          j        ¬¦  «        }t          j        |t          j        ¬¦  «        }	t          j        |t          ¬¦  «        }
|                     ¦   «          	                    t          j        ¦  «        }d}|
 
                    ¦   «         �s9||
          |k                         ¦   «         �rt          j        ||
 z  ¦  «        }d|
|<   d|	dd…<   t          j        ¦   «         5  t          j        d	d
t           ¬¦  «         t#          |t          j        |
|
¦  «                 ||
         dd¬¦  «        |	|
<   ddd¦  «         n# 1 swxY w Y   ||k     �r|	|
                              ¦   «         dk     rù|dz  }|
|	dk     z  }||         ||         |	|         z
  z                       ¦   «         }|d|z
  z  }|||	z  z  }d|
||k    <   t          j        ¦   «         5  t          j        d	d
t           ¬¦  «         t#          |t          j        |
|
¦  «                 ||
         dd¬¦  «        |	|
<   ddd¦  «         n# 1 swxY w Y   d|	|
 <   ||k     r|	|
                              ¦   «         dk     °ù|	dd…         |dd…<   |||z  z
  |dd…<   ||k    r|ddfS |
 
                    ¦   «         s ||
          |k                         ¦   «         �°|t          j                             | |z  |z
  ¦  «        dfS )zŒ
    This is a single RHS algorithm from ref [2] above. For multiple RHS
    support, the algorithm is given in  :doi:`10.1002/cem.889`
    é   Né
   g      ð?)Údtyper   Tg        ÚignorezIll-conditioned matrix)ÚmessageÚcategoryÚsymF)Úassume_aÚcheck_finiter	   éÿÿÿÿ)r   ÚTÚmaxr   ÚspacingÚzerosÚfloat64ÚboolÚcopyÚastypeÚallÚanyÚargmaxÚwarningsÚcatch_warningsÚfilterwarningsr   r   Úix_ÚminÚlinalgÚnorm)r   r   r   r
   r   r   ÚAtAÚAtbr   ÚsÚPÚwÚiterÚkÚindsÚalphas                   r   r   r   b   så  € ð
 Œ7�D€A€qà
Œ#�‰'€CØ
ˆa‰%€Càð Ø�A‘#ˆØ
€{Ø•3�q˜!‘9”9‰n�rœz¨"™~œ~Ñ-ˆõ 	Œ��"œ*Ð%Ñ%Ô%€AÝ
Œ��"œ*Ð%Ñ%Ô%€Aå
Œ��$ÐÑÔ€Að 	�Š‰
Œ
×Ò�"œ*Ñ%Ô%€Að €Dà�uŠu‰wŒwñ $˜Q ˜rœU Sš[×-Ò-Ñ/Ô/ñ $åŒI�a˜A˜2‘hÑÔˆØˆˆ!‰ð ˆˆ!ˆ!ˆ!‰åÔ$Ñ&Ô&ð 	Xð 	XÝÔ# HÐ6NÝ-:ð<ñ <ô <ð <å˜�RœV A q™\œ\Ô*¨C°¬F¸UÐQVÐWÑWÔWˆAˆa‰Dð	Xð 	Xð 	Xñ 	Xô 	Xð 	Xð 	Xð 	Xð 	Xð 	Xð 	Xøøøð 	Xð 	Xð 	Xð 	Xð �gŠ~‰~ A a¤D§H¢H¡J¤J°¢N NØ�A‰IˆDØ˜˜Aš‘;ˆDØ�t”W  $¤¨!¨D¬'Ñ 1Ñ2×7Ò7Ñ9Ô9ˆEØ�!�e‘)ÑˆAØ��q‘‰LˆAØˆAˆa�3Šh‰KÝÔ(Ñ*Ô*ð 1ð 1ÝÔ'¨Ð:RÝ1>ð@ñ @ô @ð @å˜S¥¤¨¨1¡¤Ô.°°A´ÀØ*/ð1ñ 1ô 1��!‘ð1ð 1ð 1ñ 1ô 1ð 1ð 1ð 1ð 1ð 1ð 1øøøð 1ð 1ð 1ð 1ð
 ˆAˆqˆb‰Eð �gŠ~ˆ~ A a¤D§H¢H¡J¤J°¢N Nð ���Œtˆˆ!ˆ!ˆ!‰Ø�S˜1‘W‰}ˆˆ!ˆ!ˆ!‰à�7Š?ˆ?ð
 �b˜"�9ÐðI �uŠu‰wŒwð $˜Q ˜rœU Sš[×-Ò-Ñ/Ô/ñ $ðL �bŒi�nŠn˜Q˜q™S 1™WÑ%Ô% qÐ(Ð(s&   ÅAF#Æ#F'Æ*F'È9AJÊJÊJ)N)NN)	Únumpyr   Úscipy.linalgr   r   r2   Ú__all__r   r   © r   r   ú<module>rF      s„   ðØ Ð Ð Ð Ø -Ð -Ð -Ð -Ð -Ð -Ð -Ð -Ø €€€àˆ(€ðW Tð Wð Wð Wð Wð WðtB)ð B)ð B)ð B)ð B)ð B)r   