§
    fŠtjÆ  ã                   óÀ   — 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dS )é    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d
S )Ú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                 óÜ  — |t           j                 | _        dt          j        |j        j        |j        j        z
  ¦  «        z  }|t           j                 |k    rL||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    rL||dz
           r!|t           j                  | j        |dz
  |f<   Œ:|t           j                 | j        |dz
  |f<   ŒZ|d|j        z  k    r¦|||j        z
  dz
           r+d|t           j                 z  | j        ||j        z
  dz
  |f<   Œ¦|||j        z
  dz
           r+d|t           j                 z  | j        ||j        z
  dz
  |f<   Œä|t           j                  | j        ||j        z
  dz
  |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| _        dS )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               úV/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/scipy/_lib/cobyqa/models.pyÚ__init__zInterpolation.__init__   sì  € ð �gœmÔ,ˆŒØ�2œ6 "¤)¤,°´´Ñ"=Ñ>Ô>Ñ>ˆ
Ø•7”>Ô" ZÒ/Ð/Ø,6ˆG•G”NÔ(Ñ)Ý,.¬Fà�GœNÔ+Øðñ-ô -ˆG•G”NÔ(Ñ)õ ”w˜rœu‘~”~ˆŒàŒK˜2œ9œ<¨#°½¼Ô0GÑ*GÑGÒGð 	ð *,¬¬Ð6GÔ)HˆŒÐ%Ñ&àŒIŒL˜3 ­¬Ô!8Ñ8Ñ8¸4¼;ÒFØŒ[˜BœIœL¨7µ7´>Ô+BÑBÒBñDˆõ %'¤JØŒIŒL˜Ô&¨µ´Ô)@Ñ@ØŒIŒL˜Ô&ñ%
ô %
ˆŒ�LÑ!ð
 ŒK˜2œ9œ<¨#°½¼Ô0GÑ*GÑGÒGð 	ð *,¬¬Ð6GÔ)HˆŒÐ%Ñ&àŒK˜"œ)œ,¨¨wµw´~Ô/FÑ)FÑFÒFØŒYŒ\˜G¥G¤NÔ3Ñ3°t´{ÒBñDˆõ %'¤JØŒIŒL˜Ô&¨µ´Ô)@Ñ@ØŒIŒL˜Ô&ñ%
ô %
ˆŒ�LÑ!õ ”H˜bœd G­G¬KÔ$8Ð9Ñ:Ô:ˆŒ	Ý�q˜'¥'¤+Ô.Ñ/Ô/ð 	7ñ 	7ˆAØ�B”DŠyˆyØ$ Q¨¡UÔ+ð AØ*1µ'´.Ô*AÐ)A�D”H˜Q ™U A˜XÑ&Ð&à)0µ´Ô)@�D”H˜Q ™U A˜XÑ&Ð&Ø�a˜"œ$‘h’�Ø$ Q¨¬¡X°¡\Ô2ð IØ03°g½g¼nÔ6MÑ0M�D”H˜Q ¤™X¨™\¨1˜_Ñ-Ð-Ø& q¨2¬4¡x°!¡|Ô4ð IØ04°w½w¼~Ô7NÑ0N�D”H˜Q ¤™X¨™\¨1˜_Ñ-Ð-à18½¼Ô1HÐ0H�D”H˜Q ¤™X¨™\¨1˜_Ñ-Ñ-à˜bœd™( Q™,¨2¬4Ñ/�Ø˜!˜f™*¨¬Ñ,Ñ,¨qÑ0�Ø˜6‘k R¤TÑ)�Ø"&¤(¨2¨r°A©v¨:Ô"6�”˜˜Q˜‘Ø"&¤(¨2¨r°A©v¨:Ô"6�”˜˜Q˜‘‘ØˆŒˆˆó    c                 ó&   — | j         j        d         S )út
        Number of variables.

        Returns
        -------
        int
            Number of variables.
        r   ©r$   Úshape©r&   s    r2   r    zInterpolation.n]   ó   € ð ŒxŒ~˜aÔ Ð r4   c                 ó&   — | 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Ðr4   c                 ód   — | j         r!|j        | j        | j        fk    s
