Ë
    âQ(hx<  ã                   óˆ   — d Z ddlZddlmZ dgZdd„Zd„ Zed„ «       Zed„ «       Z	d	„ Z
d
„ Zd„ Zd„ Zdd„Zd„ Zd„ Zd„ Zd„ Zy)zSparse block 1-norm estimator.
é    N)ÚaslinearoperatorÚ
onenormestc                 óæ  — t        | «      } | j                  d   | j                  d   k7  rt        d«      ‚| j                  d   }||k\  rðt        j                  t        | «      j                  t        j                  |«      «      «      }|j                  ||fk7  r"t        ddt        |j                  «      z   «      ‚t        |«      j                  d¬«      }|j                  |fk7  r"t        ddt        |j                  «      z   «      ‚t        j                  |«      }t        ||«      }	|dd…|f   }
||   }nt        | | j                  ||«      \  }}	}
}}|s|r|f}|r||	fz  }|r||
fz  }|S |S )a¼	  
    Compute a lower bound of the 1-norm of a sparse array.

    Parameters
    ----------
    A : ndarray or other linear operator
        A linear operator that can be transposed and that can
        produce matrix products.
    t : int, optional
        A positive parameter controlling the tradeoff between
        accuracy versus time and memory usage.
        Larger values take longer and use more memory
        but give more accurate output.
    itmax : int, optional
        Use at most this many iterations.
    compute_v : bool, optional
        Request a norm-maximizing linear operator input vector if True.
    compute_w : bool, optional
        Request a norm-maximizing linear operator output vector if True.

    Returns
    -------
    est : float
        An underestimate of the 1-norm of the sparse array.
    v : ndarray, optional
        The vector such that ||Av||_1 == est*||v||_1.
        It can be thought of as an input to the linear operator
        that gives an output with particularly large norm.
    w : ndarray, optional
        The vector Av which has relatively large 1-norm.
        It can be thought of as an output of the linear operator
        that is relatively large in norm compared to the input.

    Notes
    -----
    This is algorithm 2.4 of [1].

    In [2] it is described as follows.
    "This algorithm typically requires the evaluation of
    about 4t matrix-vector products and almost invariably
    produces a norm estimate (which is, in fact, a lower
    bound on the norm) correct to within a factor 3."

    .. versionadded:: 0.13.0

    References
    ----------
    .. [1] Nicholas J. Higham and Francoise Tisseur (2000),
           "A Block Algorithm for Matrix 1-Norm Estimation,
           with an Application to 1-Norm Pseudospectra."
           SIAM J. Matrix Anal. Appl. Vol. 21, No. 4, pp. 1185-1201.

    .. [2] Awad H. Al-Mohy and Nicholas J. Higham (2009),
           "A new scaling and squaring algorithm for the matrix exponential."
           SIAM J. Matrix Anal. Appl. Vol. 31, No. 3, pp. 970-989.

    Examples
    --------
    >>> import numpy as np
    >>> from scipy.sparse import csc_array
    >>> from scipy.sparse.linalg import onenormest
    >>> A = csc_array([[1., 0., 0.], [5., 8., 2.], [0., -1., 0.]], dtype=float)
    >>> A.toarray()
    array([[ 1.,  0.,  0.],
           [ 5.,  8.,  2.],
           [ 0., -1.,  0.]])
    >>> onenormest(A)
    9.0
    >>> np.linalg.norm(A.toarray(), ord=1)
    9.0
    r   é   z1expected the operator to act like a square matrixzinternal error: zunexpected shape ©ÚaxisN)r   ÚshapeÚ
ValueErrorÚnpÚasarrayÚmatmatÚidentityÚ	ExceptionÚstrÚabsÚsumÚargmaxÚelementary_vectorÚ_onenormest_coreÚH)ÚAÚtÚitmaxÚ	compute_vÚ	compute_wÚnÚ
A_explicitÚcol_abs_sumsÚargmax_jÚvÚwÚestÚnmultsÚ
nresamplesÚresults                  ú]/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/scipy/sparse/linalg/_onenormest.pyr   r      sx  € ôT 	˜Ó€AØ‡w�wˆq�z�Q—W‘W˜Q‘ZÒÜÐLÓMÐMð
 	
