403Webshell
Server IP : 217.160.0.135  /  Your IP : 216.73.217.85
Web Server : Apache
System : Linux www 6.18.52-i1-ampere #1203 SMP Mon Sep 14 18:29:59 CEST 2026 aarch64
User : sws1074145052 ( 1074145052)
PHP Version : 8.3.32
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /lib/python3/dist-packages/scipy/sparse/linalg/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /lib/python3/dist-packages/scipy/sparse/linalg/__pycache__/_onenormest.cpython-311.pyc
�

d�c~<���dZddlZddlmZdgZdd�Zd	�Zed
���Zed���Z	d�Z
d
�Zd�Zd�Z
dd�Zd�Zd�Zd�Zd�ZdS)zSparse block 1-norm estimator.
�N)�aslinearoperator�
onenormest��Fc��t|��}|jd|jdkrtd���|jd}||k�rtjt|���tj|������}|j||fkr%tddt|j��z���t|���
d���}|j|fkr%tddt|j��z���tj|��}t||��}	|dd�|f}
||}nt||j||��\}}	}
}}
|s|r|f}|r||	fz
}|r||
fz
}|S|S)a�	
    Compute a lower bound of the 1-norm of a sparse matrix.

    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 matrix.
    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_matrix
    >>> from scipy.sparse.linalg import onenormest
    >>> A = csc_matrix([[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 matrixzinternal error: zunexpected 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               �A/usr/lib/python3/dist-packages/scipy/sparse/linalg/_onenormest.pyrrs���T	����A��w�q�z�Q�W�Q�Z����L�M�M�M�
	
���
�A��A�v�v��Z� 0�� 3� 3� :� :�2�;�q�>�>� J� J�K�K�
����1�v�%�%��.�'�#�j�.>�*?�*?�?�A�A�
A��:���*�*��*�2�2����!��&�&��.�'�#�l�.@�*A�*A�A�C�C�
C��9�\�*�*���a��*�*���q�q�q�(�{�#���8�$���(8��A�C��E�(J�(J�%��Q��6�:���I������	��q�d�N�F��	��q�d�N�F��
��
�c����d���fd�}|S)z�
    Decorator for an elementwise function, to apply it blockwise along
    first dimension, to avoid excessive memory usage in temporaries.
    �c�^��|jd�kr�|��S�|d����}tj|jdf|jdd�z|j���}||d��<~t	�|jd���D] }�|||�z���|||�z�<�!|S)Nrr��dtype)rr
