Ë
    çÿæiÆ  ã                   óº   — 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
  ej                  e«      j                  Z G d„ d«      Zd„ Z G d	„ d
«      Z G d„ d«      Zy)é    N)Úeighé   )ÚOptions)ÚMaxEvalErrorÚTargetSuccessÚFeasibleSuccessc                   ó¤   — e Zd ZdZd„ Zed„ «       Zed„ «       Zed„ «       Zej                  d„ «       Zed„ «       Z
e
j                  d„ «       Z
d	„ Zy
)ÚInterpolationz×
    Interpolation set.

    This class stores a base point around which the models are expanded and the
    interpolation points. The coordinates of the interpolation points are
    relative to the base point.
    c                 ó0  — |t         j                     | _        dt        j                  |j
                  j                  |j
                  j                  z
  «      z  }|t         j                     |kD  r`||t         j                  j                  <   t        j                  |t         j                     |g«      |t         j                  j                  <   t        j                  |j                  «      | _        | j                  |j
                  j                  d|t         j                     z  z   k  }|j
                  j                  |   | j                  |<   |j
                  j                  d|t         j                     z  z   | j                  k  | j                  |j
                  j                  |t         j                     z   k  z  }t        j                  |j
                  j                  |   |t         j                     z   |j
                  j                  |   «      | j                  |<   | j                  |j
                  j                  d|t         j                     z  z
  k\  }|j
                  j                  |   | j                  |<   | j                  |j
                  j                  d|t         j                     z  z
  k  |j
                  j                  |t         j                     z
  | j                  k  z  }t        j                   |j
                  j                  |   |t         j                     z
  |j
                  j                  |   «      | j                  |<   t        j"                  |j$                  |t         j&                     f«      | _        t+        d|t         j&                     «      D �]Ô  }||j$                  k  rU||dz
     r'|t         j                      | j,                  |dz
  |f<   ŒB|t         j                     | j,                  |dz
  |f<   Œh|d|j$                  z  k  rÌ|||j$                  z
  dz
     r6d|t         j                     z  | j,                  ||j$                  z
  dz
  |f<   ŒÅ|||j$                  z
  dz
     r7d|t         j                     z  | j,                  ||j$                  z
  dz
  |f<   �Œ|t         j                      | j,                  ||j$                  z
  dz
  |f<   �ŒF||j$                  z
  dz
  |j$                  z  }	|d|	z   |j$                  z  z
  dz
  }
|
|	z   |j$                  z  }| j,                  |
|
dz   f   | j,                  |
|f<   | j,                  ||dz   f   | j,                  ||f<   �Œ× d| _        y)zÜ
        Initialize the interpolation set.

        Parameters
        ----------
        pb : `cobyqa.problem.Problem`
            Problem to be solved.
        options : dict
            Options of the solver.
        ç      à?r   é   ç       @g       ÀN)r   ÚDEBUGÚ_debugÚnpÚminÚboundsÚxuÚxlÚRHOBEGÚvalueÚRHOENDÚcopyÚx0Ú_x_baseÚx_baseÚminimumÚmaximumÚzerosÚnÚNPTÚ_xptÚrangeÚxptÚ
_lhs_cache)ÚselfÚpbÚoptionsÚ
max_radiusÚvery_close_xl_idxÚclose_xl_idxÚvery_close_xu_idxÚclose_xu_idxÚkÚspreadÚk1Úk2s               úm/Volumes/fast/ai/experiments/voice-extract-mac/.venv/lib/python3.12/site-packages/scipy/_lib/cobyqa/models.pyÚ__init__zInterpolation.__init__   sS  € ð œgŸm™mÑ,ˆŒØœ2Ÿ6™6 "§)¡)§,¡,°·±·±Ñ"=Ó>Ñ>ˆ
Ø”7—>‘>Ñ" ZÒ/Ø,6ˆG”G—N‘N×(Ñ(Ñ)Ü,.¯F©FàœGŸN™NÑ+Øðó-ˆG”G—N‘N×(Ñ(Ñ)ô —w‘w˜rŸu™u“~ˆŒà�K‰K˜2Ÿ9™9Ÿ<™<¨#°¼¿¹Ñ0GÑ*GÑGÑGð 	ð *,¯©¯©Ð6GÑ)Hˆ�‰Ð%Ñ&à�I‰I�L‰L˜3 ¬¯©Ñ!8Ñ8Ñ8¸4¿;¹;ÑFØ�[‰[˜BŸI™IŸL™L¨7´7·>±>Ñ+BÑBÑBñDˆô %'§J¡JØ�I‰I�L‰L˜Ñ&¨´·±Ñ)@Ñ@Ø�I‰I�L‰L˜Ñ&ó%
ˆ�‰�LÑ!ð
 �K‰K˜2Ÿ9™9Ÿ<™<¨#°¼¿¹Ñ0GÑ*GÑGÑGð 	ð *,¯©¯©Ð6GÑ)Hˆ�‰Ð%Ñ&à�K‰K˜"Ÿ)™)Ÿ,™,¨¨w´w·~±~Ñ/FÑ)FÑFÑFØ�Y‰Y�\‰\˜G¤G§N¡NÑ3Ñ3°t·{±{ÑBñDˆô %'§J¡JØ�I‰I�L‰L˜Ñ&¨´·±Ñ)@Ñ@Ø�I‰I�L‰L˜Ñ&ó%
ˆ�‰�LÑ!ô —H‘H˜bŸd™d G¬G¯K©KÑ$8Ð9Ó:ˆŒ	Ü�q˜'¤'§+¡+Ñ.×/ˆAØ�B—D‘DŠyØ$ Q¨¡UÒ+Ø*1´'·.±.Ñ*AÐ)A�D—H‘H˜Q ™U A˜XÒ&à)0´·±Ñ)@�D—H‘H˜Q ™U A˜XÒ&Ø�a˜"Ÿ$™$‘h’Ø$ Q¨¯©¡X°¡\Ò2Ø03°g¼g¿n¹nÑ6MÑ0M�D—H‘H˜Q §¡™X¨™\¨1˜_Ò-Ø& q¨2¯4©4¡x°!¡|Ò4Ø04°w¼w¿~¹~Ñ7NÑ0N�D—H‘H˜Q §¡™X¨™\¨1˜_Ó-à18¼¿¹Ñ1HÐ0H�D—H‘H˜Q §¡™X¨™\¨1˜_Ó-à˜bŸd™d™( Q™,¨2¯4©4Ñ/�Ø˜!˜f™*¨¯©Ñ,Ñ,¨qÑ0�Ø˜6‘k R§T¡TÑ)�Ø"&§(¡(¨2¨r°A©v¨:Ñ"6�—‘˜˜Q˜‘Ø"&§(¡(¨2¨r°A©v¨:Ñ"6�—‘˜˜Q˜“ð% 0ð& ˆ�ó    c                 ó4   — | j                   j                  d   S )út
        Number of variables.

        Returns
        -------
        int
            Number of variables.
        r   ©r$   Úshape©r&   s    r2   r    zInterpolation.n]   ó   € ð �x‰x�~‰~˜aÑ Ð r4   c                 ó4   — | j                   j                  d   S )úŠ
        Number of interpolation points.

        Returns
        -------
        int
            Number of interpolation points.
        r   r7   r9   s    r2   ÚnptzInterpolation.npti   r:   r4   c                 ó   — | j                   S )z’
        Interpolation points.

        Returns
        -------
        `numpy.ndarray`, shape (n, npt)
            Interpolation points.
        )r"   r9   s    r2   r$   zInterpolation.xptu   s   € ð �y‰yÐr4   c                 ó‚   — | j                   r,|j                  | j                  | j                  fk(  sJ d«       ‚|| _        y)zª
        Set the interpolation points.

        Parameters
        ----------
        xpt : `numpy.ndarray`, shape (n, npt)
            New interpolation points.
        z The shape of `xpt` is not valid.N)r   r8   r    r=   r"   )r&   r$   s     r2   r$   zInterpolation.xpt�   sG   € ð �;Š;Ø—9‘9Ø—‘Ø—‘ð!ò ð 2ð 2ó2ð ð ˆ�	r4   c                 ó   — | j                   S )zÄ
        Base point around which the models are expanded.

        Returns
        -------
        `numpy.ndarray`, shape (n,)
            Base point around which the models are expanded.
        )r   r9   s    r2   r   zInterpolation.x_base’   s   € ð �|‰|Ðr4   c                 ól   — | j                   r!|j                  | j                  fk(  sJ d«       ‚|| _        y)zß
        Set the base point around which the models are expanded.

        Parameters
        ----------
        x_base : `numpy.ndarray`, shape (n,)
            New base point around which the models are expanded.
        z#The shape of `x_base` is not valid.N)r   r8   r    r   )r&   r   s     r2   r   zInterpolation.x_basež   s>   € ð �;Š;Ø—<‘<Ø—‘ð$ò ð 5à4ó5ð ð ˆ�r4   c                 ó¢   — | j                   r$d|cxk  r| j                  k  sJ d«       ‚ J d«       ‚| j                  | j                  dd…|f   z   S )a<  
        Get the `k`-th interpolation point.

        The return point is relative to the origin.

        Parameters
        ----------
        k : int
            Index of the interpolation point.

        Returns
        -------
        `numpy.ndarray`, shape (n,)
            `k`-th interpolation point.
        r   zThe index `k` is not valid.N)r   r=   r   r$   )r&   r.   s     r2   ÚpointzInterpolation.point®   sO   € ð  �;Š;Ø˜Ô$˜DŸH™HÒ$ÐCÐ&CÓCÑ$ÐCÐ&CÓCÐ$Ø�{‰{˜TŸX™X¢a¨ d™^Ñ+Ð+r4   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r3   Úpropertyr    r=   r$   Úsetterr   rC   © r4   r2   r
   r
      s“   „ ñòEðN ñ	!ó ð	!ð ñ	!ó ð	!ð ñ	ó ð	ð 	‡Z�Zñó ðð  ñ	ó ð	ð ‡]�]ñó ðó,r4   r
   c                 óv  — | j                   }|�1t        j                  | j                  |d   «      r|d   |d   |d   fS t        j                  t        j
                  j                  | j                  d¬«      t        ¬«      }| j                  |z  }|j                  \  }}t        j                  ||z   d	z   ||z   d	z   f«      }d
|j                  |z  dz  z  |d|…d|…f<   d|d|…|f<   |j                  |d|…|d	z   d…f<   d||d|…f<   |||d	z   d…d|…f<   t        j                  ||z   d	z   «      }d|dz  z  |d| |dz  ||<   |||d	z   d t        |d¬«      \  }}	t        j                  | j                  «      t        j                  |«      t        j                  |«      ||	fdœ}
|
| _         ||||	ffS )a‰  
    Build the left-hand side matrix of the interpolation system. The
    matrix below stores W * diag(right_scaling),
    where W is the theoretical matrix of the interpolation system. The
    right scaling matrices is chosen to keep the elements in
    the matrix well-balanced.

    Parameters
    ----------
    interpolation : `cobyqa.models.Interpolation`
        Interpolation set.
    Nr$   ÚaÚright_scalingr   r   )Úaxis©Úinitialr   r   r   ç      ð?F)Úcheck_finite)r$   rL   rM   r   )r%   r   Úarray_equalr$   ÚmaxÚlinalgÚnormÚEPSr8   r   ÚTÚemptyr   r   )ÚinterpolationÚ_cacheÚscaleÚ	xpt_scaler    r=   rL   rM   Ú
eig_valuesÚeig_vectorsÚ	new_caches              r2   Úbuild_systemra   Ã   sä  € ð ×%Ñ%€Fð ÐœbŸn™nØ×Ñ˜6 %™=ôð �c‰{˜F ?Ñ3°V¸F±^ÐCÐCä�F‰F”2—9‘9—>‘> -×"3Ñ"3¸!�>Ó<ÄcÔJ€EØ×!Ñ! EÑ)€Ià�_‰_�F€A€sÜ
�‰�#˜‘'˜A‘+˜s Q™w¨™{Ð+Ó,€AØ˜9Ÿ;™;¨Ñ2°sÑ:Ñ:€A€d€s€dˆDˆSˆD€j�MØ€A€d€s€dˆC€i�LØ!Ÿ™€A€d€s€dˆC�!‰G‰H€nÑØ€A€cˆ4ˆCˆ4€i�LØ!€A€cˆA�g�h���€nÑô —H‘H˜S 1™W q™[Ó)€MØ  s¡
Ñ*€M�$�3ÐØ ™€M�#ÑØ#€M�#˜‘'�(Ðä" 1°5Ô9Ñ€J�ô �w‰w�}×(Ñ(Ó)Ü�W‰W�Q‹ZÜŸ™ Ó/Ø˜[Ð)ñ	€Ið  )€MÔàˆm˜j¨+Ð6Ð6Ð6r4   c                   ó€   — e Zd ZdZd„ Zd„ Zed„ «       Zed„ «       Zd„ Z	d„ Z
d„ Zd	„ Zd
„ Zd„ Zed„ «       Zed„ «       Zy)Ú	Quadratica:  
    Quadratic model.

    This class stores the Hessian matrix of the quadratic model using the
    implicit/explicit representation designed by Powell for NEWUOA [1]_.

    References
    ----------
    .. [1] M. J. D. Powell. The NEWUOA software for unconstrained optimization
       without derivatives. In G. Di Pillo and M. Roma, editors, *Large-Scale
       Nonlinear Optimization*, volume 83 of Nonconvex Optim. Appl., pages
       255--297. Springer, Boston, MA, USA, 2006. `doi:10.1007/0-387-30065-1_16
       <https://doi.org/10.1007/0-387-30065-1_16>`_.
    c                 óˆ  — || _         | j                   r!|j                  |j                  fk(  sJ d«       ‚|j                  |j                  dz   k  rt	        d|j                  dz   › d�«      ‚| j                  ||«      \  | _        | _        | _        }t        j                  | j                  | j                  f«      | _        y)aú  
        Initialize the quadratic model.

        Parameters
        ----------
        interpolation : `cobyqa.models.Interpolation`
            Interpolation set.
        values : `numpy.ndarray`, shape (npt,)
            Values of the interpolated function at the interpolation points.
        debug : bool
            Whether to make debugging tests during the execution.

        Raises
        ------
        `numpy.linalg.LinAlgError`
            If the interpolation system is ill-defined.
        ú#The shape of `values` is not valid.r   z4The number of interpolation points must be at least Ú.N)r   r8   r=   r    Ú
