
    9=e                     4    d dl mZ ddlmZmZmZ dgZddZdS )   )__nnls    )asarray_chkfinitezerosdoublennlsNc           
         t          t          | |f          \  } }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             |dnt          |          }t          |ft                    }t          |ft                    }t          |ft
                    }t          j	        | |||||||          \  }}	}
|
dk    rt          d          ||	fS )a  
    Solve ``argmin_x || Ax - b ||_2`` for ``x>=0``. This is a wrapper
    for a FORTRAN non-negative least squares solver.

    Parameters
    ----------
    A : ndarray
        Matrix ``A`` as shown above.
    b : ndarray
        Right-hand side vector.
    maxiter: int, optional
        Maximum number of iterations, optional.
        Default is ``3 * A.shape[1]``.

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

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

    Notes
    -----
    The FORTRAN code was published in the book below. The algorithm
    is an active set method. It solves the KKT (Karush-Kuhn-Tucker)
    conditions for the non-negative least squares problem.

    References
    ----------
    Lawson C., Hanson R.J., (1987) Solving Least Squares Problems, SIAM

     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 r   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 N)dtypeztoo many iterations)mapr   lenshape
ValueErrorintr   r   r   r   RuntimeError)Abmaxitermnwzzindexxrnormmodes              4lib/python3.11/site-packages/scipy/optimize/_nnls.pyr   r      s{   h  1a&))DAq
17||qD=AG==> ? ? 	?
17||qD=AG==> ? ? 	? 7DAqAGAJBEEEagaj^EEFG G 	G ObbWGqd&!!!A	t6	"	"	"B1$c"""E[Aq!QE7CCNAudqyy0111e8O    )N) r   numpyr   r   r   __all__r    r   r   <module>r$      s`          2 2 2 2 2 2 2 2 2 2(N N N N N Nr   