
    Џkh)                     H    d Z ddlmZ ddlmZmZmZmZmZm	Z	 ddl
Zd Zd Zy)a  
This module contains subroutines concerning the geometry-improving of the interpolation set.

Translated from Zaikun Zhang's modern-Fortran reference implementation in PRIMA.

Dedicated to late Professor M. J. D. Powell FRS (1936--2015).

Python translation by Nickolai Belakovski.
   )	DEBUGGING)isinvmatprodinprodnormprimasum	primapow2    Nc                 4   d}t        j                  |d      }t        rO|dk\  sJ t        j                  |      |k(  rt        t        j                  |            sJ ||k\  r|dkD  sJ t        j                  |d      |k(  rt        j                  |d      |dz   k(  sJ t        j                  |      j                         sJ t        t        j
                  t        |ddd|f         d      dkD        sJ t        j                  |d      |k(  rt        j                  |d      |k(  sJ t        j                  |      j                         sJ t        |ddd|f   ||      sJ t        j                  t        j                  |d            }| rWt        t        |ddd|f   t        j                  ||df      j                  z
        d      |d| t        ||z        ||<   n't        t        |ddd|f         d      |d| d||<   t        j                  d|t        t        j                  ||dz              z        }	t        ||      }
|	t        t        j                  g |
dt        |
      z
              z  }| sd||<   d|t        j                   |      <   d}t#        |dkD        rt        j$                  |      }| r|t        j$                  |      }t        r'|d|cxk  r	|dz   k  sJ  J ||k  s| sJ |dk\  s| rJ |S )a  
    This function finds (the index) of a current interpolation point to be replaced with
    the trust-region trial point. See (19)-(22) of the COBYLA paper.
    N.B.:
    1. If XIMPROVED == True, then JDROP > 0 so that D is included into XPT. Otherwise,
       it is a bug.
    2. COBYLA never sets JDROP = NUM_VARS
    TODO: Check whether it improves the performance if JDROP = NUM_VARS is allowed when
    XIMPROVED is True. Note that UPDATEXFC should be revised accordingly.
    g?r
      N)axis
   )npsizer   allisfinitemaxabsr   zerosr   r	   tileTmaximumr   arrayisnananyargmax)	ximprovedddeltarhosimsimiitolnum_varsdistsqweightsimidscorejdrops                ^/var/www/teggl/fontify/venv/lib/python3.12/site-packages/scipy/_lib/pyprima/cobyla/geometry.py
setdrop_trr,      s    D wwsAH 1}}wwqzX%#bkk!n*===|a''wwsA(*rwwsA(Q,/NNN{{3##%%%266#c!YhY,/0q9A=>>>wwtQ8+a0@H0LLL{{4 $$&&&SIXI&d333~ XXbggc1o&F$Ys1ixi</@2771xYZmC\C^C^/^%_fghy#AaC=x$Ys1ixi</@%AJyxZZ6IbjjeBh.G$HHIF D!ES"?E"?1x+>"?@AAE h  E"((5/E 519~		% em		&! }e!:hl!:;;!:;; I--z** L    c	           
         |t        j                  |d      nd}	t        j                  |d      }
t        j                  |d      }t        r|
|	cxk\  rdk\  sJ  J |dk\  sJ |dkD  sJ |dkD  sJ t        j                  |d      |k(  rt        j                  |d      |k(  sJ t        j                  |      j	                         sJ t        j                  |      |dz   k(  r4t        t        j                  |      t        j                  |      z        rJ t        j                  |d      |
k(  rt        j                  |d      |dz   k(  sJ t        j
                  t        j                  |      t        j                  |      z        rJ t        j                  |      |dz   k(  r:t        |dt        j                  |      z  t        j                  |      z  k        rJ d| cxk  r|k  sJ  J || ddf   }||t        |      z  z  }t        |d| ||   z
  |      }t        j                  ||
f      }||j                  n||ddd|	f<   t        ||	dd|f   t        j                  ||	d|f   |df      j                  z
  |      j                  |dd|	df<   t        j                  t        j                  d|dd|f   t        ||      z               }t        j                  t        j                  d|dd|f   t        ||      z
              }t        ||       ||z  z   t        ||      ||z  z   k  r|dz  }t        rkt        j                  |      |k(  rt	        t        j                  |            sJ d|z  t         j                   j                  |      cxk  r	d|z  k  sJ  J |S )z
    This function calculates a geometry step so that the geometry of the interpolation set is improved
    when SIM[: JDROP_GEO] is replaced with SIM[:, NUM_VARS] + D. See (15)--(17) of the COBYLA paper.
    Nr
   r   r   g?g?)r   r   r   r   r   r   r   isposinfr   r   r   r   r   r   appendr   linalg)r*   amatbvecconmatcpencvaldelbarfvalr#   m_lconnum_constraintsr%   r   gAcvpdcvnds                    r+   geostepr?      sg    "&!1RWWT1qFggfa(OwwtQH &-A-----1}}zzaxxwwtQ8+a0@H0LLL{{4 $$&&&wwt}1,S$"++VZJ[9[5\\\wwvq!_49KxZ[|9[[[66"((6*R[[-@@AAAwwt}1,SBHHTN@RUWU`U`aeUf@f9f5gggE$H$$$$$ 	UAXA!d1g+A 	Yh$x.0$7A
(O,-A".DFFDAa&jMVFGYhY$67''&():";h]KMMNPTVVWVW ajM 66"))Avak2WQ]BCDD66"))Avak2WQ]BCDDq!}td{"VAq\D4K%??	R wwqzX%#bkk!n*=== V|biinnQ/?3<?????Hr-   )__doc__common.constsr   common.linalgr   r   r   r   r   r	   numpyr   r,   r?    r-   r+   <module>rE      s$    & M M Pj=r-   