�‰�‰
€AØˆA‚vÜ—Z‘ZÔ 0°Ó 3× :Ñ :¼2¿;¹;Àq»>Ó JÓKˆ
Ø×Ñ  1˜vÒ%ÜÐ.Ø'¬#¨j×.>Ñ.>Ó*?Ñ?óAð Aä˜:“×*Ñ*°Ð*Ó2ˆØ×Ñ ! Ò&ÜÐ.Ø'¬#¨l×.@Ñ.@Ó*AÑAóCð Cä—9‘9˜\Ó*ˆÜ˜a Ó*ˆØ’q˜(�{Ñ#ˆØ˜8Ñ$‰ä(8¸¸A¿C¹CÀÀEÓ(JÑ%ˆˆQ��6˜:ñ ‘IØ�ˆÙØ�q�d‰NˆFÙØ�q�d‰NˆFØˆàˆ
ó    c                 ó   ‡ ‡— dŠˆˆ fd„}|S )z‘
    Decorator for an elementwise function, to apply it blockwise along
    first dimension, to avoid excessive memory usage in temporaries.
    é   c                 óB  •— | j                   d   ‰k  r ‰| «      S  ‰| d ‰ «      }t        j                  | j                   d   f|j                   dd  z   |j                  ¬«      }||d ‰ ~t	        ‰| j                   d   ‰«      D ]  } ‰| ||‰z    «      |||‰z    Œ |S )Nr   r   ©Údtype)r	   r   Úzerosr,   Úrange)ÚxÚy0ÚyÚjÚ
block_sizeÚfuncs       €€r&   Úwrapperz%_blocked_elementwise.<locals>.wrapper€   s¬   ø€ Ø�7‰7�1‰:˜
Ò"Ù˜“7ˆNá�a˜˜�nÓ%ˆBÜ—‘˜!Ÿ'™' !™*˜¨¯©°!°"¨Ñ5¸R¿X¹XÔFˆAØˆAˆkˆzˆNØÜ˜: q§w¡w¨q¡z°:Ó>ò <�Ù$(¨¨1¨Q¨z©\Ð):Ó$;��!�A�j‘LÑ!ð<àˆHr'   © )r4   r5   r3   s   ` @r&   Ú_blocked_elementwiser7   y   s   ù€ ð
 €Jõ
ð €Nr'   c                 óf   — | j                  «       }d||dk(  <   |t        j                  |«      z  }|S )a9  
    This should do the right thing for both real and complex matrices.

    From Higham and Tisseur:
    "Everything in this section remains valid for complex matrices
    provided that sign(A) is redefined as the matrix (aij / |aij|)
    (and sign(0) = 1) transposes are replaced by conjugate transposes."

    r   r   )Úcopyr   r   )ÚXÚYs     r&   Úsign_round_upr<   Ž   s2   € ð 	