J d¦   «         ‚|| _        dS )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�   sR   € ð Œ;ð 	2Ø”9Ø”Ø”ð!ò ð ð ð 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                 óX   — | j         r|j        | j        fk    s
J d¦   «         ‚|| _        dS )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ž   sK   € ð Œ;ð 	5Ø”<Ø”ð$ò ð ð à4ñô ð ð ˆŒˆˆr4   c                 ó~   — | j         rd|cxk    r| j        k     sn 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®   sZ   € ð  Œ;ð 	DØ˜Ð$Ð$Ò$Ð$˜DœHÒ$Ð$Ð$Ð$Ð$Ð&CÑ$Ô$Ð$ØŒ{˜TœX a a a¨ dœ^Ñ+Ð+r4   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r3   Úpropertyr    r=   r$   Úsetterr   rC   © r4   r2   r
   r
      sæ   € € € € € ðð ðEð Eð EðN ð	!ð 	!ñ „Xð	!ð ð	!ð 	!ñ „Xð	!ð ð	ð 	ñ „Xð	ð 	„Zðð ñ „Zðð  ð	ð 	ñ „Xð	ð „]ðð ñ „]ðð,ð ,ð ,ð ,ð ,r4   r
   c                 óB  — | j         }|�7t          j        | j        |d         ¦  «        r|d         |d         |d         fS t          j        t          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ØÔ˜6 %œ=ñô Ðð �cŒ{˜F ?Ô3°V¸F´^ÐCÐCåŒF•2”9—>’> -Ô"3¸!�>Ñ<Ô<ÅcÐJÑJÔ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ˆH€nÑØ€A€cˆ4ˆCˆ4€i�LØ!€A€cˆA�g€h€h���€nÑõ ”H˜S 1™W q™[Ñ)Ô)€MØ  s¡
Ñ*€M�$�3�$ÑØ ™€M�#ÑØ#€M�#˜‘'�(�(Ñå" 1°5Ð9Ñ9Ô9Ñ€J�õ Œw�}Ô(Ñ)Ô)ÝŒW�Q‰ZŒ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dS )Ú	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                 óR  — || _         | j         r|j        |j        fk    s
J d¦   «         ‚|j        |j        dz   k     rt	          d|j        dz   › d�¦  «        ‚|                      ||¦  «        \  | _        | _        | _        }t          j
        | j        | j        f¦  «        | _        dS )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ñô ð ð Ô˜}œ°Ñ2Ò2Ð2Ýð*Ø ”? QÑ&ð*ð *ð *ñô ð ð 48·?²?ØØñ4