�zerosr.�range)�x�y0�y�j�
block_size�funcs    ��r(�wrapperz%_blocked_elementwise.<locals>.wrapper�s�����7�1�:�
�"�"��4��7�7�N���a����n�%�%�B���!�'�!�*����!�"�"��5�R�X�F�F�F�A��A�k�z�k�N���:�q�w�q�z�:�>�>�
<�
<��$(�D��1�Q�z�\�>�):�$;�$;��!�A�j�L�.�!�!��Hr)�)r6r7r5s` @r(�_blocked_elementwiser9ys0����
�J�
�
�
�
�
�
��Nr)c�n�|���}d||dk<|tj|��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."

    rr)�copyr
r)�X�Ys  r(�
sign_round_upr>�s4��	
�����A��A�a�1�f�I�������N�A��Hr)c�R�tjtj|��d���S)Nrr	)r
�maxr)r<s r(�_max_abs_axis1rA�s��
�6�"�&��)�)�!�$�$�$�$r)c	���d}d}td|jd|��D]?}tjtj||||z���d���}|�|}�:||z
}�@|S)Nr+rr	)r0rr
rr)r<r5�rr4r3s     r(�_sum_abs_axis0rD�st���J��A�
�1�a�g�a�j�*�
-�
-�����F�2�6�!�A�a�
�l�N�+�,�,�1�5�5�5���9��A�A�
��F�A�A��Hr)c�F�tj|t���}d||<|S)Nr-r)r
r/�float)r�ir"s   r(rr�s$��
���%� � � �A��A�a�D��Hr)c��|jdks|j|jkrtd���|jd}tj||��|kS)Nrz2expected conformant vectors with entries in {-1,1}r)�ndimrrr
�dot)r"r#rs   r(�vectors_are_parallelrK�sL��	�v��{�{�a�g���(�(��M�N�N�N�	���
�A�
�6�!�Q�<�<�1��r)c�b��|jD]%�t�fd�|jD����sdS�&dS)Nc3�8�K�|]}t�|��V��dS�N�rK��.0r#r"s  �r(�	<genexpr>z;every_col_of_X_is_parallel_to_a_col_of_Y.<locals>.<genexpr>�s.�����;�;�!�'��1�-�-�;�;�;�;�;�;r)FT)�T�any)r<r=r"s  @r(�(every_col_of_X_is_parallel_to_a_col_of_YrU�sL���
�S�����;�;�;�;�q�s�;�;�;�;�;�	��5�5�	��4r)c������j\}}�dd�|f�t��fd�t|��D����rdS|�"t�fd�|jD����rdSdS)Nc3�L�K�|]}t��dd�|f��V��dSrNrO)rQr4r<r"s  ��r(rRz*column_needs_resampling.<locals>.<genexpr>�s:�����
>�
>����1�Q�Q�Q��T�7�+�+�
>�
>�
>�
>�
>�
>r)Tc3�8�K�|]}t�|��V��dSrNrOrPs  �r(rRz*column_needs_resampling.<locals>.<genexpr>�s.�����7�7�a�#�A�q�)�)�7�7�7�7�7�7r)F)rrTr0rS)rGr<r=rrr"s `   @r(�column_needs_resamplingrY�s�����
�7�D�A�q�	�!�!�!�Q�$��A�
�
>�
>�
>�
>�
>�U�1�X�X�
>�
>�
>�>�>���t��}��7�7�7�7�1�3�7�7�7�7�7�	��4��5r)c�z�tj�dd|jd���dzdz
|dd�|f<dS)Nrr��sizer)r
�random�randintr)rGr<s  r(�resample_columnr_�s>���i����1�1�7�1�:��6�6�q�8�1�<�A�a�a�a��d�G�G�Gr)c�8�tj||��p||kSrN)r
�allclose)�a�bs  r(�less_than_or_closerd�s��
�;�q�!���'��Q��'r)c	�T�t|��}t|��}|jd}tj||f��}|dkr6tj�dd||dz
f���dzdz
|dd�dd�f<|t
|��z}d}d}d}	t|��}
	tj|�	|����}t|��}tj|��}
|���|ddd�}t|��}tj|�	|����}t|��}|	dkrFtt!|��tj|dd�|
f|dd�|
f����r�ntj|��ddd�d|�}
||
}t|��D]}t'||
|��|dd�|f<� |	dkrVt|d|d��st)d���t|d|d��st)d���|	d	kr=t|��D]-}t||||��st)d
����.|}|}|	dz
}	��||
fS)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.

    rrrr[NT���zinvariant (2.2) is violated�zinvariant (2.3) is violated)rrr