ValueErrorÚ
_get_modelÚ_constÚ_gradÚ_i_hessr   r   Ú_e_hess)r&   rZ   ÚvaluesÚdebugÚ_s        r2   r3   zQuadratic.__init__  sÁ   € ð$ ˆŒØ�;Š;Ø—<‘<Ø×!Ñ!ð$ò ð 5à4ó5ð ð ×Ñ˜}Ÿ™°Ñ2Ò2ÜØFØ —?‘? QÑ&Ð' qð*óð ð 48·?±?ØØó4
Ñ0ˆŒ�T”Z ¤¨qô —x‘x §¡¨¯©Ð 0Ó1ˆ�r4   c                 ó2  — | j                   r!|j                  | j                  fk(  sJ d«       ‚||j                  z
  }| j                  | j
                  |z  z   d| j                  |j                  j                  |z  dz  z  || j                  z  |z  z   z  z   S )a�  
        Evaluate the quadratic model at a given point.

        Parameters
        ----------
        x : `numpy.ndarray`, shape (n,)
            Point at which the quadratic model is evaluated.
        interpolation : `cobyqa.models.Interpolation`
            Interpolation set.

        Returns
        -------
        float
            Value of the quadratic model at `x`.
        úThe shape of `x` is not valid.r   r   )
r   r8   r    r   ri   rj   rk   r$   rX   rl   ©r&   ÚxrZ   Úx_diffs       r2   Ú__call__zQuadratic.__call__*  s›   € ð  �;Š;Ø—7‘7˜tŸv™v˜iÒ'ÐIÐ)IÓIÐ'Ø�]×)Ñ)Ñ)ˆà�K‰KØ�j‰j˜6Ñ!ñ"àà—‘ × 1Ñ 1× 3Ñ 3°fÑ <ÀÑDÑDØ˜4Ÿ<™<Ñ'¨&Ñ0ñ1ññð	
r4   c                 ó.   — | j                   j                  S )r6   )rj   Úsizer9   s    r2   r    zQuadratic.nG  s   € ð �z‰z�‰Ðr4   c                 ó.   — | j                   j                  S )zÐ
        Number of interpolation points used to define the quadratic model.

        Returns
        -------
        int
            Number of interpolation points used to define the quadratic model.
        )rk   rw   r9   s    r2   r=   zQuadratic.nptS  s   € ð �|‰|× Ñ Ð r4   c                 ó¸   — | j                   r!|j                  | j                  fk(  sJ d«       ‚||j                  z
  }| j                  | j                  ||«      z   S )aº  
        Evaluate the gradient of the quadratic model at a given point.

        Parameters
        ----------
        x : `numpy.ndarray`, shape (n,)
            Point at which the gradient of the quadratic model is evaluated.
        interpolation : `cobyqa.models.Interpolation`
            Interpolation set.

        Returns
        -------
        `numpy.ndarray`, shape (n,)
            Gradient of the quadratic model at `x`.
        rq   )r   r8   r    r   rj   Ú	hess_prodrr   s       r2   ÚgradzQuadratic.grad_  sS   € ð  �;Š;Ø—7‘7˜tŸv™v˜iÒ'ÐIÐ)IÓIÐ'Ø�]×)Ñ)Ñ)ˆØ�z‰z˜DŸN™N¨6°=ÓAÑAÐAr4   c                 ó¦   — | j                   |j                  | j                  dd…t        j                  f   |j                  j
                  z  z  z   S )a;  
        Evaluate the Hessian matrix of the quadratic model.

        Parameters
        ----------
        interpolation : `cobyqa.models.Interpolation`
            Interpolation set.

        Returns
        -------
        `numpy.ndarray`, shape (n, n)
            Hessian matrix of the quadratic model.
        N)rl   r$   rk   r   ÚnewaxisrX   )r&   rZ   s     r2   ÚhesszQuadratic.hesst  sG   € ð �|‰|˜m×/Ñ/Ø�L‰LšœBŸJ™J˜Ñ'¨-×*;Ñ*;×*=Ñ*=Ñ=ñ