�‰‹€AØ€A€aˆ1�f�IØŒ�‰�‹�N€AØ€Hr'   c                 óV   — t        j                  t        j                  | «      d¬«      S )Nr   r   )r   Úmaxr   )r:   s    r&   Ú_max_abs_axis1r?   Ÿ   s   € ä�6‰6”"—&‘&˜“) !Ô$Ð$r'   c           	      óÀ   — d}d }t        d| j                  d   |«      D ]<  }t        j                  t        j                  | |||z    «      d¬«      }|€|}Œ8||z  }Œ> |S )Nr)   r   r   )r.   r	   r   r   r   )r:   r3   Úrr2   r1   s        r&   Ú_sum_abs_axis0rB   ¤   sj   € Ø€JØ€AÜ�1�a—g‘g˜a‘j *Ó-ò ˆÜ�F‰F”2—6‘6˜!˜A˜a 
™lÐ+Ó,°1Ô5ˆØˆ9Ø‰Aà�‰F‰Aðð €Hr'   c                 óF   — t        j                  | t        ¬«      }d||<   |S )Nr+   r   )r   r-   Úfloat)r   Úir    s      r&   r   r   °   s    € Ü
�‰�œ%Ô €AØ€A€a�DØ€Hr'   c                 ó¸   — | j                   dk7  s| j                  |j                  k7  rt        d«      ‚| j                  d   }t        j                  | |«      |k(  S )Nr   z2expected conformant vectors with entries in {-1,1}r   )Úndimr	   r
   r   Údot)r    r!   r   s      r&   Úvectors_are_parallelrI   ¶   sL   € ð 	‡v�v�‚{�a—g‘g §¡Ò(ÜÐMÓNÐNØ	�‰�‰
€AÜ�6‰6�!�Q‹<˜1ÑÐr'   c                 óh   ‡— | j                   D ]"  Št        ˆfd„|j                   D «       «      rŒ" y y)Nc              3   ó6   •K  — | ]  }t        ‰|«      –— Œ y ­w©N©rI   ©Ú.0r!   r    s     €r&   ú	<genexpr>z;every_col_of_X_is_parallel_to_a_col_of_Y.<locals>.<genexpr>Â   s   øè ø€ Ò;°!Ô'¨¨1×-Ñ;ùó   ƒFT)ÚTÚany)r:   r;   r    s     @r&   Ú(every_col_of_X_is_parallel_to_a_col_of_YrT   À   s0   ø€ Ø�S‰Sò ˆÜÓ;°q·s±sÔ;Õ;Ùðð r'   c                 ó¸   ‡‡— ‰j                   \  }}‰d d …| f   Št        ˆˆfd„t        | «      D «       «      ry|�t        ˆfd„|j                  D «       «      ryy)Nc              3   óD   •K  — | ]  }t        ‰‰d d …|f   «      –— Œ y ­wrL   rM   )rO   r2   r:   r    s     €€r&   rP   z*column_needs_resampling.<locals>.<genexpr>Í   s!   øè ø€ Ò
>°Ô  1¢Q¨ T¡7×+Ñ
>ùs   ƒ Tc              3   ó6   •K  — | ]  }t        ‰|«      –— Œ y ­wrL   rM   rN   s     €r&   rP   z*column_needs_resampling.<locals>.<genexpr>Ð   s   øè ø€ Ò7¨aÔ# A q×)Ñ7ùrQ   F)r	   rS   r.   rR   )rE   r:   r;   r   r   r    s    `   @r&   Úcolumn_needs_resamplingrX   Ç   sQ   ù€ ð �7‰7�D€A€qØ	Š!ˆQˆ$‰€AÜ
Ô
>´U¸1³XÔ
>Ô>ØØ€}ÜÓ7°1·3±3Ô7Ô7ØØr'   c                 ó|   — t         j                  j                  dd|j                  d   ¬«      dz  dz
  |d d …| f<   y )Nr   é   ©Úsizer   )r   ÚrandomÚrandintr	   )rE   r:   s     r&   Úresample_columnr_   Õ   s7   € Ü�i‰i×Ñ  1¨1¯7©7°1©:ÐÓ6°qÑ8¸1Ñ<€A‚aˆ€d‚Gr'   c                 ó<   — t        j                  | |«      xs | |k  S rL   )r   Úallclose)ÚaÚbs     r&   Úless_than_or_closerd   Ù   s   € Ü�;‰;�q˜!ÓÒ'  Q¡Ð'r'   c           	      óh  — t        | «      }t        |«      }|j                  d   }t        j                  ||f«      }|dkD  r6t        j                  j                  dd||dz
  f¬«      dz  dz
  |dd…dd…f<   |t        |«      z  }d}d}d}	t        |«      }
	 t        j                  |j                  |«      «      }t        |«      }t        j                  |«      }|j                  «        |ddd…   }t        |«      }t        j                  |j                  |«      «      }t        |«      }|	dk\  r<t        t!        |«      t        j"                  |dd…|f   |dd…|f   «      «      r	 ||
fS t        j$                  |«      ddd…   d| }
||
   }t        |«      D ]  }t'        ||
