+
    LV-j…%  ã                   ó|   € ^ RI Ht ^ RIt^ RIHtHt ^ RIHtH	t	 ^RI
HtHt R.tR	R lt]! R
RRR4      R 4       tR# )é    )ÚIterableN)Ú_asarray_validatedÚ_apply_over_batch)Ú
block_diagÚLinAlgError)Ú_compute_lworkÚget_lapack_funcsÚcossinc                ó6  € V'       g
   V'       Ed'   Vf   ^M
\        V4      pVf   ^M
\        V4      p\        V RR7      p \        P                  ! V P                  RR !  '       g   \        RV P                  RR  24      hV P                  R,          pW8¼  g   V^ 8:  d$   \        RV RV P                  R,           R24      hW'8¼  g   V^ 8:  d$   \        RV R	V P                  R,           R24      hV R
RV1RV13,          V R
RV1VR13,          V R
VR1RV13,          V R
VR1VR13,          3w  r‰r«MT\        V \        4      '       g   \        R4      h\        V 4      ^8w  d   \        R\        V 4       24      hR V  4       w  r‰r«\        W‰W«W4WVR7      # )u¦  
Compute the cosine-sine (CS) decomposition of an orthogonal/unitary matrix.

X is an ``(m, m)`` orthogonal/unitary matrix, partitioned as the following
where upper left block has the shape of ``(p, q)``::

                               â”Œ                   â”�
                               â”‚ I  0  0 â”‚ 0  0  0 â”‚
    â”Œ           â”�   â”Œ         â”�â”‚ 0  C  0 â”‚ 0 -S  0 â”‚â”Œ         â”�*
    â”‚ X11 â”‚ X12 â”‚   â”‚ U1 â”‚    â”‚â”‚ 0  0  0 â”‚ 0  0 -I â”‚â”‚ V1 â”‚    â”‚
    â”‚ â”€â”€â”€â”€â”¼â”€â”€â”€â”€ â”‚ = â”‚â”€â”€â”€â”€â”¼â”€â”€â”€â”€â”‚â”‚â”€â”€â”€â”€â”€â”€â”€â”€â”€â”¼â”€â”€â”€â”€â”€â”€â”€â”€â”€â”‚â”‚â”€â”€â”€â”€â”¼â”€â”€â”€â”€â”‚
    â”‚ X21 â”‚ X22 â”‚   â”‚    â”‚ U2 â”‚â”‚ 0  0  0 â”‚ I  0  0 â”‚â”‚    â”‚ V2 â”‚
    â””           â”˜   â””         â”˜â”‚ 0  S  0 â”‚ 0  C  0 â”‚â””         â”˜
                               â”‚ 0  0  I â”‚ 0  0  0 â”‚
                               â””                   â”˜

``U1``, ``U2``, ``V1``, ``V2`` are square orthogonal/unitary matrices of
dimensions ``(p,p)``, ``(m-p,m-p)``, ``(q,q)``, and ``(m-q,m-q)``
respectively, and ``C`` and ``S`` are ``(r, r)`` nonnegative diagonal
matrices satisfying ``C^2 + S^2 = I`` where ``r = min(p, m-p, q, m-q)``.

Moreover, the rank of the identity matrices are ``min(p, q) - r``,
``min(p, m - q) - r``, ``min(m - p, q) - r``, and ``min(m - p, m - q) - r``
respectively.

X can be supplied either by itself and block specifications p, q or its
subblocks in an iterable from which the shapes would be derived. See the
examples below.

The documentation is written assuming array arguments are of specified
"core" shapes. However, array argument(s) of this function may have additional
"batch" dimensions prepended to the core shape. In this case, the array is treated
as a batch of lower-dimensional slices; see :ref:`linalg_batch` for details.

Parameters
----------
X : array_like, iterable
    complex unitary or real orthogonal matrix to be decomposed, or iterable
    of subblocks ``X11``, ``X12``, ``X21``, ``X22``, when ``p``, ``q`` are
    omitted.
p : int, optional
    Number of rows of the upper left block ``X11``, used only when X is
    given as an array.
q : int, optional
    Number of columns of the upper left block ``X11``, used only when X is
    given as an array.