ñ 
ð 	
r4   c                 óâ   — | j                   r!|j                  | j                  fk(  sJ d«       ‚| j                  |z  |j                  | j
                  |j                  j                  |z  z  z  z   S )a.  
        Evaluate the right product of the Hessian matrix of the quadratic model
        with a given vector.

        Parameters
        ----------
        v : `numpy.ndarray`, shape (n,)
            Vector with which the Hessian matrix of the quadratic model is
            multiplied from the right.
        interpolation : `cobyqa.models.Interpolation`
            Interpolation set.

        Returns
        -------
        `numpy.ndarray`, shape (n,)
            Right product of the Hessian matrix of the quadratic model with
            `v`.
        úThe shape of `v` is not valid.)r   r8   r    rl   r$   rk   rX   ©r&   ÚvrZ   s      r2   rz   zQuadratic.hess_prod†  si   € ð& �;Š;Ø—7‘7˜tŸv™v˜iÒ'ÐIÐ)IÓIÐ'Ø�|‰|˜aÑ -×"3Ñ"3Ø�L‰L˜M×-Ñ-×/Ñ/°!Ñ3Ñ4ñ#
ñ 
ð 	
r4   c                 óÔ   — | j                   r!|j                  | j                  fk(  sJ d«       ‚|| j                  z  |z  | j                  |j
                  j                  |z  dz  z  z   S )aÄ  
        Evaluate the curvature of the quadratic model along a given direction.

        Parameters
        ----------
        v : `numpy.ndarray`, shape (n,)
            Direction along which the curvature of the quadratic model is
            evaluated.
        interpolation : `cobyqa.models.Interpolation`
            Interpolation set.

        Returns
        -------
        float
            Curvature of the quadratic model along `v`.
        r€   r   )r   r8   r    rl   rk   r$   rX   r�   s      r2   ÚcurvzQuadratic.curvŸ  sf   € ð" �;Š;Ø—7‘7˜tŸv™v˜iÒ'ÐIÐ)IÓIÐ'à�—‘Ñ˜qÑ Ø�l‰l˜m×/Ñ/×1Ñ1°AÑ5¸#Ñ=Ñ=ñ>ð	
r4   c                 ó&  — | j                   rfd|cxk  r| j                  k  sJ d«       ‚ J d«       ‚|j                  | j                  fk(  sJ d«       ‚|j                  | j                  fk(  sJ d«       ‚| xj                  | j
                  |   t        j                  ||«      z  z  c_        d| j
                  |<   | j                  ||«      \  }}}}| xj                  |z  c_	        | xj                  |z  c_
        | xj
                  |z  c_        |S )a�  
        Update the quadratic model.

        This method applies the derivative-free symmetric Broyden update to the
        quadratic model. The `knew`-th interpolation point must be updated
        before calling this method.

        Parameters
        ----------
        interpolation : `cobyqa.models.Interpolation`
            Updated interpolation set.
        k_new : int
            Index of the updated interpolation point.
        dir_old : `numpy.ndarray`, shape (n,)
            Value of ``interpolation.xpt[:, k_new]`` before the update.
        values_diff : `numpy.ndarray`, shape (npt,)
            Differences between the values of the interpolated nonlinear
            function and the previous quadratic model at the updated
            interpolation points.

        Raises
        ------
        `numpy.linalg.LinAlgError`
            If the interpolation system is ill-defined.
        r   úThe index `k_new` is not valid.z$The shape of `dir_old` is not valid.z(The shape of `values_diff` is not valid.ç        )r   r=   r8   r    rl   rk   r   Úouterrh   ri   rj   )	r&   rZ   Úk_newÚdir_oldÚvalues_diffÚconstr{   Úi_hessÚill_conditioneds	            r2   ÚupdatezQuadratic.update·  s  € ð4 �;Š;Ø˜Ô( §¡Ò(ÐKÐ*KÓKÑ(ÐKÐ*KÓKÐ(Ø—=‘=Ø—‘ð%ò ð 6à5ó6ð ð ×$Ñ$Ø—‘ð)ò ð :à9ó:ð ð 	�Š˜Ÿ™ UÑ+¬b¯h©h°wÀÓ.HÑHÑH�Ø!ˆ�‰�UÑð 04¯©ØØó0
Ñ,ˆˆt�V˜_ð 	�Š�uÑ�Ø�
Š
�dÑ�
Ø�Š˜Ñ�ØÐr4   c                 óš  — | j                   r!|j                  | j                  fk(  sJ d«       ‚ | ||«      | _        | j	                  ||«      | _        ||j                  z
  }t        j                  ||j                  d|dd…t        j                  f   z  z
  | j                  z  «      }| xj                  ||j                  z   z  c_        y)aB  
        Shift the point around which the quadratic model is defined.

        Parameters
        ----------
        interpolation : `cobyqa.models.Interpolation`
            Previous interpolation set.
        new_x_base : `numpy.ndarray`, shape (n,)
            Point that will replace ``interpolation.x_base``.
        ú'The shape of `new_x_base` is not valid.r   N)r   r8   r    ri   r{   rj   r   r   rˆ   r$   r}   rk   rl   rX   )r&   rZ   Ú
new_x_baseÚshiftr�   s        r2   Úshift_x_basezQuadratic.shift_x_baseë  s¼   € ð �;Š;Ø×#Ñ#Ø—‘ð(ò ð 9à8ó9ð ñ ˜: }Ó5ˆŒØ—Y‘Y˜z¨=Ó9ˆŒ
Ø˜]×1Ñ1Ñ1ˆÜ—‘ØØ×Ñ  uªQ´·
±
¨]Ñ';Ñ!;Ñ;¸t¿|¹|ÑKó
ˆð 	�Š˜ §¡Ñ)Ñ)Žr4   c                 óÞ  — | j                   j                  \  }}|j                  dk(  r|j                  d   ||z   dz   k(  sJ d«       ‚t        | «      \  }}}||dd…t        j
                  f   z  }t	        j                  t	        j                  |«      «      r(t	        j                  t	        j                  |«      «      st        j                  j                  d«      ‚|\  }}	t	        j                  |«      t        kD  }
|	dd…|
f   }	d||
   z  }t	        j                  |
d«       }|	|	j                  |z  |dd…t        j
                  f   z  z  }||dd…t        j
                  f   z  |fS )a•  
        Solve the interpolation systems.

        Parameters
        ----------
        interpolation : `cobyqa.models.Interpolation`
            Interpolation set.
        rhs : `numpy.ndarray`, shape (npt + n + 1, m)
            Right-hand side vectors of the ``m`` interpolation systems.

        Returns
        -------
        `numpy.ndarray`, shape (npt + n + 1, m)
            Solutions of the interpolation systems.
        `numpy.ndarray`, shape (m, )
            Whether the interpolation systems are ill-conditioned.

        Raises
        ------
        `numpy.linalg.LinAlgError`
            If the interpolation systems are ill-defined.
        r   r   r   z The shape of `rhs` is not valid.Nz(The interpolation system is ill-defined.rQ   )r$   r8   Úndimra   r   r}   ÚallÚisfiniterU   ÚLinAlgErrorÚabsrW   rX   )rZ   Úrhsr    r=   rL   rM   ÚeigÚ