ô 4
Ñ0ˆŒ�T”Z ¤¨qõ ”x ¤¨¬Ð 0Ñ1Ô1ˆŒˆˆr4   c                 óÖ   — | 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�   € ð  Œ;ð 	JØ”7˜tœv˜iÒ'Ð'Ð'Ð)IÑ'Ô'Ð'Ø�]Ô)Ñ)ˆàŒKØŒj˜6Ñ!ñ"àà” Ô 1Ô 3°fÑ <ÀÑDÑDØ˜4œ<Ñ'¨&Ñ0ñ1ññð	
r4   c                 ó   — | j         j        S )r6   )rj   Úsizer9   s    r2   r    zQuadratic.nG  s   € ð Œ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        |                      ||¦  «        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_  sW   € ð  Œ;ð 	JØ”7˜tœv˜iÒ'Ð'Ð'Ð)IÑ'Ô'Ð'Ø�]Ô)Ñ)ˆØŒz˜DŸNšN¨6°=ÑAÔAÑAÐAr4   c                 ór   — | 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  s<   € ð Œ|˜mÔ/ØŒL˜˜˜�Bœ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†  sb   € ð& Œ;ð 	JØ”7˜tœv˜iÒ'Ð'Ð'Ð)IÑ'Ô'Ð'ØŒ|˜aÑ -Ô"3ØŒ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Ÿ  sb   € ð" Œ;ð 	JØ”7˜tœv˜iÒ'Ð'Ð'Ð)IÑ'Ô'Ð'à�”Ñ˜qÑ ØŒl˜mÔ/Ô1°AÑ5¸#Ñ=Ñ=ñ>ð	
r4   c                 óÈ  — | j         rTd|cxk    r| j        k     sn 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        |<   |                      ||¦  «        \  }}}}| 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·  s3  € ð4 Œ;ð 	:Ø˜Ð(Ð(Ò(Ð( ¤Ò(Ð(Ð(Ð(Ð(Ð*KÑ(Ô(Ð(Ø”=Ø”ð%ò ð ð à5ñô ð ð Ô$Ø”ð)ò ð ð à9ñô ð ð 	ˆŒ˜œ UÔ+­b¬h°wÀÑ.HÔ.HÑHÑHˆŒØ!ˆŒ�UÑð 04¯ªØØñ0
ô 0
Ñ,ˆˆt�V˜_ð 	ˆŒ�uÑˆŒØˆ
Œ
�dÑˆ
Œ
ØˆŒ˜ÑˆŒØÐr4   c                 ó^  — | j         r|j        | j        fk    s
J d¦   «         ‚ | ||¦  «        | _        |                      ||¦  «        | _        ||j        z
  }t          j        ||j	        d|dd…t          j
        f         z  z
  | j        z  ¦  «        }| xj        ||j        z   z  c_        dS )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ñô ð ð �d˜: }Ñ5Ô5ˆŒØ—Y’Y˜z¨=Ñ9Ô9ˆŒ
Ø˜]Ô1Ñ1ˆÝ”ØØÔ  u¨Q¨Q¨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         	                    d¦  «        ‚|\  }}	t	          j
        |¦  «        t          k    }
|	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  ss  € ð0 Ô"Ô(‰ˆˆ3àŒH˜ŠMˆM˜cœi¨œl¨c°A©g¸©kÒ9Ð9Ð9Ø-ñ :Ô9Ð9õ !-¨]Ñ ;Ô ;Ñˆˆ=˜#ð ˜=¨¨¨­B¬J¨Ô7Ñ7ˆ
Ý”•r”{ 1‘~”~Ñ&Ô&ð 	­2¬6µ"´+¸jÑ2IÔ2IÑ+JÔ+Jð 	Ý”)×'Ò'Ø:ñô ð ð
 #&Ñˆ
�Kåœ6 *Ñ-Ô-µÒ3ÐØ! ! ! !Ð%5Ð"5Ô6ˆØ˜zÐ*:Ô;Ñ;ˆÝœ6Ð"2°AÑ6Ô6Ð6ˆØ +ØŒ]˜ZÑ'¨>¸!¸!¸!½R¼Z¸-Ô+HÑHñ!
Ðð " M°!°!°!µR´Z°-Ô$@Ñ@Øð
ð 	
r4   c           
      ó:  — |j         | j        fk    s
J d¦   «         ‚| j        j         \  }}t                               | 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 Œ|ØÔð 
ò 
ð 
ð 
à0ñ
ô 
ð 
ð Ô"Ô(‰ˆˆ3Ý&×4Ò4ØÝŒHð Ýœ  Q¡™œððñô ô ñ

ô 

Ñˆˆ?ð ��a�Œy˜!˜C !™G˜H˜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ð  2ð  2ðD
ð 
ð 
ð: ð	ð 	ñ „Xð	ð ð	!ð 	!ñ „Xð	!ðBð Bð Bð*
ð 
ð 
ð$
ð 
ð 
ð2
ð 
ð 
ð02ð 2ð 2ðh*ð *ð *ð0 ð>
ð >
ñ „\ð>
ð@ ð(Fð (Fñ „\ð(Fð (Fð (Fr4   rc   c                   ól  — 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$dS )$ÚModelsz6
    Models for a nonlinear optimization problem.
    c           	      óä  — |t           j                 | _        t          ||¦  «        | _        | 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    r'|| j        |<   || j        |dd…f<   || j        |dd…f<   nJ| j                             |¦  «        } |||¦  «        \  | j        |<   | j        |dd…f<   | j        |dd…f<   |j        rh|                     | j                             |¦  «        | j        |dd…f         | j        |dd…f         ¦  «        |t           j                 k    rt0          ‚| j        |         |t           j                 k    rh|                     | j                             |¦  «        | j        |dd…f         | j        |dd…f         ¦  «        |t           j                 k    rt4          ‚�Œ‘t7          | j        | j        |t           j                 ¦  «        | _        t          j        | j        t6          ¬¦  «        | _        t          j        | j         t6          ¬¦  «        | _!        t          | j        ¦  «        D ]?}	t7          | j        | j        dd…|	f         |t           j                 ¦  «        | j        |	<   Œ@t          | j         ¦  «        D ]?}	t7          | j        | j        dd…|	f         |t           j                 ¦  «        | j!        |	<   Œ@| j        r|  "                    ¦   «          dS dS )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  s±  € ð6 �gœmÔ,ˆŒÝ+¨B°Ñ8Ô8ˆÔð Ô#×)Ò)¨!Ñ,Ô,ˆØ') r¨&°'Ñ':Ô':Ñ$ˆ�(˜HÝœ ­¬Ô 4µb´fÑ=Ô=ˆŒÝœ ­¬Ô!5°x´}Ð EÅrÄvÑNÔNˆŒÝœ ­¬Ô!5°x´}Ð EÅrÄvÑNÔNˆŒÝ�w�wœ{Ô+Ñ,Ô,ð &	$ñ &	$ˆAØ�G�GÔ,Ô-Ò-Ð-Ý"Ð"Ø�AŠvˆvØ"*�”˜Q‘Ø%-�”˜Q   ˜TÑ"Ø%-�”˜Q   ˜TÑ"Ð"àÔ+×1Ò1°!Ñ4Ô4�ØJLÈ"ØØñKô KÑG�”˜Q‘ ¤¨a°°°¨dÑ!3°T´\À!ÀQÀQÀQÀ$Ñ5Gð Ô!ð	&à—H’HØÔ&×,Ò,¨QÑ/Ô/Ø”L  A A A Ô&Ø”L  A A A Ô&ñô ð
 �7Ô2Ô3ò4ð 4õ &Ð%ð
 ”˜aÔ  G­G¬NÔ$;Ò;Ð;Ø—H’HØÔ&×,Ò,¨QÑ/Ô/Ø”L  A A A Ô&Ø”L  A A A Ô&ñô ð
 �7Ô2Ô3ò4ð 4õ $Ð#ùõ ØÔØŒMØ•G”MÔ"ñ
ô 
ˆŒ	õ
 ”H˜TÔ0½	ÐBÑBÔBˆŒ	Ý”H˜TÔ0½	ÐBÑBÔBˆŒ	Ý�tÔ*Ñ+Ô+ð 	ð 	ˆAÝ$ØÔ"Ø”˜Q˜Q˜Q ˜TÔ"Ø�œÔ&ñô ˆDŒI�a‰LˆLõ
 �tÔ*Ñ+Ô+ð 	ð 	ˆAÝ$ØÔ"Ø”˜Q˜Q˜Q ˜TÔ"Ø�œÔ&ñô ˆDŒI�a‰LˆLð
 Œ;ð 	3Ø×0Ò0Ñ2Ô2Ð2Ð2Ð2ð	3ð 	3r4   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                 ó&   — | 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                 ó&   — | 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        ¦  «        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<  sF   € ð  Œ;ð 	JØ”7˜tœv˜iÒ'Ð'Ð'Ð)IÑ'Ô'Ð'Ø�yŠy˜˜DÔ.Ñ/Ô/Ð/r4   c                 ó†   — | j         r|j        | j        fk    s
J d¦   «         ‚| 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  sH   € ð  Œ;ð 	JØ”7˜tœv˜iÒ'Ð'Ð'Ð)IÑ'Ô'Ð'ØŒy�~Š~˜a Ô!3Ñ4Ô4Ð4r4   c                 ó@   — | 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�~Š~˜dÔ0Ñ1Ô1Ð1r4   c                 ó†   — | j         r|j        | j        fk    s
J d¦   «         ‚| 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  sJ   € ð" Œ;ð 	JØ”7˜tœv˜iÒ'Ð'Ð'Ð)IÑ'Ô'Ð'ØŒy×"Ò" 1 dÔ&8Ñ9Ô9Ð9r4   c                 ó†   — | j         r|j        | j        fk    s
J d¦   «         ‚| 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…  sH   € ð" Œ;ð 	JØ”7˜tœv˜iÒ'Ð'Ð'Ð)IÑ'Ô'Ð'ØŒy�~Š~˜a Ô!3Ñ4Ô4Ð4r4   c                 ó¼   — | j         r|j        | j        fk    s
J d¦   «         ‚t          | 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^   € ð, Œ;ð 	JØ”7˜tœv˜iÒ'Ð'Ð'Ð)IÑ'Ô'Ð'Ý˜$Ô,¨d¬l¸D¼KÑHÔHˆØ�zŠz˜!˜TÔ/Ñ0Ô0Ð0r4   Nc                 óì   ‡ ‡— ‰ j         r8‰j        ‰ j        fk    s
J d¦   «         ‚|�|j        ‰ j        fk    s
J d¦   «         ‚t	          j        ˆ ˆfd„‰                      |¦  «        D ¦   «         ¦  «        S )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   Nú!The shape of `mask` is not valid.c                 ó2   •— g | ]} |‰‰j         ¦  «        ‘ŒS rJ   ©rZ   ©Ú.0rÚ   r&   rs   s     €€r2   ú
<listcomp>zModels.cub.<locals>.<listcomp>Î  ó(   ø€ ÐKÐKÐK¨eˆUˆU�1�dÔ(Ñ)Ô)ÐKÐKÐKr4   ©r   r8   r    r¸   r   ÚarrayÚ_get_cub©r&   rs   Úmasks   `` r2   Úcubz
Models.cubµ  s¡   øø€ ð& Œ;ð 	3Ø”7˜tœv˜iÒ'Ð'Ð'Ð)IÑ'Ô'Ð'Ø�< 4¤:ØÔ#ð2ò $ð $ð $à2ñ$ô $ð õ ŒxØKÐKÐKÐKÐK°t·}²}ÀTÑ7JÔ7JÐKÑKÔKñ
ô 
ð 	
r4   c                 óü   ‡ ‡— ‰ j         r8‰j        ‰ j        fk    s
J d¦   «         ‚|�|j        ‰ j        fk    s
J d¦   «         ‚t	          j        ˆ ˆfd„‰                      |¦  «        D ¦   «         d‰ j        f¦  «        S )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   NrÝ   c                 óF   •— g | ]}|                      ‰‰j        ¦  «        ‘ŒS rJ   ©r{   rZ   rà   s     €€r2   râ   z#Models.cub_grad.<locals>.<listcomp>ê  ó:   ø€ ð /ð /ð /Øð �ZŠZ˜˜4Ô-Ñ.Ô.ð /ð /ð /r4   éÿÿÿÿ©r   r8   r    r¸   r   Úreshaperæ   rç   s   `` r2   Úcub_gradzModels.cub_gradÑ  ó»   øø€ ð& Œ;ð 	3Ø”7˜tœv˜iÒ'Ð'Ð'Ð)IÑ'Ô'Ð'Ø�< 4¤:ØÔ#ð2ò $ð $ð $à2ñ$ô $ð õ Œzð/ð /ð /ð /ð /ØŸ-š-¨Ñ-Ô-ð/ñ /ô /à�”ˆLñ
ô 
ð 	
r4   c                 óÎ   ‡ — ‰ j         r|�|j        ‰ j        fk    s
J d¦   «         ‚t          j        ˆ fd„‰                      |¦  «        D ¦   «         d‰ j        ‰ j        f¦  «        S )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.
        NrÝ   c                 óD   •— g | ]}|                      ‰j        ¦  «        ‘ŒS rJ   ©r~   rZ   ©rá   rÚ   r&   s     €r2   râ   z#Models.cub_hess.<locals>.<listcomp>  ó(   ø€ ÐMÐMÐM°ˆU�ZŠZ˜Ô*Ñ+Ô+ÐMÐMÐMr4   rî   )r   r8   r¸   r   rð   ræ   r    ©r&   rè   s   ` r2   Úcub_hesszModels.cub_hessï  ó‹   ø€ ð  Œ;ð 	3Ø�< 4¤:ØÔ#ð2ò $ð $ð $à2ñ$ô $ð õ ŒzØMÐMÐMÐM¸¿ºÀtÑ9LÔ9LÐMÑMÔMØ�”˜œÐ ñ
