Ë
    0Ò^j�  ã                   óH   — d Z ddlZddlmZmZmZmZmZ ddl	m
Z
mZ d„ Zd„ Zy)a   
This module provides some Powell-style linear algebra procedures.

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.
é    Né   )ÚisminorÚplanerotÚmatprodÚinprodÚhypot)Ú	DEBUGGINGÚEPSc           
      óJ  — |j                   d   }|}t        | |«      }t        t        | «      t        |«      «      }t        j                  t        ||«      D ��	cg c]  \  }}	t        ||	«      rdn|‘Œ c}	}«      }t        |dz
  |dz
  d«      D ]g  }
t        ||
dz      «      dkD  sŒt        ||
|
dz    «      }t        |dd…|
|
dz   gf   |j                  «      |dd…|
|
dz   gf<   t        ||
|
dz    Ž ||
<   Œi ||k  r/t        ||   «      t        dz  kD  rt        ||   ||   «      s|dz  }|dz
  dk\  r|dz
  |k  r||dz
     ||dz
  <   t        rI||cxk  rt        |dz   |«      k  sJ ‚ J ‚|t        |«      cxk  r|k  sJ ‚ J ‚|j                   ||fk(  sJ ‚|||fS c c}	}w )a�  
    This function updates the QR factorization of an MxN matrix A of full column rank, attempting to
    add a new column C to this matrix as the LAST column while maintaining the full-rankness.
    Case 1. If C is not in range(A) (theoretically, it implies N < M), then the new matrix is np.hstack([A, C])
    Case 2. If C is in range(A), then the new matrix is np.hstack([A[:, :n-1], C])
    N.B.:
    0. Instead of R, this subroutine updates Rdiag, which is np.diag(R), with a size at most M and at
    least min(m, n+1). The number is min(m, n+1) rather than min(m, n) as n may be augmented by 1 in
    the function.
    1. With the two cases specified as above, this function does not need A as an input.
    2. The function changes only Q[:, nsave:m] (nsave is the original value of n) and
    R[:, n-1] (n takes the updated value)
    3. Indeed, when C is in range(A), Powell wrote in comments that "set iOUT to the index of the
    constraint (here, column of A --- Zaikun) to be deleted, but branch if no suitable index can be
    found". The idea is to replace a column of A by C so that the new matrix still has full rank
    (such a column must exist unless C = 0). But his code essentially sets iout=n always. Maybe he
    found this worked well enough in practice. Meanwhile, Powell's code includes a snippet that can
    never be reached, which was probably intended to deal with the case that IOUT != n
    r   r   é   éÿÿÿÿN)Úshaper   ÚabsÚnpÚarrayÚzipr   Úranger   ÚTr   r
   r	   ÚminÚlen)ÚcÚQÚRdiagÚnÚmÚnsaveÚcqÚcqaÚcqiÚcqaiÚkÚGs               úp/var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/scipy/_external/pyprima/common/powalg.pyÚqradd_Rdiagr$      sÍ  € ð( 	
�‰�‰
€AØ€Eô 
��A‹€BÜ
”#�a“&œ#˜a›&Ó
!€Cô 
�‰ÄSÈÈSÃ\×R¹	¸¸Tœ  TÔ*‘1°Ñ3ÓRÓ	S€Bô
 �1�Q‘3˜˜!™˜RÓ ò &ˆÜˆr�!�A‘#‰w‹<˜!Óô ˜˜A˜a ™c˜Ó#ˆAÜ$ Q¢q¨1¨a°©c¨( {¡^°Q·S±SÓ9ˆAŠa�!�Q�q‘S�ˆk‰NÜ˜2˜a  !¡˜9Ð%ˆBˆqŠEð&ð 	ˆ1‚uäˆr�!‰u‹:œ˜Q™Ò¤w¨r°!©u°c¸!±fÔ'=Ø�‰FˆAð 	ˆ1�u�‚z�a˜!‘e˜a’iØ˜!˜a™%‘yˆˆa�!‰e‰åØ˜Ô.œS ¨¡¨AÓ.Ò.Ð.Ñ.Ð.Ð.Ø”C˜“JÔ# !Ò#Ð#Ñ#Ð#Ð#Ø�w‰w˜1˜a˜&Ò Ð Ð àˆe�Qˆ;Ðùó9 Ss   ÁF
c                 ó°  — | j                   \  }}|dk\  r||k  sJ ‚|dk\  r||k  sJ ‚t        |«      |k(  sJ ‚|j                   d   |k(  r$|j                   d   |k\  r|j                   d   |k  sJ ‚|dk  s||k\  r||fS t        ||dz
  «      D ]^  }t        ||dz      t	        |dd…|f   | dd…|dz   f   «      g«      }t        |dd…|dz   |gf   |j                  «      |dd…||dz   gf<   Œ` t        ||dz
  «      D �cg c]  }t	        |dd…|f   | dd…|dz   f   «      ‘Œ! c}|||dz
   t	        |dd…|dz
  f   | dd…|f   «      ||dz
  <   ||fS c c}w )a[  
    This function updates the QR factorization for an MxN matrix A=Q@R so that the updated Q and
    R form a QR factorization of [A_0, ..., A_{I-1}, A_{I+1}, ..., A_{N-1}, A_I] which is the matrix
    obtained by rearranging columns [I, I+1, ... N-1] of A to [I+1, ..., N-1, I]. Here A is ASSUMED TO
    BE OF FULL COLUMN RANK, Q is a matrix whose columns are orthogonal, and R, which is not present,
    is an upper triangular matrix whose diagonal entries are nonzero. Q and R need not be square.
    N.B.:
    0. Instead of R, this function updates Rdiag, which is np.diag(R), the size being n.
    1. With L = Q.shape[1] = R.shape[0], we have M >= L >= N. Most often L = M or N.
    2. This function changes only Q[:, i:] and Rdiag[i:]
    3. (NDB 20230919) In Python, i is either icon or nact - 2, whereas in FORTRAN it is either icon or nact - 1.
    r   r   N)r   r   r   r   r   r   r   )ÚAr   r   Úir   r   r!   r"   s           r#   Úqrexc_Rdiagr(   L   s‡  € ð �7‰7�D€A€qð �Š6�a˜1’fÐÐØ�Š6�a˜!’eÐÐÜˆu‹:˜Š?Ðˆ?Ø�7‰7�1‰:˜Š?˜qŸw™w q™z¨Qš°1·7±7¸1±:À²?ÐBÐBð
 	ˆ1‚u��Q’Ø�%ˆxˆô �1�a˜‘c‹]ò 8ˆÜ�e˜A˜a™C‘j¤&¨ª1¨a¨4©°!²A°q¸±s°F±)Ó"<Ð=Ó>ˆÜ  ¢1 q¨¡s¨A h ;¡°!·#±#Ó7ˆŠ!ˆa��1‘ˆXˆ+Šð8ô 9>¸aÀÀ1Á»ÖF°1”F˜1šQ ˜T™7 A¢a¨¨1© f¡IÕ.ÒF€Eˆ!ˆAˆa‰C€LÜ˜š!˜Q˜q™S˜&™	 1¢Q¨ T¡7Ó+€Eˆ!ˆA‰#�Jàˆeˆ8€Oùò Gs   Ã?$E)Ú__doc__Únumpyr   Úlinalgr   r   r   r   r   Úconstsr	   r
   r$   r(   © ó    r#   ú<module>r/      s#   ðñó ß =Õ =ß "ò9óx7r.   