rhs_scaledr^   r_   Úlarge_eig_valuesÚinv_eig_valuesrŽ   Úleft_scaled_solutionss                 r2   Úsolve_systemszQuadratic.solve_systems  sZ  € ð0 ×"Ñ"×(Ñ(‰ˆˆ3à�H‰H˜ŠM˜cŸi™i¨™l¨c°A©g¸©kÒ9ð	.à-ó	.Ø9ô !-¨]Ó ;Ñˆˆ=˜#ð ˜=ª¬B¯J©J¨Ñ7Ñ7ˆ
Ü—‘”r—{‘{ 1“~Ô&¬2¯6©6´"·+±+¸jÓ2IÔ+JÜ—)‘)×'Ñ'Ø:óð ð
 #&Ñˆ
�KäŸ6™6 *Ó-´Ñ3ÐØ!¢!Ð%5Ð"5Ñ6ˆØ˜zÐ*:Ñ;Ñ;ˆÜŸ6™6Ð"2°AÓ6Ð6ˆØ +Ø�]‰]˜ZÑ'¨>º!¼R¿Z¹Z¸-Ñ+HÑHñ!
Ðð " M²!´R·Z±Z°-Ñ$@Ñ@Øð
ð 	
r4   c           
      óL  — |j                   | j                  fk(  sJ d«       ‚| j                  j                   \  }}t        j	                  | t        j                  |t        j                  |dz   «      gg«      j                  «      \  }}||df   ||dz   d…df   |d|…df   |fS )aÓ  
        Solve the interpolation system.

        Parameters
        ----------
        interpolation : `cobyqa.models.Interpolation`
            Interpolation set.
        values : `numpy.ndarray`, shape (npt,)
            Values of the interpolated function at the interpolation points.

        Returns
        -------
        float
            Constant term of the quadratic model.
        `numpy.ndarray`, shape (n,)
            Gradient of the quadratic model at ``interpolation.x_base``.
        `numpy.ndarray`, shape (npt,)
            Implicit Hessian matrix of the quadratic model.

        Raises
        ------
        `numpy.linalg.LinAlgError`
            If the interpolation system is ill-defined.
        re   r   r   N)	r8   r=   r$   rc   r¡   r   Úblockr   rX   )rZ   rm   r    r=   rs   rŽ   s         r2   rh   zQuadratic._get_modelD  sÃ   € ð4 �|‰|Ø×Ñð 
ò 
ð 	1à0ó	1ð 
ð ×"Ñ"×(Ñ(‰ˆˆ3Ü&×4Ñ4ØÜ�H‰Hð ÜŸ™  Q¡›ððó÷ ‰aó

Ñˆˆ?ð ��a�‰y˜!˜C !™G™H a˜K™.¨!¨D¨S¨D°!¨G©*°oÐEÐEr4   N)rD   rE   rF   rG   r3   ru   rH   r    r=   r{   r~   rz   r„   r�   r”   Ústaticmethodr¡   rh   rJ   r4   r2   rc   rc   ø   s…   „ ñò 2òD
ð: ñ	ó ð	ð ñ	!ó ð	!òBò*
ò$
ò2
ò02òh*ð0 ñ>
ó ð>
ð@ ñ(Fó ñ(Fr4   rc   c                   ó:  — e Zd ZdZd„ Zed„ «       Zed„ «       Zed„ «       Zed„ «       Z	ed„ «       Z
ed„ «       Zed	„ «       Zed
„ «       Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd#d„Zd#d„Zd#d„Zd#d„Zd#d„Zd#d„Zd#d„Zd#d„Zd#d„Zd#d„Zd„ Zd„ Zd#d„Z d„ Z!d#d „Z"d#d!„Z#d"„ Z$y)$ÚModelsz6
    Models for a nonlinear optimization problem.
    c           	      ó¦  — |t         j                     | _        t        ||«      | _        | j
                  j                  d«      } |||«      \  }}}t        j                  |t         j                     t        j                  «      | _        t        j                  |t         j                     |j                  ft        j                  «      | _        t        j                  |t         j                     |j                  ft        j                  «      | _        t        |t         j                     «      D �]²  }||t         j                      k\  rt"        ‚|dk(  r6|| j$                  |<   || j&                  |dd…f<   || j(                  |dd…f<   nW| j
                  j                  |«      } |||«      \  | j$                  |<   | j&                  |dd…f<   | j(                  |dd…f<   |j*                  rh|j-                  | j
                  j                  |«      | j&                  |dd…f   | j(                  |dd…f   «      |t         j.                     k  rt0        ‚| j                  |   |t         j2                     k  s�ŒK|j-                  | j
                  j                  |«      | j&                  |dd…f   | j(                  |dd…f   «      |t         j.                     k  s�Œ¯t4        ‚ t7        | j
                  | j                  |t         j                     «      | _        t        j:                  | j<                  t6        ¬«      | _        t        j:                  | j@                  t6        ¬«      | _!        t        | j<                  «      D ]H  }	t7        | j
                  | j&                  dd…|	f   |t         j                     «      | j>                  |	<   ŒJ t        | j@                  «      D ]H  }	t7        | j
                  | j(                  dd…|	f   |t         j                     «      | jB                  |	<   ŒJ | j                  r| jE                  «        yy)aE  
        Initialize the models.

        Parameters
        ----------
        pb : `cobyqa.problem.Problem`
            Problem to be solved.
        options : dict
            Options of the solver.
        penalty : float
            Penalty parameter used to select the point in the filter to forward
            to the callback function.

        Raises
        ------
        `cobyqa.utils.MaxEvalError`
            If the maximum number of evaluations is reached.
        `cobyqa.utils.TargetSuccess`
            If a nearly feasible point has been found with an objective
            function value below the target.
        `cobyqa.utils.FeasibleSuccess`
            If a feasible point has been found for a feasibility problem.
        `numpy.linalg.LinAlgError`
            If the interpolation system is ill-defined.
        r   N)Údtype)#r   r   r   r
   Ú_interpolationrZ   rC   r   Úfullr!   ÚnanÚ_fun_valrw   Ú_cub_valÚ_ceq_valr#   ÚMAX_EVALr   Úfun_valÚcub_valÚceq_valÚis_feasibilityÚmaxcvÚFEASIBILITY_TOLr   ÚTARGETr   rc   Ú_funrY   Úm_nonlinear_ubÚ_cubÚm_nonlinear_eqÚ_ceqÚ_check_interpolation_conditions)
r&   r'   r(   ÚpenaltyÚx_evalÚfun_initÚcub_initÚceq_initr.   Úis
             r2   r3   zModels.__init__u  si  € ð6 œgŸm™mÑ,ˆŒÜ+¨B°Ó8ˆÔð ×#Ñ#×)Ñ)¨!Ó,ˆÙ')¨&°'Ó':Ñ$ˆ�(˜HÜŸ™ ¬¯©Ñ 4´b·f±fÓ=ˆŒÜŸ™ ¬¯©Ñ!5°x·}±}Ð EÄrÇvÁvÓNˆŒÜŸ™ ¬¯©Ñ!5°x·}±}Ð EÄrÇvÁvÓNˆŒÜ�wœwŸ{™{Ñ+×,ˆAØ�GœG×,Ñ,Ñ-Ò-Ü"Ð"Ø�AŠvØ"*�—‘˜Q‘Ø%-�—‘˜Q¢˜TÑ"Ø%-�—‘˜Q¢˜TÒ"à×+Ñ+×1Ñ1°!Ó4�ÙJLØØóKÑG�—‘˜Q‘ §¡¨a²¨dÑ!3°T·\±\À!ÂQÀ$Ñ5Gð ×!Ò!Ø—H‘HØ×&Ñ&×,Ñ,¨QÓ/Ø—L‘L ¢A Ñ&Ø—L‘L ¢A Ñ&óð
 œ7×2Ñ2Ñ3ò4ô &Ð%ð
 —‘˜aÑ  G¬G¯N©NÑ$;Ô;Ø—H‘HØ×&Ñ&×,Ñ,¨QÓ/Ø—L‘L ¢A Ñ&Ø—L‘L ¢A Ñ&óð
 œ7×2Ñ2Ñ3ô4ô $Ð#ðM -ôR Ø×ÑØ�M‰MØ”G—M‘MÑ"ó
ˆŒ	ô
 —H‘H˜T×0Ñ0¼	ÔBˆŒ	Ü—H‘H˜T×0Ñ0¼	ÔBˆŒ	Ü�t×*Ñ*Ö+ˆAÜ$Ø×"Ñ"Ø—‘šQ ˜TÑ"ØœŸ™Ñ&óˆD�I‰I�aŠLð ,ô �t×*Ñ*Ö+ˆAÜ$Ø×"Ñ"Ø—‘šQ ˜TÑ"ØœŸ™Ñ&óˆD�I‰I�aŠLð ,ð �;Š;Ø×0Ñ0Õ2ð r4   c                 ó.   — | j                   j                  S )z~
        Dimension of the problem.

        Returns
        -------
        int
            Dimension of the problem.
        )rZ   r    r9   s    r2   r    zModels.nØ  s   € ð ×!Ñ!×#Ñ#Ð#r4   c                 ó.   — | j                   j                  S )r<   )rZ   r=   r9   s    r2   r=   z