|   «      |dd…|f<   Œ |	dk\  r:t        |d   |d   «      st)        d«      ‚t        |d   |d   «      st)        d«      ‚|	dk\  r-t        |«      D ]  }t        ||   ||   «      rŒt)        d	«      ‚ |}|}|	dz  }	�Œœ)
a"  
    This is Algorithm 2.2.

    Parameters
    ----------
    A : ndarray or other linear operator
        A linear operator that can produce matrix products.
    AT : ndarray or other linear operator
        The transpose of A.
    t : int, optional
        A positive parameter controlling the tradeoff between
        accuracy versus time and memory usage.

    Returns
    -------
    g : sequence
        A non-negative decreasing vector
        such that g[j] is a lower bound for the 1-norm
        of the column of A of jth largest 1-norm.
        The first entry of this vector is therefore a lower bound
        on the 1-norm of the linear operator A.
        This sequence has length t.
    ind : sequence
        The ith entry of ind is the index of the column A whose 1-norm
        is given by g[i].
        This sequence of indices has length t, and its entries are
        chosen from range(n), possibly with repetition,
        where n is the order of the operator A.

    Notes
    -----
    This algorithm is mainly for testing.
    It uses the 'ind' array in a way that is similar to
    its usage in algorithm 2.4. This algorithm 2.2 may be easier to test,
    so it gives a chance of uncovering bugs related to indexing
    which could have propagated less noticeably to algorithm 2.4.

    r   r   rZ   r[   Néÿÿÿÿzinvariant (2.2) is violatedé   zinvariant (2.3) is violated)r   r	   r   Úonesr]   r^   rD   r.   r   r   rB   r   Úsortr<   r?   rd   r>   rH   Úargsortr   r   )r   ÚATr   ÚA_linear_operatorÚAT_linear_operatorr   r:   Úg_prevÚh_prevÚkÚindr;   ÚgÚbest_jÚSÚZÚhr2   s                     r&   Ú_algorithm_2_2rw   Ý   sJ  € ôN )¨Ó+ÐÜ)¨"Ó-ÐØ×Ñ Ñ"€Aô 	�‰��A�‹€AØˆ1‚uÜ—9‘9×$Ñ$ Q¨°°A°a±C°Ð$Ó9¸!Ñ;¸aÑ?ˆŠ!ˆQ‰Rˆ%‰ØŒˆq‹�M€Að €FØ€FØ	€AÜ
�‹(€CØ
Ü�J‰JÐ(×/Ñ/°Ó2Ó3ˆÜ˜1ÓˆÜ—‘˜1“ˆØ	�‰ŒØ‰d�ˆd‰GˆÜ˜!ÓˆÜ�J‰JÐ)×0Ñ0°Ó3Ó4ˆÜ˜1Óˆð �Š6Ü!¤# a£&¬"¯&©&°²1°f°9±¸qÂÀFÀ¹|Ó*LÔMØð2 ˆcˆ6€Mô1 �j‰j˜‹m™D˜b˜DÑ! " 1Ð%ˆØˆc‰FˆÜ�q“ò 	3ˆAÜ'¨¨3¨q©6Ó2ˆAŠa�ˆdŠGð	3ð �Š6Ü% f¨Q¡i°¸±Ô;ÜÐ =Ó>Ð>Ü% f¨Q¡i°°1±Ô6ÜÐ =Ó>Ð>ð �Š6Ü˜1“Xò C�Ü)¨!¨A©$°°q±	Õ:Ü#Ð$AÓBÐBðCð
 ˆØˆØ	ˆQ‰ˆñU r'   c                 óò  — t        | «      }t        |«      }|dk  rt        d«      ‚|dk  rt        d«      ‚| j                  d   }||k\  rt        d«      ‚d}d}t        j                  ||ft
        ¬«      }	|dkD  rXt        d|«      D ]  }
t        |
|	«       Œ t        |«      D ]-  }
t        |
|	«      sŒt        |
|	«       |dz  }t        |
|	«      rŒŒ/ |	t        |«      z  }	t        j                  dt        j                  ¬«      }d}t        j                  ||ft
        ¬«      }d}d}	 t        j                  |j                  |	«      «      }|dz  }t        |«      }t        j                  |«      }t        j                  |«      }||kD  s|dk(  r|dk\  r||   }|dd…|f   }|dk\  r	||k  r|}�n²|}|}||kD  r�n§t!        |«      }~t#        ||«      r�n�|dkD  r=t        |«      D ]/  }