separate : bool, optional
    if ``True``, the low level components are returned instead of the
    matrix factors, i.e. ``(u1,u2)``, ``theta``, ``(v1h,v2h)`` instead of
    ``u``, ``cs``, ``vh``.
swap_sign : bool, optional
    if ``True``, the ``-S``, ``-I`` block will be the bottom left,
    otherwise (by default) they will be in the upper right block.
compute_u : bool, optional
    if ``False``, ``u`` won't be computed and an empty array is returned.
compute_vh : bool, optional
    if ``False``, ``vh`` won't be computed and an empty array is returned.

Returns
-------
u : ndarray
    When ``compute_u=True``, contains the block diagonal orthogonal/unitary
    matrix consisting of the blocks ``U1`` (``p`` x ``p``) and ``U2``
    (``m-p`` x ``m-p``) orthogonal/unitary matrices. If ``separate=True``,
    this contains the tuple of ``(U1, U2)``.
cs : ndarray
    The cosine-sine factor with the structure described above.
     If ``separate=True``, this contains the ``theta`` array containing the
     angles in radians.
vh : ndarray
    When ``compute_vh=True`, contains the block diagonal orthogonal/unitary
    matrix consisting of the blocks ``V1H`` (``q`` x ``q``) and ``V2H``
    (``m-q`` x ``m-q``) orthogonal/unitary matrices. If ``separate=True``,
    this contains the tuple of ``(V1H, V2H)``.

References
----------
.. [1] Brian D. Sutton. Computing the complete CS decomposition. Numer.
       Algorithms, 50(1):33-65, 2009.

Examples
--------
>>> import numpy as np
>>> from scipy.linalg import cossin
>>> from scipy.stats import unitary_group
>>> x = unitary_group.rvs(4)
>>> u, cs, vdh = cossin(x, p=2, q=2)
>>> np.allclose(x, u @ cs @ vdh)
True

Same can be entered via subblocks without the need of ``p`` and ``q``. Also
let's skip the computation of ``u``

>>> ue, cs, vdh = cossin((x[:2, :2], x[:2, 2:], x[2:, :2], x[2:, 2:]),
...                      compute_u=False)
>>> print(ue)
[]
>>> np.allclose(x, u @ cs @ vdh)
True

NT)Úcheck_finitez=Cosine Sine decomposition only supports square matrices, got z
invalid p=z, 0<p<z
 must holdz
invalid q=z, 0<q<.zJWhen p and q are None, X must be an Iterable containing the subblocks of Xz?When p and q are None, exactly four arrays should be in X, got c              3   óN   "  € T F  p\         P                  ! V4      x € K  	  R # 5i)N)ÚnpÚ
atleast_2d)Ú.0Úxs   & Úl/Volumes/fast/ai/experiments/ui-tars-smoke/.venv/lib/python3.14/site-packages/scipy/linalg/_decomp_cossin.pyÚ	<genexpr>Úcossin.<locals>.<genexpr>‰   s   é € Ð:¹°1œbŸmšm¨A×.Ð.»ùs   ‚#%)ÚseparateÚ	swap_signÚ	compute_uÚ
compute_vhéþÿÿÿ)
Úintr   r   ÚequalÚshapeÚ
ValueErrorÚ
isinstancer   ÚlenÚ_cossin)ÚXÚpÚqr   r   r   r   ÚmÚx11Úx12Úx21Úx22s   &&&&&&&     r   r
   r
      s¥  € ÷P 	�AˆAØ’‰A¤ A£ˆØ’‰A¤ A£ˆÜ˜q¨tÔ4ˆÜ�xŠx˜Ÿ™  ˜×&Ð&Üð /Ø/0¯w©w°r°s¨|¨nð>ó ?ð ?à�G‰G�B�KˆØŒ6�Q˜!”VÜ˜z¨!¨¨F°1·7±7¸2µ;°-¸zÐJÓKÐKØŒ6�Q˜!”VÜ˜z¨!¨¨F°1·7±7¸2µ;°-¸zÐJÓKÐKà  R a R¨¨!¨ �n¨a°°R°a°R¸¹°­nØ  Q¡R¨¨!¨ �n¨a°°Q±R¸¹°­nð>Ñˆ�#�sä˜œ8×$Ò$Üð :ó ;ð 	;ô ˆq‹6�QŒ;Üð 5Ü58¸³V°Hð>ó ?ð ?á:¹Ó:Ñˆ�#ä�3˜S°Ø&ô?ð ?ó    c                 óÒ
  € \        . ROWW#.4       F+  w  r‰V	P                  ^,          ^ 8X  g   K  \        V R24      h	  V P                  w  r«VP                  w  rÍVP                  W­38w  d   \        RW­3 RVP                   24      hVP                  WË38w  d   \        RWË3 RVP                   24      hW¬,           W½,           8w  d   \        RW¬,            R	W½,            R
24      hW¬,           p\        WW#3 Uu. uF  p\        P
                  ! V4      NK  	  up4      pV'       d   RMRp\        VVR,           .WW#.4      w  pp\        VWêVR7      pV'       d   RV^ ,          RV^,          /MRV/pV! RR V RVRVRVRVRVRVRVRRRV/
VB Ev pppppppVP                  V,           pV^ 8  d   \        RV)  RV 24      hV^ 8”  d   \        V RV 24      hV'       d
   VV3VVV33# \        VV4      p\        VV4      p\        P                  ! \        P                  ! V4      4      p \        P                  ! \        P                  ! V4      4      p!\        W«Wê,
          Wë,
          4      p"\        W«4      V",
          p#\        W®V,
          4      V",
          p$\        Wê,
          V4      V",
          p%\        Wê,
          Wë,
          4      V",
          p&\        P                  ! \        P                   ! V#V$V%V&V".4      VP"                  R7      p'\        P$                  ! Wî3VP"                  R7      p(V'RV#1RV#13,          V(RV#1RV#13&   V#V",           p)V#V",           V$,           p*V#V%,           V&,           ^V",          ,           p+V#V%,           V&,           ^V",          ,           V$,           p,V'       d   V'RV$1RV$13,          MV'RV$1RV$13,          ) V(V)V*1V+V,13&   V
V&,           V",           p)V
V&,           V",           V%5,           p*V#V",           p+V#V",           V%,           p,V'       d   V'RV%1RV%13,          ) MV'RV%1RV%13,          V(V)V*1V+V,13&   V'RV&1RV&13,          V(WªV&,           1W»V&,           13&   V V(V#V#V",           1V#V#V",           13&   V V(V
V&,           V
V&,           V",           1V#V",           V%,           V&,           ^V",          V#,           V%,           V&,           13&   T#p)V#V",           p*V#V%,           V&,           V",           p+V#V%,           V&,           ^V",          ,           p,V'       d   T!MV!) V(V)V*1V+V,13&   V'       d   V!) MT!V(V
V&,           V
V&,           V",           1V#V#V",           13&   VV(V3# u upi )r%   r&   r'   r(   z can't be emptyz Invalid x12 dimensions: desired z, got z Invalid x21 dimensions: desired zWThe subblocks have compatible sizes but don't form a square array (instead they form a r   z5 array). This might be due to missing p, q arguments.ÚuncsdÚorcsdÚ_lwork)r$   r"   r#   ÚlworkÚlrworkÚ
compute_u1Ú
compute_u2Úcompute_v1tÚcompute_v2tÚtransFÚsignszillegal value in argument z of internal z did not converge: )ÚdtypeN)r%   r&   r'   r(   © )Úzipr   r   Úanyr   Úiscomplexobjr	   r   Útypecoder   r   ÚdiagÚcosÚsinÚminÚeyeÚmaxr6   Úzeros)-r%   r&   r'   r(   r   r   r   r   ÚnameÚblockr"   r#   ÚmmpÚmmqr$   r   ÚcplxÚdriverÚcsdÚ	csd_lworkr.   Ú
lwork_argsÚ_ÚthetaÚu1Úu2Úv1hÚv2hÚinfoÚmethod_nameÚUÚVDHÚcÚsÚrÚn11Ún12Ún21Ún22ÚIdÚCSÚxsÚxeÚysÚyes-   &&&&&&&&                                     r   r    r    �   s˜  € ô Ò7Ø cÐ/ö1‰ˆà�;‰;�q�>˜QÖÜ ˜v _Ð5Ó6Ð6ñ1ð �9‰9�D€AØ�y‰y�H€Cà
‡y�y�Q�HÔÜÐ;¸Q¸H¸:ð F Ø #§	¡	˜{ð,ó -ð 	-ð ‡y�y�S�HÔÜÐ;¸S¸H¸:ð F Ø #§	¡	˜{ð,ó -ð 	-ð 	…w�!•'ÔÜð à�g˜Y a¨­ yð 1;ð;ó <ð 	<ð
 	
�€Aä¨S°sÑ,@ÓAÑ,@ q”—’ Ö"Ñ,@ÑAÓB€Dß‰W '€FÜ% v¨v¸Õ/@Ð&AØ'*°Ð&:ó<�N€Cˆä˜9¨°!Ô4€Eß=A�7˜E !�H h°°aµÑ9Ø˜EÐ"ð á(+ñ ):°ð ):¸ð ):À#ð ):È3ð ):Ø7@ð):à7@ð):ð 9Cð):ð 9Cð	):ð
 38ð):ð
 @Ið):ð /9ñ):Ñ%€Qˆˆr�2�s˜C ð —,‘, Õ'€KØˆa„xÜÐ5°t°e°Wð =(Ø(3 }ð6ó 7ð 	7àˆa„xÜ˜[˜MÐ)<¸T¸FÐCÓDÐDçØ�Bˆx˜  c 
Ð*Ð*ä�2�rÓ€AÜ
�S˜#Ó
€Cô 	�Š”—’�u“Ó€AÜ
�Š”—’�u“Ó€AÜˆA�!•%˜�Ó€AÜ
ˆa‹)�a�-€CÜ
ˆa�Q•‹-˜!Õ
€CÜ
ˆa�e�Q‹-˜!Õ
€CÜ
ˆa�e�Q•UÓ
˜aÕ
€CÜ	�Š”—’˜˜S # s¨AÐ.Ó/°u·{±{Ô	C€BÜ	�Š�1�& §¡Ô	,€Bà˜˜˜˜d˜s˜d˜
•^€B€tˆ€tˆTˆcˆT€z�Nà	ˆq�€BØ	ˆq��3�€BØ	ˆs��S�˜1˜q�5Õ	 €BØ	ˆs��S�˜1˜q�5Õ	  3Õ	&€Bß*3˜˜4˜C˜4  # ˜:ž¸"¸T¸c¸TÀ4ÀCÀ4¸Z½.¸€B€rˆ2€vˆr�"ˆu€}Ñà	
ˆS��1�€BØ	
ˆS��1�˜�uÕ	€BØ	ˆq�€BØ	ˆq��3�€Bß*3˜˜4˜C˜4  # ˜:�‘¸¸D¸S¸DÀ$À3À$¸J½€B€rˆ"€uˆb�ˆe€|Ñà! $ 3 $¨¨¨ *�~€B€qˆS�€y�!˜•G�)ÐÑØ#$€B€sˆ3��7€{�C˜˜a��KÐÑ ØKL€B€qˆ3…wˆq�3�w˜�{Ð˜C !�G c�M¨CÕ/°°Aµ¸µ¸cÕ0AÀCÕ0GÐGÐGÑHà	€BØ	ˆq�€BØ	ˆs��S�˜1Õ	€BØ	ˆs��S�˜1˜q�5Õ	 €Bß%‘q¨A¨2€B€rˆ"€uˆb�ˆe€|Ñç1:¨A©2À€B€qˆ3…wˆq�3�w˜�{Ð˜C  a¥˜KÐ'Ñ(àˆb�#ˆ:ÐùòC Bs   Ã<U$)NNFFTT)r%   é   )r&   rc   )r'   rc   )r(   rc   )Úcollections.abcr   Únumpyr   Úscipy._lib._utilr   r   Úscipy.linalgr   r   Úlapackr   r	   Ú__all__r
   r    r7   r)   r   Ú<module>rj      sD   ðÝ $Û ç Bß 0ß 4àˆ*€ôA?ñH �:˜z¨:°zÓBñZó CòZr)   