Models.nptä  s   € ð ×!Ñ!×%Ñ%Ð%r4   c                 ó4   — | j                   j                  d   S )z¢
        Number of nonlinear inequality constraints.

        Returns
        -------
        int
            Number of nonlinear inequality constraints.
        r   )r±   r8   r9   s    r2   r¸   zModels.m_nonlinear_ubð  ó   € ð �|‰|×!Ñ! !Ñ$Ð$r4   c                 ó4   — | j                   j                  d   S )zž
        Number of nonlinear equality constraints.

        Returns
        -------
        int
            Number of nonlinear equality constraints.
        r   )r²   r8   r9   s    r2   rº   zModels.m_nonlinear_eqü  rÆ   r4   c                 ó   — | j                   S )zŠ
        Interpolation set.

        Returns
        -------
        `cobyqa.models.Interpolation`
            Interpolation set.
        )r©   r9   s    r2   rZ   zModels.interpolation  s   € ð ×"Ñ"Ð"r4   c                 ó   — | j                   S )zà
        Values of the objective function at the interpolation points.

        Returns
        -------
        `numpy.ndarray`, shape (npt,)
            Values of the objective function at the interpolation points.
        )r¬   r9   s    r2   r°   zModels.fun_val  s   € ð �}‰}Ðr4   c                 ó   — | j                   S )a1  
        Values of the nonlinear inequality constraint functions at the
        interpolation points.

        Returns
        -------
        `numpy.ndarray`, shape (npt, m_nonlinear_ub)
            Values of the nonlinear inequality constraint functions at the
            interpolation points.
        )r­   r9   s    r2   r±   zModels.cub_val   ó   € ð �}‰}Ðr4   c                 ó   — | j                   S )a-  
        Values of the nonlinear equality constraint functions at the
        interpolation points.

        Returns
        -------
        `numpy.ndarray`, shape (npt, m_nonlinear_eq)
            Values of the nonlinear equality constraint functions at the
            interpolation points.
        )r®   r9   s    r2   r²   zModels.ceq_val.  rË   r4   c                 ó”   — | j                   r!|j                  | j                  fk(  sJ d«       ‚| j                  || j                  «      S )a�  
        Evaluate the quadratic model of the objective function at a given
        point.

        Parameters
        ----------
        x : `numpy.ndarray`, shape (n,)
            Point at which to evaluate the quadratic model of the objective
            function.

        Returns
        -------
        float
            Value of the quadratic model of the objective function at `x`.
        rq   )r   r8   r    r·   rZ   ©r&   rs   s     r2   Úfunz
Models.fun<  s@   € ð  �;Š;Ø—7‘7˜tŸv™v˜iÒ'ÐIÐ)IÓIÐ'Ø�y‰y˜˜D×.Ñ.Ó/Ð/r4   c                 ó¨   — | j                   r!|j                  | j                  fk(  sJ d«       ‚| j                  j	                  || j
                  «      S )aÆ  
        Evaluate the gradient of the quadratic model of the objective function
        at a given point.

        Parameters
        ----------
        x : `numpy.ndarray`, shape (n,)
            Point at which to evaluate the gradient of the quadratic model of
            the objective function.

        Returns
        -------
        `numpy.ndarray`, shape (n,)
            Gradient of the quadratic model of the objective function at `x`.
        rq   )r   r8   r    r·   r{   rZ   rÎ   s     r2   Úfun_gradzModels.fun_gradP  sD   € ð  �;Š;Ø—7‘7˜tŸv™v˜iÒ'ÐIÐ)IÓIÐ'Ø�y‰y�~‰~˜a ×!3Ñ!3Ó4Ð4r4   c                 óL   — | j                   j                  | j                  «      S )zû
        Evaluate the Hessian matrix of the quadratic model of the objective
        function.

        Returns
        -------
        `numpy.ndarray`, shape (n, n)
            Hessian matrix of the quadratic model of the objective function.
        )r·   r~   rZ   r9   s    r2   Úfun_hesszModels.fun_hessd  s   € ð �y‰y�~‰~˜d×0Ñ0Ó1Ð1r4   c                 ó¨   — | j                   r!|j                  | j                  fk(  sJ d«       ‚| j                  j	                  || j
                  «      S )a'  
        Evaluate the right product of the Hessian matrix of the quadratic model
        of the objective function with a given vector.

        Parameters
        ----------
        v : `numpy.ndarray`, shape (n,)
            Vector with which the Hessian matrix of the quadratic model of the
            objective function is multiplied from the right.

        Returns
        -------
        `numpy.ndarray`, shape (n,)
            Right product of the Hessian matrix of the quadratic model of the
            objective function with `v`.
        r€   )r   r8   r    r·   rz   rZ   ©r&   r‚   s     r2   Úfun_hess_prodzModels.fun_hess_prodp  sF   € ð" �;Š;Ø—7‘7˜tŸv™v˜iÒ'ÐIÐ)IÓIÐ'Ø�y‰y×"Ñ" 1 d×&8Ñ&8Ó9Ð9r4   c                 ó¨   — | j                   r!|j                  | j                  fk(  sJ d«       ‚| j                  j	                  || j
                  «      S )aÑ  
        Evaluate the curvature of the quadratic model of the objective function
        along a given direction.

        Parameters
        ----------
        v : `numpy.ndarray`, shape (n,)
            Direction along which the curvature of the quadratic model of the
            objective function is evaluated.

        Returns
        -------
        float
            Curvature of the quadratic model of the objective function along
            `v`.
        r€   )r   r8   r    r·   r„   rZ   rÕ   s     r2   Úfun_curvzModels.fun_curv…  sD   € ð" �;Š;Ø—7‘7˜tŸv™v˜iÒ'ÐIÐ)IÓIÐ'Ø�y‰y�~‰~˜a ×!3Ñ!3Ó4Ð4r4   c                 óê   — | j                   r!|j                  | j                  fk(  sJ d«       ‚t        | j                  | j
                  | j                   «      }|j                  || j                  «      S )ap  
        Evaluate the gradient of the alternative quadratic model of the
        objective function at a given point.

        Parameters
        ----------
        x : `numpy.ndarray`, shape (n,)
            Point at which to evaluate the gradient of the alternative
            quadratic model of the objective function.

        Returns
        -------
        `numpy.ndarray`, shape (n,)
            Gradient of the alternative quadratic model of the objective
            function at `x`.

        Raises
        ------
        `numpy.linalg.LinAlgError`
            If the interpolation system is ill-defined.
        rq   )r   r8   r    rc   rZ   r°   r{   )r&   rs   Úmodels      r2   Úfun_alt_gradzModels.fun_alt_gradš  s\   € ð, �;Š;Ø—7‘7˜tŸv™v˜iÒ'ÐIÐ)IÓIÐ'Ü˜$×,Ñ,¨d¯l©l¸D¿K¹KÓHˆØ�z‰z˜!˜T×/Ñ/Ó0Ð0r4   Nc           	      ó2  — | j                   rD|j                  | j                  fk(  sJ d«       ‚|�!|j                  | j                  fk(  sJ d«       ‚t	        j
                  | j                  |«      D �cg c]  } ||| j                  «      ‘Œ c}«      S c c}w )a;  
        Evaluate the quadratic models of the nonlinear inequality functions at
        a given point.

        Parameters
        ----------
        x : `numpy.ndarray`, shape (n,)
            Point at which to evaluate the quadratic models of the nonlinear
            inequality functions.
        mask : `numpy.ndarray`, shape (m_nonlinear_ub,), optional
            Mask of the quadratic models to consider.

        Returns
        -------
        `numpy.ndarray`
            Values of the quadratic model of the nonlinear inequality
            functions.
        rq   ú!The shape of `mask` is not valid.)r   r8   r    r¸   r   ÚarrayÚ_get_cubrZ   ©r&   rs   ÚmaskrÚ   s       r2   Úcubz