ô 
ð 	
r4   c                 óü   ‡ ‡— ‰ j         r8‰j        ‰ j        fk    s
J d¦   «         ‚|�|j        ‰ j        fk    s
J d¦   «         ‚t	          j        ˆ ˆfd„‰                      |¦  «        D ¦   «         d‰ j        f¦  «        S )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€   NrÝ   c                 óF   •— g | ]}|                      ‰‰j        ¦  «        ‘ŒS rJ   ©rz   rZ   ©rá   rÚ   r&   r‚   s     €€r2   râ   z(Models.cub_hess_prod.<locals>.<listcomp>!  ó:   ø€ ð ð ð àð —’  4Ô#5Ñ6Ô6ðð ð r4   rî   rï   ©r&   r‚   rè   s   `` r2   Úcub_hess_prodzModels.cub_hess_prod  ó½   øø€ ð& Œ;ð 	3Ø”7˜tœv˜iÒ'Ð'Ð'Ð)IÑ'Ô'Ð'Ø�< 4¤:ØÔ#ð2ò $ð $ð $à2ñ$ô $ð õ Œzðð ð ð ð à!Ÿ]š]¨4Ñ0Ô0ðñ ô ð �”ˆLñ
ô 
ð 	
r4   c                 óì   ‡ ‡— ‰ j         r8‰j        ‰ j        fk    s
J d¦   «         ‚|�|j        ‰ j        fk    s
J d¦   «         ‚t	          j        ˆ ˆfd„‰                      |¦  «        D ¦   «         ¦  «        S )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€   NrÝ   c                 óF   •— g | ]}|                      ‰‰j        ¦  «        ‘ŒS rJ   ©r„   rZ   rþ   s     €€r2   râ   z#Models.cub_curv.<locals>.<listcomp>A  rí   r4   rä   r   s   `` r2   Úcub_curvzModels.cub_curv(  ó²   øø€ ð& Œ;ð 	3Ø”7˜tœv˜iÒ'Ð'Ð'Ð)IÑ'Ô'Ð'Ø�< 4¤:ØÔ#ð2ò $ð $ð $à2ñ$ô $ð õ Œxð/ð /ð /ð /ð /ØŸ-š-¨Ñ-Ô-ð/ñ /ô /ñ
ô 
ð 	
r4   c                 óì   ‡ ‡— ‰ j         r8‰j        ‰ j        fk    s
J d¦   «         ‚|�|j        ‰ j        fk    s
J d¦   «         ‚t	          j        ˆ ˆfd„‰                      |¦  «        D ¦   «         ¦  «        S )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   NrÝ   c                 ó2   •— g | ]} |‰‰j         ¦  «        ‘ŒS rJ   rß   rà   s     €€r2   râ   zModels.ceq.<locals>.<listcomp>]  rã   r4   ©r   r8   r    rº   r   rå   Ú_get_ceqrç   s   `` r2   Úceqz
Models.ceqE  s¡   øø€ ð$ Œ;ð 	3Ø”7˜tœv˜iÒ'Ð'Ð'Ð)IÑ'Ô'Ð'Ø�< 4¤:ØÔ#ð2ò $ð $ð $à2ñ$ô $ð õ ŒxØKÐKÐKÐKÐK°t·}²}ÀTÑ7JÔ7JÐKÑKÔKñ
ô 
ð 	
r4   c                 óü   ‡ ‡— ‰ j         r8‰j        ‰ j        fk    s
J d¦   «         ‚|�|j        ‰ j        fk    s
J d¦   «         ‚t	          j        ˆ ˆfd„‰                      |¦  «        D ¦   «         d‰ j        f¦  «        S )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   NrÝ   c                 óF   •— g | ]}|                      ‰‰j        ¦  «        ‘ŒS rJ   rì   rà   s     €€r2   râ   z#Models.ceq_grad.<locals>.<listcomp>y  rí   r4   rî   ©r   r8   r    rº   r   rð   r  rç   s   `` r2   Úceq_gradzModels.ceq_grad`  rò   r4   c                 óÎ   ‡ — ‰ j         r|�|j        ‰ j        fk    s
J d¦   «         ‚t          j        ˆ fd„‰                      |¦  «        D ¦   «         d‰ j        ‰ j        f¦  «        S )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.
        NrÝ   c                 óD   •— g | ]}|                      ‰j        ¦  «        ‘ŒS rJ   rõ   rö   s     €r2   râ   z#Models.ceq_hess.<locals>.<listcomp>“  r÷   r4   rî   )r   r8   rº   r   rð   r  r    rø   s   ` r2   Úceq_hesszModels.ceq_hess~  rú   r4   c                 óü   ‡ ‡— ‰ j         r8‰j        ‰ j        fk    s