�onesr]r^rFr0rrrDr�sortr>rArdr@rJ�argsortrr)r�ATr�A_linear_operator�AT_linear_operatorrr<�g_prev�h_prev�k�indr=�g�best_j�S�Z�hr4s                  r(�_algorithm_2_2rw�s���N)��+�+��)�"�-�-�����"�A�	���A����A��1�u�u��9�$�$�Q���A�a�C��$�9�9�!�;�a�?��!�!�!�Q�R�R�%����q���M�A��F�
�F�	�A�
��(�(�C�*��J�(�/�/��2�2�3�3���1������1����	������
�d�d��d�G���!�����J�)�0�0��3�3�4�4���1����
��6�6�!�#�a�&�&�"�&��1�1�1�f�9��q����F��|�*L�*L�M�M�
���j��m�m�D�D�b�D�!�"�1�"�%��
�c�F���q���	3�	3�A�'��3�q�6�2�2�A�a�a�a��d�G�G�
��6�6�%�f�Q�i����;�;�
?�� =�>�>�>�%�f�Q�i��1��6�6�
?�� =�>�>�>�
��6�6��1�X�X�
C�
C��)�!�A�$��q�	�:�:�C�#�$A�B�B�B�C�����	�Q���U*�Z
�c�6�Mr)c��t|��}t|��}|dkrtd���|dkrtd���|jd}||krtd���d}d}tj||ft
���}	|dkrjt
d|��D]}
t|
|	���t
|��D]7}
t|
|	��r%t|
|	��|dz
}t|
|	���%�8|	t|��z}	tj	dtj
���}d}tj	||ft
���}
d}d}	tj|�|	����}|dz
}t|��}tj|��}tj|��}||ks|dkr|dkr||}|dd�|f}|dkr
||kr|}�n	|}|
}||kr�n�t!|��}
~t#|
|��r�n�|dkrIt
|��D]9}
t|
|
|��r&t|
|
��|dz
}t|
|
|���&�:~tj|�|
����}|dz
}t%|��}~|dkrt|��||kr�n.tj|��ddd
�d|t)|��z����}~|dkrhtj|d|�|�����rn�tj||��}tj||||f��}t
|��D]}t3|||��|	dd�|f<� |d|�tj|d|�|��}tj||f��}|dz
}���t3||��}|||||fS)a�
    Compute a lower bound of the 1-norm of a sparse matrix.

    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 matrix.
    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$at least two iterations are requiredrzat least one column is requiredrz't should be smaller than the order of Ar-NTrf)rrrr
rhrFr0r_rYr/�intprrrDr@rr>rUrArj�lenr;�in1d�all�concatenater)rrkrrrlrmrr%r&r<rG�ind_hist�est_oldrtrprqr=�magsr$rs�ind_bestr#�S_oldrurv�seenr4�new_indr"s                             r(rrDsY��R)��+�+��)�"�-�-���q�y�y��?�@�@�@��1�u�u��:�;�;�;�	���
�A��A�v�v��B�C�C�C��F��J�	���A��e�$�$�$�A�	�1�u�u��q�!���	"�	"�A�
�A�q�!�!�!�!��q���	 �	 �A�)�!�Q�/�/�
 ���1�%�%�%��a��
�*�!�Q�/�/�
 ����q���M�A��x����)�)�)�H��G�
��!�Q��u�%�%�%�A�	�A�
�C�=��J�(�/�/��2�2�3�3���!����a� � ���f�T�l�l����4������=�=�A��F�F��A�v�v��v�;���!�!�!�V�)��A���6�6�c�W�n�n��C�������u�9�9���!����
�3�A�u�=�=�	���q�5�5��1�X�X�
$�
$��-�a��E�:�:�$�#�A�q�)�)�)��!�O�J�.�a��E�:�:�$��
��J�)�0�0��3�3�4�4���!����1����
���6�6�c�!�f�f��(��+�+���j��m�m�D�D�b�D�!�"2�1�S��]�]�?�"2�3�8�8�:�:��
��q�5�5��w�s�2�A�2�w��)�)�-�-�/�/�
���7�3��)�)�D��.�#�t�e�*�c�$�i�!8�9�9�C��q���	3�	3�A�'��3�q�6�2�2�A�a�a�a��d�G�G��b�q�b�'�2�7�3�r��r�7�H�5�5�5�6���>�8�W�"5�6�6��	�Q���{=�|	�!�X�&�&�A���1�f�j�(�(r))rrFFrN)�__doc__�numpyr
�scipy.sparse.linalgr�__all__rr9r>rArDrrKrUrYr_rdrwrr8r)r(�<module>r�s7��������0�0�0�0�0�0��.��k�k�k�k�\���*�

�

���

� �%�%���%�	
�	
�	
�
�
�
�����������=�=�=�(�(�(�d�d�d�NO)�O)�O)�O)�O)r)

Youez - 2016 - github.com/yon3zu
LinuXploit