Models.cubµ  s™   € ð& �;Š;Ø—7‘7˜tŸv™v˜iÒ'ÐIÐ)IÓIÐ'Ø�< 4§:¡:Ø×#Ñ#ð2ò $ð 3à2ó3ð ô �x‰xØ7;·}±}ÀTÔ7JÓKÑ7J¨e‰U�1�d×(Ñ(Õ)Ð7JÑKó
ð 	
ùÚKó   Á3Bc           	      ó^  — | j                   rD|j                  | j                  fk(  sJ d«       ‚|�!|j                  | j                  fk(  sJ d«       ‚t	        j
                  | j                  |«      D �cg c]  }|j                  || j                  «      ‘Œ  c}d| j                  f«      S c c}w )a`  
        Evaluate the gradients of the quadratic models of the nonlinear
        inequality functions at a given point.

        Parameters
        ----------
        x : `numpy.ndarray`, shape (n,)
            Point at which to evaluate the gradients of the quadratic models of
            the nonlinear inequality functions.
        mask : `numpy.ndarray`, shape (m_nonlinear_eq,), optional
            Mask of the quadratic models to consider.

        Returns
        -------
        `numpy.ndarray`
            Gradients of the quadratic model of the nonlinear inequality
            functions.
        rq   rÝ   éÿÿÿÿ)	r   r8   r    r¸   r   Úreshaperß   r{   rZ   rà   s       r2   Úcub_gradzModels.cub_gradÑ  ó±   € ð& �;Š;Ø—7‘7˜tŸv™v˜iÒ'ÐIÐ)IÓIÐ'Ø�< 4§:¡:Ø×#Ñ#ð2ò $ð 3à2ó3ð ô �z‰zàŸ-™-¨Ô-ó/Ù-�ð �Z‰Z˜˜4×-Ñ-Õ.Ø-ñ/à�—‘ˆLó
ð 	
ùò/ó   Á3#B*c                 ó0  — | j                   r#|�!|j                  | j                  fk(  sJ d«       ‚t        j                  | j                  |«      D �cg c]  }|j                  | j                  «      ‘Œ c}d| j                  | j                  f«      S c c}w )a¶  
        Evaluate the Hessian matrices of the quadratic models of the nonlinear
        inequality functions.

        Parameters
        ----------
        mask : `numpy.ndarray`, shape (m_nonlinear_ub,), optional
            Mask of the quadratic models to consider.

        Returns
        -------
        `numpy.ndarray`
            Hessian matrices of the quadratic models of the nonlinear
            inequality functions.
        rÝ   rå   )	r   r8   r¸   r   ræ   rß   r~   rZ   r    ©r&   rá   rÚ   s      r2   Úcub_hesszModels.cub_hessï  ó�   € ð  �;Š;Ø�< 4§:¡:Ø×#Ñ#ð2ò $ð 3à2ó3ð ô �z‰zØ9=¿¹ÀtÔ9LÓMÑ9L°ˆU�Z‰Z˜×*Ñ*Õ+Ð9LÑMØ�—‘˜Ÿ™Ð ó
ð 	
ùÚMó   Á"Bc           	      ó^  — | j                   rD|j                  | j                  fk(  sJ d«       ‚|�!|j                  | j                  fk(  sJ d«       ‚t	        j
                  | j                  |«      D �cg c]  }|j                  || j                  «      ‘Œ  c}d| j                  f«      S c c}w )aÂ  
        Evaluate the right product of the Hessian matrices of the quadratic
        models of the nonlinear inequality functions with a given vector.

        Parameters
        ----------
        v : `numpy.ndarray`, shape (n,)
            Vector with which the Hessian matrices of the quadratic models of
            the nonlinear inequality functions are multiplied from the right.
        mask : `numpy.ndarray`, shape (m_nonlinear_ub,), optional
            Mask of the quadratic models to consider.

        Returns
        -------
        `numpy.ndarray`
            Right products of the Hessian matrices of the quadratic models of
            the nonlinear inequality functions with `v`.
        r€   rÝ   rå   )	r   r8   r    r¸   r   ræ   rß   rz   rZ   ©r&   r‚   rá   rÚ   s       r2   Úcub_hess_prodzModels.cub_hess_prod  óµ   € ð& �;Š;Ø—7‘7˜tŸv™v˜iÒ'ÐIÐ)IÓIÐ'Ø�< 4§:¡:Ø×#Ñ#ð2ò $ð 3à2ó3ð ô �z‰zð "Ÿ]™]¨4Ô0óá0�Eð —‘  4×#5Ñ#5Õ6Ø0ñð �—‘ˆLó
ð 	
ùòré   c           	      óD  — | j                   rD|j                  | j                  fk(  sJ d«       ‚|�!|j                  | j                  fk(  sJ d«       ‚t	        j
                  | j                  |«      D �cg c]  }|j                  || j                  «      ‘Œ  c}«      S c c}w )az  
        Evaluate the curvature of the quadratic models of the nonlinear
        inequality functions along a given direction.

        Parameters
        ----------
        v : `numpy.ndarray`, shape (n,)
            Direction along which the curvature of the quadratic models of the
            nonlinear inequality functions is evaluated.
        mask : `numpy.ndarray`, shape (m_nonlinear_ub,), optional
            Mask of the quadratic models to consider.

        Returns
        -------
        `numpy.ndarray`
            Curvature of the quadratic models of the nonlinear inequality
            functions along `v`.
        r€   rÝ   )	r   r8   r    r¸   r   rÞ   rß   r„   rZ   rð   s       r2   Úcub_curvzModels.cub_curv(  ó¦   € ð& �;Š;Ø—7‘7˜tŸv™v˜iÒ'ÐIÐ)IÓIÐ'Ø�< 4§:¡:Ø×#Ñ#ð2ò $ð 3à2ó3ð ô �x‰xàŸ-™-¨Ô-ó/Ù-�ð �Z‰Z˜˜4×-Ñ-Õ.Ø-ñ/ó
ð 	
ùò/ó   Á3#Bc           	      ó2  — | j                   rD|j                  | j                  fk(  sJ d«       ‚|�!|j                  | j                  fk(  sJ d«       ‚t	        j
                  | j                  |«      D �cg c]  } ||| j                  «      ‘Œ c}«      S c c}w )a)  
        Evaluate the quadratic models of the nonlinear equality functions at a
        given point.

        Parameters
        ----------
        x : `numpy.ndarray`, shape (n,)
            Point at which to evaluate the quadratic models of the nonlinear
            equality functions.
        mask : `numpy.ndarray`, shape (m_nonlinear_eq,), optional
            Mask of the quadratic models to consider.

        Returns
        -------
        `numpy.ndarray`
            Values of the quadratic model of the nonlinear equality functions.
        rq   rÝ   )r   r8   r    rº   r   rÞ   Ú_get_ceqrZ   rà   s       r2   Úceqz
Models.ceqE  s™   € ð$ �;Š;Ø—7‘7˜tŸv™v˜iÒ'ÐIÐ)IÓIÐ'Ø�< 4§:¡:Ø×#Ñ#ð2ò $ð 3à2ó3ð ô �x‰xØ7;·}±}ÀTÔ7JÓKÑ7J¨e‰U�1�d×(Ñ(Õ)Ð7JÑKó
ð 	
ùÚKrã   c           	      ó^  — | j                   rD|j                  | j                  fk(  sJ d«       ‚|�!|j                  | j                  fk(  sJ d«       ‚t	        j
                  | j                  |«      D �cg c]  }|j                  || j                  «      ‘Œ  c}d| j                  f«      S c c}w )aZ  
        Evaluate the gradients of the quadratic models of the nonlinear
        equality functions at a given point.

        Parameters
        ----------
        x : `numpy.ndarray`, shape (n,)
            Point at which to evaluate the gradients of the quadratic models of
            the nonlinear equality functions.
        mask : `numpy.ndarray`, shape (m_nonlinear_eq,), optional
            Mask of the quadratic models to consider.

        Returns
        -------
        `numpy.ndarray`
            Gradients of the quadratic model of the nonlinear equality
            functions.
        rq   rÝ   rå   )	r   r8   r    rº   r   ræ   rø   r{   rZ   rà   s       r2   Úceq_gradzModels.ceq_grad`  rè   ré   c                 ó0  — | j                   r#|�!|j                  | j                  fk(  sJ d«       ‚t        j                  | j                  |«      D �cg c]  }|j                  | j                  «      ‘Œ c}d| j                  | j                  f«      S c c}w )a²  
        Evaluate the Hessian matrices of the quadratic models of the nonlinear
        equality functions.

        Parameters
        ----------
        mask : `numpy.ndarray`, shape (m_nonlinear_eq,), optional
            Mask of the quadratic models to consider.

        Returns
        -------
        `numpy.ndarray`
            Hessian matrices of the quadratic models of the nonlinear equality
            functions.
        rÝ   rå   )	r   r8   rº   r   ræ   rø   r~   rZ   r    rë   s      r2   Úceq_hesszModels.ceq_hess~  rí   rî   c           	      ó^  — | j                   rD|j                  | j                  fk(  sJ d«       ‚|�!|j                  | j                  fk(  sJ d«       ‚t	        j
                  | j                  |«      D �cg c]  }|j                  || j                  «      ‘Œ  c}d| j                  f«      S c c}w )a¼  
        Evaluate the right product of the Hessian matrices of the quadratic
        models of the nonlinear equality functions with a given vector.

        Parameters
        ----------
        v : `numpy.ndarray`, shape (n,)
            Vector with which the Hessian matrices of the quadratic models of
            the nonlinear equality functions are multiplied from the right.
        mask : `numpy.ndarray`, shape (m_nonlinear_eq,), optional
            Mask of the quadratic models to consider.

        Returns
        -------
        `numpy.ndarray`
            Right products of the Hessian matrices of the quadratic models of
            the nonlinear equality functions with `v`.
        r€   rÝ   rå   )	r   r8   r    rº   r   ræ   rø   rz   rZ   rð   s       r2   Úceq_hess_prodzModels.ceq_hess_prod—  rò   ré   c           	      óD  — | j                   rD|j                  | j                  fk(  sJ d«       ‚|�!|j                  | j                  fk(  sJ d«       ‚t	        j
                  | j                  |«      D �cg c]  }|j                  || j                  «      ‘Œ  c}«      S c c}w )at  
        Evaluate the curvature of the quadratic models of the nonlinear
        equality functions along a given direction.

        Parameters
        ----------
        v : `numpy.ndarray`, shape (n,)
            Direction along which the curvature of the quadratic models of the
            nonlinear equality functions is evaluated.
        mask : `numpy.ndarray`, shape (m_nonlinear_eq,), optional
            Mask of the quadratic models to consider.

        Returns
        -------
        `numpy.ndarray`
            Curvature of the quadratic models of the nonlinear equality
            functions along `v`.
        r€   rÝ   )	r   r8   r    rº   r   rÞ   rø   r„   rZ   rð   s       r2   Úceq_curvzModels.ceq_curv·  rõ   rö   c                 ó  — t        | j                  | j                  | j                  «      | _        t        | j                  «      D ]A  }t        | j                  | j                  dd…|f   | j                  «      | j                  |<   ŒC t        | j                  «      D ]A  }t        | j                  | j                  dd…|f   | j                  «      | j                  |<   ŒC | j                  r| j                  «        yy)a9  
        Set the quadratic models of the objective function, nonlinear
        inequality constraints, and nonlinear equality constraints to the
        alternative quadratic models.

        Raises
        ------
        `numpy.linalg.LinAlgError`
            If the interpolation system is ill-defined.
        N)rc   rZ   r°   r   r·   r#   r¸   r±   r¹   rº   r²   r»   r¼   )r&   rÂ   s     r2   Úreset_modelszModels.reset_modelsÔ  sÌ   € ô ˜d×0Ñ0°$·,±,ÀÇÁÓLˆŒ	Ü�t×*Ñ*Ö+ˆAÜ$Ø×"Ñ"Ø—‘šQ ˜TÑ"Ø—‘óˆD�I‰I�aŠLð ,ô �t×*Ñ*Ö+ˆAÜ$Ø×"Ñ"Ø—‘šQ ˜TÑ"Ø—‘óˆD�I‰I�aŠLð ,ð �;Š;Ø×0Ñ0Õ2ð r4   c           	      óÐ  — | j                   ržd|cxk  r| j                  k  sJ d«       ‚ J d«       ‚|j                  | j                  fk(  sJ d«       ‚t	        |t
        «      sJ d«       ‚|j                  | j                  fk(  sJ d«       ‚|j                  | j                  fk(  sJ d«       ‚t        j                  | j                  «      }t        j                  | j                  j                  «      }t        j                  | j                  j                  «      }|| j                  |«      z
  ||<   || j                  |«      z
  ||dd…f<   || j                  |«      z
  ||dd…f<   || j                  |<   || j                  |dd…f<   || j                  |dd…f<   t        j                   | j"                  j$                  dd…|f   «      }	|| j"                  j&                  z
  | j"                  j$                  dd…|f<   | j(                  j+                  | j"                  ||	|«      }