J d¦   «         ‚|�|j        ‰ j        fk    s
J d¦   «         ‚t	          j        ˆ ˆfd„‰                      |¦  «        D ¦   «         d‰ j        f¦  «        S )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€   NrÝ   c                 óF   •— g | ]}|                      ‰‰j        ¦  «        ‘ŒS rJ   rý   rþ   s     €€r2   râ   z(Models.ceq_hess_prod.<locals>.<listcomp>°  rÿ   r4   rî   r  r   s   `` r2   Úceq_hess_prodzModels.ceq_hess_prod—  r  r4   c                 óì   ‡ ‡— ‰ j         r8‰j        ‰ j        fk    s
J d¦   «         ‚|�|j        ‰ j        fk    s
J d¦   «         ‚t	          j        ˆ ˆfd„‰                      |¦  «        D ¦   «         ¦  «        S )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€   NrÝ   c                 óF   •— g | ]}|                      ‰‰j        ¦  «        ‘ŒS rJ   r  rþ   s     €€r2   râ   z#Models.ceq_curv.<locals>.<listcomp>Ð  rí   r4   r
  r   s   `` r2   Úceq_curvzModels.ceq_curv·  r  r4   c                 ó®  — t          | j        | j        | j        ¦  «        | _        t          | j        ¦  «        D ]4}t          | j        | j        dd…|f         | j        ¦  «        | j        |<   Œ5t          | j	        ¦  «        D ]4}t          | j        | j
        dd…|f         | j        ¦  «        | j        |<   Œ5| j        r|                      ¦   «          dS dS )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°$´,ÀÄÑLÔLˆŒ	Ý�tÔ*Ñ+Ô+ð 	ð 	ˆAÝ$ØÔ"Ø”˜Q˜Q˜Q ˜TÔ"Ø”ñô ˆDŒI�a‰LˆLõ
 �tÔ*Ñ+Ô+ð 	ð 	ˆAÝ$ØÔ"Ø”˜Q˜Q˜Q ˜TÔ"Ø”ñô ˆDŒI�a‰LˆLð
 Œ;ð 	3Ø×0Ò0Ñ2Ô2Ð2Ð2Ð2ð	3ð 	3r4   c           	      ó  — | j         rŽd|cxk    r| j        k     sn 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        ¦  «        }||                      |¦  «        z
  ||<   ||                      |¦  «        z
  ||dd…f<   ||                      |¦  «        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        ||	|¦  «        }