t        |
||«      sŒt        |
|«       |dz  }t        |
||«      rŒŒ1 ~t        j                  |j                  |«      «      }|dz  }t%        |«      }~|dk\  rt        |«      |   k(  rnþt        j&                  |«      ddd	…   d|t)        |«      z    j+                  «       }~|dkD  r\t        j,                  |d| |«      j/                  «       rn˜t        j,                  ||«      }t        j0                  ||    ||   f«      }t        |«      D ]  }t3        |||   «      |	dd…|f<   Œ |d| t        j,                  |d| |«          }t        j0                  ||f«      }|dz  }�Œ;t3        |«      }||||fS )
aî  
    Compute a lower bound of the 1-norm of a sparse array.

    Parameters
    ----------
    A : ndarray or other linear operator
        A linear operator that can produce matrix products.
    AT : ndarray or other linear operator
        The transpose of A.
    t : int, optional
        A positive parameter controlling the tradeoff between
        accuracy versus time and memory usage.
    itmax : int, optional
        Use at most this many iterations.

    Returns
    -------
    est : float
        An underestimate of the 1-norm of the sparse array.
    v : ndarray, optional
        The vector such that ||Av||_1 == est*||v||_1.
        It can be thought of as an input to the linear operator
        that gives an output with particularly large norm.
    w : ndarray, optional
        The vector Av which has relatively large 1-norm.
        It can be thought of as an output of the linear operator
        that is relatively large in norm compared to the input.
    nmults : int, optional
        The number of matrix products that were computed.
    nresamples : int, optional
        The number of times a parallel column was observed,
        necessitating a re-randomization of the column.

    Notes
    -----
    This is algorithm 2.4.

    rZ   z$at least two iterations are requiredr   zat least one column is requiredr   z't should be smaller than the order of Ar+   Nrf   )r   r
   r	   r   rh   rD   r.   r_   rX   r-   Úintpr   r   rB   r>   r   r<   rT   r?   rj   Úlenr9   ÚisinÚallÚconcatenater   )r   rk   r   r   rl   rm   r   r#   r$   r:   rE   Úind_histÚest_oldrt   rp   rq   r;   Úmagsr"   rs   Úind_bestr!   ÚS_oldru   rv   Úseenr2   Únew_indr    s                                r&   r   r   D  sž  € ôR )¨Ó+ÐÜ)¨"Ó-ÐØˆq‚yÜÐ?Ó@Ð@Øˆ1‚uÜÐ:Ó;Ð;Ø	�‰�‰
€AØˆA‚vÜÐBÓCÐCð €FØ€Jô 	�‰��A�œeÔ$€Að 	ˆ1‚uÜ�q˜!“ò 	"ˆAô ˜A˜qÕ!ð	"ô �q“ò 	 ˆAÜ)¨!¨QÕ/Ü  1Ô%Ø˜a‘�
ô *¨!¨QÖ/ð	 ð
 Œˆq‹�M€Aä�x‰x˜¤§¡Ô)€HØ€GÜ
�‰�!�Q�œuÔ%€AØ	€AØ
€CØ
Ü�J‰JÐ(×/Ñ/°Ó2Ó3ˆØ�!‰ˆÜ˜aÓ ˆÜ�f‰f�T‹lˆÜ—‘˜4“ˆØ�Š=˜A šFØ�AŠvØ˜v™;�Ø’!�V�)‘ˆAà�Š6�c˜W’nØˆCÙØˆØˆØˆuŠ9ÙÜ˜!ÓˆØä3°A°uÔ=ÙØˆqŠ5ô ˜1“Xò $�Ü-¨a°°EÕ:Ü# A qÔ)Ø !‘O�Jô .¨a°°EÖ:ð$ð ä�J‰JÐ)×0Ñ0°Ó3Ó4ˆØ�!‰ˆÜ˜1ÓˆØà�Š6”c˜!“f  (¡Ò+Øô �j‰j˜‹m™D˜b˜DÑ!Ð"2 1¤S¨£]¡?Ð3×8Ñ8Ó:ˆØØˆqŠ5ô �w‰w�s˜2˜A�w Ó)×-Ñ-Ô/Øô —7‘7˜3 Ó)ˆDÜ—.‘. # t e¡*¨c°$©iÐ!8Ó9ˆCÜ�q“ò 	3ˆAÜ'¨¨3¨q©6Ó2ˆAŠa�ˆdŠGð	3ð �b�q�'œ2Ÿ7™7 3 r¨ 7¨HÓ5Ð5Ñ6ˆÜ—>‘> 8¨WÐ"5Ó6ˆØ	ˆQ‰ˆñ{ ô| 	˜!˜XÓ&€AØ��1�f˜jÐ(Ð(r'   )rZ   é   FFrL   )Ú__doc__Únumpyr   Úscipy.sparse.linalgr   Ú__all__r   r7   r<   r?   rB   r   rI   rT   rX   r_   rd   rw   r   r6   r'   r&   ú<module>rŠ      s   ðñó Ý 0ð ˆ.€ókò\ð* ñó ðð  ñ%ó ð%ò	òòòóò=ò(òdóNO)r'   