t-        | j                  «      D ]8  }|
xs2 | j.                  |   j+                  | j"                  ||	|dd…|f   «      }
Œ: t-        | j                  «      D ]8  }|
xs2 | j0                  |   j+                  | j"                  ||	|dd…|f   «      }
Œ: | j                   r| j3                  «        |
S )aÿ  
        Update the interpolation set.

        This method updates the interpolation set by replacing the `knew`-th
        interpolation point with `xnew`. It also updates the function values
        and the quadratic models.

        Parameters
        ----------
        k_new : int
            Index of the updated interpolation point.
        x_new : `numpy.ndarray`, shape (n,)
            New interpolation point. Its value is interpreted as relative to
            the origin, not the base point.
        fun_val : float
            Value of the objective function at `x_new`.
            Objective function value at `x_new`.
        cub_val : `numpy.ndarray`, shape (m_nonlinear_ub,)
            Values of the nonlinear inequality constraints at `x_new`.
        ceq_val : `numpy.ndarray`, shape (m_nonlinear_eq,)
            Values of the nonlinear equality constraints at `x_new`.

        Raises
        ------
        `numpy.linalg.LinAlgError`
            If the interpolation system is ill-defined.
        r   r†   ú"The shape of `x_new` is not valid.z The function value is not valid.z$The shape of `cub_val` is not valid.z$The shape of `ceq_val` is not valid.N)r   r=   r8   r    Ú
isinstanceÚfloatr¸   rº   r   r   r±   r²   rÏ   râ   rù   r°   r   rZ   r$   r   r·   r�   r#   r¹   r»   r¼   )r&   r‰   Úx_newr°   r±   r²   Úfun_diffÚcub_diffÚceq_diffrŠ   rŽ   rÂ   s               r2   Úupdate_interpolationzModels.update_interpolationï  sÁ  € ð8 �;Š;Ø˜Ô( §¡Ò(ÐKÐ*KÓKÑ(ÐKÐ*KÓKÐ(Ø—;‘; 4§6¡6 )Ò+ð 5Ø4ó5Ð+ä˜g¤uÔ-ð 3Ø2ó3Ð-à—=‘=Ø×#Ñ#ð%ò ð 6à5ó6ð ð —=‘=Ø×#Ñ#ð%ò ð 6à5ó6ð ô
 —8‘8˜DŸH™HÓ%ˆÜ—8‘8˜DŸL™L×.Ñ.Ó/ˆÜ—8‘8˜DŸL™L×.Ñ.Ó/ˆØ! D§H¡H¨U£OÑ3ˆ�‰Ø$ t§x¡x°£Ñ6ˆ�š�ÑØ$ t§x¡x°£Ñ6ˆ�š�Ñð &ˆ�‰�UÑØ!(ˆ�‰�UšA�XÑØ!(ˆ�‰�UšA�XÑô —'‘'˜$×,Ñ,×0Ñ0²°E°Ñ:Ó;ˆØ+0°4×3EÑ3E×3LÑ3LÑ+Lˆ×Ñ×Ñšq %˜xÑ(ð Ÿ)™)×*Ñ*Ø×ÑØØØó	
ˆô �t×*Ñ*Ö+ˆAØ-ò °·±¸1±×1DÑ1DØ×"Ñ"ØØØš˜A˜‘ó	2‰Oð ,ô �t×*Ñ*Ö+ˆAØ-ò °·±¸1±×1DÑ1DØ×"Ñ"ØØØš˜A˜‘ó	2‰Oð ,ð �;Š;Ø×0Ñ0Ô2ØÐr4   c                 óf  — | j                   rG|j                  | j                  fk(  sJ d«       ‚|�$d|cxk  r| j                  k  sJ d«       ‚ J d«       ‚|| j                  j
                  z
  }t        j                  | j                  | j                  z   dz   df«      }d| j                  j                  j                  |z  dz  z  |d| j                  …df<   d|| j                  df<   ||| j                  dz   d…df<   t        j                  | j                  |«      d   }d||z  dz  z  |dd…df   |dd…df   z  z
  }|€„t        j                  | j                  | j                  z   dz   | j                  «      }t        j                  t        j                  | j                  |«      d   «      }|d| j                  …df   }	nat        j                  | j                  | j                  z   dz   d| «      }t        j                  | j                  |«      d   |df   }||df   }	||z  |	dz  z   S )	aÎ  
        Compute the normalized determinants of the new interpolation systems.

        Parameters
        ----------
        x_new : `numpy.ndarray`, shape (n,)
            New interpolation point. Its value is interpreted as relative to
            the origin, not the base point.
        k_new : int, optional
            Index of the updated interpolation point. If `k_new` is not
            specified, all the possible determinants are computed.

        Returns
        -------
        {float, `numpy.ndarray`, shape (npt,)}
            Determinant(s) of the new interpolation system.

        Raises
        ------
        `numpy.linalg.LinAlgError`
            If the interpolation system is ill-defined.

        Notes
        -----
        The determinants are normalized by the determinant of the current
        interpolation system. For stability reasons, the calculations are done
        using the formula (2.12) in [1]_.

        References
        ----------
        .. [1] M. J. D. Powell. On updating the inverse of a KKT matrix.
           Technical Report DAMTP 2004/NA01, Department of Applied Mathematics
           and Theoretical Physics, University of Cambridge, Cambridge, UK,
           2004.
        r  Nr   r†   r   r   r   rQ   )r   r8   r    r=   rZ   r   r   rY   r$   rX   rc   r¡   ÚeyeÚdiag)