t-          | j        ¦  «        D ]6}|
p1| j        |                              | j        ||	|dd…|f         ¦  «        }
Œ7t-          | j        ¦  «        D ]6}|
p1| j        |                              | j        ||	|dd…|f         ¦  «        }
Œ7| j         r|                      ¦   «          |
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 Œ;ð 	6Ø˜Ð(Ð(Ò(Ð( ¤Ò(Ð(Ð(Ð(Ð(Ð*KÑ(Ô(Ð(Ø”; 4¤6 )Ò+Ð+Ð+Ø4ñ ,Ô+Ð+å˜g¥uÑ-Ô-ð 3ð 3Ø2ñ3ô 3Ð-à”=ØÔ#ð%ò ð ð à5ñô ð ð ”=ØÔ#ð%ò ð ð à5ñô ð õ
 ”8˜DœHÑ%Ô%ˆÝ”8˜DœLÔ.Ñ/Ô/ˆÝ”8˜DœLÔ.Ñ/Ô/ˆØ! D§H¢H¨U¡O¤OÑ3ˆ�‰Ø$ t§x¢x°¡¤Ñ6ˆ�˜˜˜�ÑØ$ t§x¢x°¡¤Ñ6ˆ�˜˜˜�Ñð &ˆŒ�UÑØ!(ˆŒ�U˜A˜A˜A�XÑØ!(ˆŒ�U˜A˜A˜A�XÑõ ”'˜$Ô,Ô0°°°°E°Ô:Ñ;Ô;ˆØ+0°4Ô3EÔ3LÑ+LˆÔÔ˜q˜q˜q %˜xÑ(ð œ)×*Ò*ØÔØØØñ	
ô 
ˆõ �tÔ*Ñ+Ô+ð 	ð 	ˆAØ-ð °´¸1´×1DÒ1DØÔ"ØØØ˜˜˜˜A˜”ñ	2ô 2ˆOˆOõ �tÔ*Ñ+Ô+ð 	ð 	ˆAØ-ð °´¸1´×1DÒ1DØÔ"ØØØ˜˜˜˜A˜”ñ	2ô 2ˆOˆOð Œ;ð 	3Ø×0Ò0Ñ2Ô2Ð2ØÐr4   c                 óÌ  — | j         r;|j        | j        fk    s
J d¦   «         ‚|�d|cxk    r| j        k     sn 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        |¦  «        d         }d||z  dz  z  |dd…df         |dd…df         z  z
  }|€tt          j        | j        | j        z   dz   | j        ¦  «        }t          j        t                               | j        |¦  «        d         ¦  «        }|d| j        …df         }	n_t          j        | j        | j        z   dz   d| ¦  «        }t                               | 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  s;  € ðH Œ;ð 	1Ø”; 4¤6 )Ò+Ð+Ð+Ø4ñ ,Ô+Ð+ð �  eÐ!6Ð!6Ò!6Ð!6¨d¬hÒ!6Ð!6Ð!6Ð!6Ð!6Ø0ñ "7Ô!6Ð6ð ˜Ô*Ô1Ñ1ˆÝ”(˜DœH t¤vÑ-°Ñ1°1Ð5Ñ6Ô6ˆà�tÔ)Ô-Ô/°%Ñ7¸CÑ?Ñ?ð 	�
�$”(�
˜A�Ñà"ˆ�”˜!�ÑØ$)ˆ�”˜1‘��˜qÐ Ñ!Ý×-Ò-¨dÔ.@À'ÑJÔJÈ1ÔMˆØ�e˜e‘m¨Ñ+Ñ+¨g°a°a°a¸°d¬m¸kÈ!È!È!ÈQÈ$Ô>OÑ.OÑOˆð ˆ=Ýœ˜tœx¨$¬&Ñ0°1Ñ4°d´hÑ?Ô?ˆIÝ”GÝ×'Ò'ØÔ&Øñô ð ôñô ˆEð ˜j ¤˜j¨!˜mÔ,ˆCˆCåœ˜tœ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        D ]}|                     | j        |¦  «         Œ| j        D ]}|                     | j        |¦  «         Œ|| j        j        z
  }| j        xj        |z  c_        | j        xj	        |dd…t          j        f         z  c_	        |t          j                 r|                      ¦   «          dS dS )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Œ  s6  € ð Œ;ð 	9ØÔ#Ø”ð(ò ð ð à8ñô ð ð
 	Œ	×Ò˜tÔ1°:Ñ>Ô>Ð>Ø”Yð 	?ð 	?ˆEØ×Ò˜tÔ1°:Ñ>Ô>Ð>Ð>Ø”Yð 	?ð 	?ˆEØ×Ò˜tÔ1°:Ñ>Ô>Ð>Ð>ð ˜TÔ/Ô6Ñ6ˆØÔÐ!Ô! UÑ*Ð!Ô!ØÔÐÔ %¨¨¨­2¬:¨Ô"6Ñ6ÐÔØ•7”=Ô!ð 	3Ø×0Ò0Ñ2Ô2Ð2Ð2Ð2ð	3ð 	3r4   c                 ó.   — |€| j         n| 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ø   s     r2   ræ   zModels._get_cubª  ó   € ð !˜LˆtŒyˆy¨d¬i¸¬oÐ=r4   c                 ó.   — |€| j         n| 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º  r1  r4   c                 óæ  — d}d}d}t          | j        ¦  «        D �].}t          j        |t          j        |                      | j                             |¦  «        ¦  «        | j        |         z
  ¦  «        g¦  «        }t          j        t          j        |  	                    | j                             |¦  «        ¦  «        | j
        |dd…f         z
  ¦  «        |¬¦  «        }t          j        t          j        |                      | j                             |¦  «        ¦  «        | j        |dd…f         z
  ¦  «        |¬¦  «        }�Œ0dt          j        t          ¦  «        z  t          | j        | j        ¦  «        z  }||t          j        t          j        | j        ¦  «        d¬¦  «        z  k    rt!          j        dt$          d¦  «         ||t          j        t          j        | j
        ¦  «        d¬¦  «        z  k    rt!          j        dt$          d¦  «         ||t          j        t          j        | j        ¦  «        d¬¦  «        z  k    rt!          j        d	t$          d¦  «         dS dS )
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‘”ð 	ñ 	ˆAÝœàÝ”FØŸš Ô!3×!9Ò!9¸!Ñ!<Ô!<Ñ=Ô=ÀÄÈQÄÑOñô ðñô ˆIõ œÝ”Ø—H’H˜TÔ/×5Ò5°aÑ8Ô8Ñ9Ô9¸D¼LÈÈAÈAÈAÈÔ<NÑNñô ð "ð	ñ ô ˆIõ œÝ”Ø—H’H˜TÔ/×5Ò5°aÑ8Ô8Ñ9Ô9¸D¼LÈÈAÈAÈAÈÔ<NÑNñô ð "ð	ñ ô ˆI‰Ið •R”W�S‘\”\Ñ!¥C¨¬°´Ñ$9Ô$9Ñ9ˆØ�s�RœV¥B¤F¨4¬<Ñ$8Ô$8À#ÐFÑFÔFÑFÒFÐFÝŒMð!åØñ	ô ð ð �s�RœV¥B¤F¨4¬<Ñ$8Ô$8À#ÐFÑFÔFÑFÒFÐFÝŒMð.åØñ	ô ð ð �s�RœV¥B¤F¨4¬<Ñ$8Ô$8À#ÐFÑFÔFÑFÒFÐFÝŒMð.åØñ	ô ð ð ð ð GÐFr4   )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ð a3ð a3ðF ð	$ð 	$ñ „Xð	$ð ð	&ð 	&ñ „Xð	&ð ð	%ð 	%ñ „Xð	%ð ð	%ð 	%ñ „Xð	%ð ð	#ð 	#ñ „Xð	#ð ð	ð 	ñ „Xð	ð ðð ñ „Xðð ðð ñ „Xðð0ð 0ð 0ð(5ð 5ð 5ð(
2ð 
2ð 
2ð:ð :ð :ð*5ð 5ð 5ð*1ð 1ð 1ð6
ð 
ð 
ð 
ð8
ð 
ð 
ð 
ð<
ð 
ð 
ð 
ð2
ð 
ð 
ð 
ð@
ð 
ð 
ð 
ð:
ð 
ð 
ð 
ð6
ð 
ð 
ð 
ð<
ð 
ð 
ð 
ð2
ð 
ð 
ð 
ð@
ð 
ð 
ð 
ð:3ð 3ð 3ð6Qð Qð QðfH'ð H'ð H'ð H'ðT3ð 3ð 3ð<>ð >ð >ð >ð >ð >ð >ð >ð 1ð 1ð 1ð 1ð 1r4   r¦   )r5  Únumpyr   Úscipy.linalgr   Úsettingsr   Úutilsr   r   r   Úfinfor  ÚepsrW   r
   ra   rc   r¦   rJ   r4   r2   ú<module>rB     s&  ðØ €€€à Ð Ð Ð Ø Ð Ð Ð Ð Ð à Ð Ð Ð Ð Ð Ø ?Ð ?Ð ?Ð ?Ð ?Ð ?Ð ?Ð ?Ð ?Ð ?ð €b„hˆu�o„oÔ€ðs,ð s,ð s,ð s,ð s,ñ s,ô s,ð s,ðl27ð 27ð 27ðjuFð uFð uFð uFð uFñ uFô uFð uFðpKð Kð Kð Kð Kñ Kô Kð Kð Kð Kr4   