r&   r  r‰   r“   Únew_colÚinv_new_colÚbetaÚ	coord_vecÚalphaÚtaus
             r2   ÚdeterminantszModels.determinantsB  sI  € ðH �;Š;Ø—;‘; 4§6¡6 )Ò+ð 5Ø4ó5Ð+ð �  eÔ!6¨d¯h©hÒ!6ð1à0ó1Ø6Ð!6ð1à0ó1Ø6ð ˜×*Ñ*×1Ñ1Ñ1ˆÜ—(‘(˜DŸH™H t§v¡vÑ-°Ñ1°1Ð5Ó6ˆà�t×)Ñ)×-Ñ-×/Ñ/°%Ñ7¸CÑ?Ñ?ð 	�
�$—(‘(�
˜A�Ñà"ˆ�—‘˜!�ÑØ$)ˆ�—‘˜1‘‘˜qÐ Ñ!Ü×-Ñ-¨d×.@Ñ.@À'ÓJÈ1ÑMˆØ�e˜e‘m¨Ñ+Ñ+¨g²a¸°d©m¸kÊ!ÈQÈ$Ñ>OÑ.OÑOˆð ˆ=ÜŸ™˜tŸx™x¨$¯&©&Ñ0°1Ñ4°d·h±hÓ?ˆIÜ—G‘GÜ×'Ñ'Ø×&Ñ&Øóð ñóˆEð ˜j §¡˜j¨!˜mÑ,‰CäŸ™˜tŸx™x¨$¯&©&Ñ0°1Ñ4°a¸%¸Ó@ˆIÜ×+Ñ+Ø×"Ñ"Øóð ñ	ð
 �QˆhñˆEð ˜e Q˜hÑ'ˆCØ�t‰|˜c 3™hÑ&Ð&r4   c                 ó~  — | j                   r!|j                  | j                  fk(  sJ d«       ‚| j                  j	                  | j
                  |«       | j                  D ]  }|j	                  | j
                  |«       Œ  | j                  D ]  }|j	                  | j
                  |«       Œ  || j
                  j                  z
  }| j
                  xj                  |z  c_        | j
                  xj                  |dd…t        j                  f   z  c_	        |t        j                     r| j                  «        yy)zü
        Shift the base point without changing the interpolation set.

        Parameters
        ----------
        new_x_base : `numpy.ndarray`, shape (n,)
            New base point.
        options : dict
            Options of the solver.
        r‘   N)r   r8   r    r·   r”   rZ   r¹   r»   r   r$   r   r}   r   r   r¼   )r&   r’   r(   rÚ   r“   s        r2   r”   zModels.shift_x_baseŒ  s  € ð �;Š;Ø×#Ñ#Ø—‘ð(ò ð 9à8ó9ð ð
 	�	‰	×Ñ˜t×1Ñ1°:Ô>Ø—Y”YˆEØ×Ñ˜t×1Ñ1°:Õ>ð à—Y”YˆEØ×Ñ˜t×1Ñ1°:Õ>ð ð ˜T×/Ñ/×6Ñ6Ñ6ˆØ×Ñ×!Ò! UÑ*Õ!Ø×Ñ×Ò %ª¬2¯:©:¨Ñ"6Ñ6ÕØ”7—=‘=Ò!Ø×0Ñ0Õ2ð "r4   c                 ó<   — |€| j                   S | j                   |   S )ao  
        Get the quadratic models of the nonlinear inequality constraints.

        Parameters
        ----------
        mask : `numpy.ndarray`, shape (m_nonlinear_ub,), optional
            Mask of the quadratic models to return.

        Returns
        -------
        `numpy.ndarray`
            Quadratic models of the nonlinear inequality constraints.
        )r¹   ©r&   rá   s     r2   rß   zModels._get_cubª  ó   € ð !˜Lˆt�y‰yÐ=¨d¯i©i¸©oÐ=r4   c                 ó<   — |€| j                   S | j                   |   S )ak  
        Get the quadratic models of the nonlinear equality constraints.

        Parameters
        ----------
        mask : `numpy.ndarray`, shape (m_nonlinear_eq,), optional
            Mask of the quadratic models to return.

        Returns
        -------
        `numpy.ndarray`
            Quadratic models of the nonlinear equality constraints.
        )r»   r  s     r2   rø   zModels._get_ceqº  r  r4   c                 ó  — d}d}d}t        | j                  «      D �]1  }t        j                  |t        j                  | j                  | j                  j                  |«      «      | j                  |   z
  «      g«      }t        j                  t        j                  | j                  | j                  j                  |«      «      | j                  |dd…f   z
  «      |¬«      }t        j                  t        j                  | j                  | j                  j                  |«      «      | j                  |dd…f   z
  «      |¬«      }�Œ4 dt        j                  t        «      z  t        | j                  | j                  «      z  }||t        j                  t        j                  | j                  «      d¬«      z  kD  rt!        j"                  dt$        d«       ||t        j                  t        j                  | j                  «      d¬«      z  kD  rt!        j"                  dt$        d«       ||t        j                  t        j                  | j                  «      d¬«      z  kD  rt!        j"                  d	t$        d«       yy)
zM
        Check the interpolation conditions of all quadratic models.
        r‡   NrO   g      $@rQ   zJThe interpolation conditions for the objective function are not satisfied.r   zVThe interpolation conditions for the inequality constraint function are not satisfied.zTThe interpolation conditions for the equality constraint function are not satisfied.)r#   r=   r   rT   rš   rÏ   rZ   rC   r°   râ   r±   rù   r²   ÚsqrtrW   r    ÚwarningsÚwarnÚRuntimeWarning)r&   Ú	error_funÚ	error_cubÚ	error_ceqr.   Útols         r2   r¼   z&Models._check_interpolation_conditionsÊ  s÷  € ð ˆ	Øˆ	Øˆ	Ü�t—x‘x—ˆAÜŸ™àÜ—F‘FØŸ™ ×!3Ñ!3×!9Ñ!9¸!Ó!<Ó=ÀÇÁÈQÁÑOóðóˆIô Ÿ™Ü—‘Ø—H‘H˜T×/Ñ/×5Ñ5°aÓ8Ó9¸D¿L¹LÈÊAÈÑ<NÑNóð "ô	ˆIô Ÿ™Ü—‘Ø—H‘H˜T×/Ñ/×5Ñ5°aÓ8Ó9¸D¿L¹LÈÊAÈÑ<NÑNóð "ô	ŠIð !ð* ”R—W‘WœS“\Ñ!¤C¨¯©°·±Ó$9Ñ9ˆØ�sœRŸV™V¤B§F¡F¨4¯<©<Ó$8À#ÔFÑFÒFÜ�M‰Mð!äØô	ð �sœRŸV™V¤B§F¡F¨4¯<©<Ó$8À#ÔFÑFÒFÜ�M‰Mð.äØô	ð �sœRŸV™V¤B§F¡F¨4¯<©<Ó$8À#ÔFÑFÒFÜ�M‰Mð.äØõ	ð Gr4   )N)%rD   rE   rF   rG   r3   rH   r    r=   r¸   rº   rZ   r°   r±   r²   rÏ   rÑ   rÓ   rÖ   rØ   rÛ   râ   rç   rì   rñ   rô   rù   rû   rý   rÿ   r  r  r  r  r”   rß   rø   r¼   rJ   r4   r2   r¦   r¦   p  s'  „ ñòa3ðF ñ	$ó ð	$ð ñ	&ó ð	&ð ñ	%ó ð	%ð ñ	%ó ð	%ð ñ	#ó ð	#ð ñ	ó ð	ð ñó ðð ñó ðò0ò(5ò(
2ò:ò*5ò*1ó6
ó8
ó<
ó2
ó@
ó:
ó6
ó<
ó2
ó@
ò:3ò6QófH'òT3ó<>ó >ó 1r4   r¦   )r  Únumpyr   Úscipy.linalgr   Úsettingsr   Úutilsr   r   r   Úfinfor  ÚepsrW   r
   ra   rc   r¦   rJ   r4   r2   Ú<module>r+     s\   ðÛ ã Ý å ß ?Ñ ?ð €b‡h�hˆuƒo×Ñ€÷s,ñ s,òl27÷juFñ uF÷pKò Kr4   