+
    /iz<                         R t ^ RIt^ RIHt R.tRR ltR t]R 4       t]R 4       t	R t
R	 tR
 tR tRR ltR tR tR tR tR# )zSparse block 1-norm estimator.
N)aslinearoperator
onenormestc                ^   \        V 4      p V P                  ^ ,          V P                  ^,          8w  d   \        R4      hV P                  ^,          pW8  Ed   \        P                  ! \        V 4      P                  \        P                  ! V4      4      4      pVP                  WU38w  d'   \        RR\        VP                  4      ,           4      h\        V4      P                  ^ R7      pVP                  V38w  d'   \        RR\        VP                  4      ,           4      h\        P                  ! V4      p\        WX4      p	VRV3,          p
Wx,          pM\        W P                  W4      w  rrpV'       g	   V'       d(   V3pV'       d
   W3,          pV'       d
   W3,          pV# V# )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
z1expected the operator to act like a square matrixzinternal error: zunexpected shape axisNNN)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/html/photoedit/myenv/lib/python3.14/site-packages/scipy/sparse/linalg/_onenormest.pyr   r      sd   T 	AwwqzQWWQZLMM
 	

AvZZ 0 3 : :2;;q> JK
v%.'#j.>.>*??A A:***2!&.'#l.@.@*AAC C99\*a*q({#$(8CC(J%: IdNFdNF
    c                   a a RoVV 3R lpV# )z
Decorator for an elementwise function, to apply it blockwise along
first dimension, to avoid excessive memory usage in temporaries.
c                 ~  < V P                   ^ ,          S8  d	   S! V 4      # S! V RS 4      p\        P                  ! V P                   ^ ,          3VP                   R,          ,           VP                  R7      pWRS% ?\	        SV P                   ^ ,          S4       F  pS! WVS,            4      W#VS,           % K  	  V# )    N   NNdtype)r   r
   zerosr-   range)xy0yj
block_sizefuncs   &   r%   wrapper%_blocked_elementwise.<locals>.wrapper   s    771:
"7Nan%B!''!*"5RXXFAkzN:qwwqz:>$(Qz\):$;AjL! ?Hr&       )r5   r6   r4   s   f @r%   _blocked_elementwiser:   y   s    
 J
 Nr&   c                n    V P                  4       p^W^ 8H  &   V\        P                  ! V4      ,          pV# )a!  
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."

)copyr
   r   )XYs   & r%   sign_round_upr?      s0     	
AA1fINAHr&   c                 Z    \         P                  ! \         P                  ! V 4      ^R7      # )r+   r   )r
   maxr   )r=   s   &r%   _max_abs_axis1rB      s    66"&&)!$$r&   c           	          RpRp\        ^ V P                  ^ ,          V4       FG  p\        P                  ! \        P                  ! WW1,            4      ^ R7      pVf   TpK?  W$,          pKI  	  V# )   Nr   r8   )r/   r   r
   r   r   )r=   r4   rr3   r2   s   &    r%   _sum_abs_axis0rF      s_    JA1aggaj*-FF266!al+,159AFA . Hr&   c                 F    \         P                  ! V \        R 7      p^W!&   V# )r,   )r
   r.   float)r   ir   s   && r%   r   r      s    
% AADHr&   c                     V P                   ^8w  g   V P                  VP                  8w  d   \        R4      hV P                  ^ ,          p\        P                  ! W4      V8H  # )r+   z2expected conformant vectors with entries in {-1,1})ndimr   r	   r
   dot)r   r    r   s   && r%   vectors_are_parallelrM      sJ     	vv{agg(MNN	
A66!<1r&   c                    a V P                    FZ  o\        ;QJ d)    V3R  lVP                    4       F  '       g   K   RM	  RM! V3R  lVP                    4       4      '       d   KY   R# 	  R# )c              3   <   <"   T F  p\        SV4      x  K  	  R # 5iNrM   .0r    r   s   & r%   	<genexpr>;every_col_of_X_is_parallel_to_a_col_of_Y.<locals>.<genexpr>   s     ;s!'1--s   TF)Tany)r=   r>   r   s   &&@r%   (every_col_of_X_is_parallel_to_a_col_of_YrY      sB    SSs;qss;sss;qss;;;  r&   c                   aa SP                   w  r4SR V 3,          o\        ;QJ d)    VV3R l\        V 4       4       F  '       g   K   RM	  RM! VV3R l\        V 4       4       4      '       d   R# VeW   \        ;QJ d)    V3R lVP                   4       F  '       g   K   RM	  RM! V3R lVP                   4       4      '       d   R# R# )r   c              3   N   <"   T F  p\        SSR V3,          4      x  K  	  R# 5i)r   NrQ   )rS   r3   r=   r   s   & r%   rT   *column_needs_resampling.<locals>.<genexpr>   s$     
>X1QT7++Xs   "%TFc              3   <   <"   T F  p\        SV4      x  K  	  R # 5irP   rQ   rR   s   & r%   rT   r\      s     73a#Aq))3rV   )r   rX   r/   rW   )rI   r=   r>   r   r   r   s   &f&  @r%   column_needs_resamplingr^      s}     77DA	!Q$A
s
>U1X
>sss
>U1X
>>>}3713373337133777r&   c                     \         P                  P                  ^ ^VP                  ^ ,          R7      ^,          ^,
          VRV 3&   R# )r)   sizer   N)r
   randomrandintr   )rI   r=   s   &&r%   resample_columnrd      s7    ii11771:6q81<AadGr&   c                 F    \         P                  ! W4      ;'       g    W8  # rP   )r
   allclose)abs   &&r%   less_than_or_closeri      s    ;;q'''r&   c           	     .   \        V 4      p\        V4      pVP                  ^ ,          p\        P                  ! WR34      pV^8  d<   \        P                  P                  ^ ^WR^,
          3R7      ^,          ^,
          VR&   V\        V4      ,          pRpRp^p	\        V4      p
 \        P                  ! VP                  V4      4      p\        V4      p\        P                  ! V4      pVP                  4        VRRR1,          p\        V4      p\        P                  ! VP                  V4      4      p\        V4      pV	^8  dG   \        \!        V4      \        P"                  ! VRV3,          VRV3,          4      4      '       d    W3# \        P$                  ! V4      RRR1,          RV p
VV
,          p\        V4       F  p\'        WZV,          4      VRV3&   K  	  V	^8  dW   \        V^ ,          V^ ,          4      '       g   \)        R4      h\        V^ ,          V^ ,          4      '       g   \)        R4      hV	^8  d>   \        V4       F.  p\        VV,          VV,          4      '       d   K%  \)        R4      h	  TpTpV	^,          p	EK  )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   Nzinvariant (2.2) is violatedzinvariant (2.3) is violated)r   r*   )r   r   r
   onesrb   rc   rH   r/   r   r   rF   r   sortr?   rB   ri   rA   rL   argsortr   r   )r   ATr   A_linear_operatorAT_linear_operatorr   r=   g_prevh_prevkindr>   gbest_jSZhr3   s   &&&               r%   _algorithm_2_2r{      s6   N )+)"-"A 	A1u99$$QaC$9!;a?%qMA FF	A
(C
JJ(//2311	ddG!JJ)00341 6!#a&"&&1f9qF|*LMM2 6M1 jjmDbD!"1%cFqA'q62AadG  6%fQi;; =>>%fQi166 =>> 61X)!A$q	::#$ABB 
 	Qr&   c                   \        V 4      p\        V4      pV^8  d   \        R4      hV^8  d   \        R4      hV P                  ^ ,          pW&8  d   \        R4      h^ p^ p\        P                  ! Wb3\
        R7      p	V^8  dX   \        ^V4       F  p
\        W4       K  	  \        V4       F*  p
\        W4      '       g   K  \        W4       V^,          pK)  	  V	\        V4      ,          p	\        P                  ! ^ \        P                  R7      p^ p\        P                  ! Wb3\
        R7      p^pRp \        P                  ! VP                  V	4      4      pV^,          p\        V4      p\        P                  ! V4      p\        P                  ! V4      pVV8  g   V^8X  d   V^8  d
   VV,          pVRV3,          pV^8  d   VV8:  d   TpEMTpTpW8  d   EM\!        V4      p?\#        VV4      '       d   EMV^8  d;   \        V4       F+  p
\        WV4      '       g   K  \        W4       V^,          pK*  	  ?\        P                  ! VP                  V4      4      pV^,          p\%        V4      p?V^8  d   \        V4      VX,          8X  d   EM'\        P&                  ! V4      RRR1,          RV\)        V4      ,            P+                  4       p?V^8  dm   \        P,                  ! VRV V4      P/                  4       '       d   M\        P,                  ! W4      p\        P0                  ! VV( ,          VV,          34      p\        V4       F  p\3        WoV,          4      V	RV3&   K  	  VRV \        P,                  ! VRV V4      ( ,          p\        P0                  ! VV34      pV^,          pEK  \3        VX4      pVVXWx3# )aj  
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.

z$at least two iterations are requiredzat least one column is requiredz't should be smaller than the order of Ar,   Nr   rk   )r   r	   r   r
   rl   rH   r/   rd   r^   r.   intpr   r   rF   rA   r   r?   rY   rB   rn   lenr<   isinallconcatenater   )r   ro   r   r   rp   rq   r   r"   r#   r=   rI   ind_histest_oldrx   rt   ru   r>   magsr!   rw   ind_bestr    S_oldry   rz   seenr3   new_indr   s   &&&&                         r%   r   r   D  s[   R )+)"-qy?@@1u:;;	
AvBCC FJ 	e$A 	1uq!A A!  qA)!//%a
 
 qMAxx)HG
!u%A	A
C
JJ(//23!a ffTl4=AFAvv;!V)A6cWnC9!3Au==q5 1X-aE::#A)!OJ  JJ)0034!16c!f(+ jjmDbD!"21S]?388:q5 wws2Aw)--// 773)D..#te*c$i!89CqA'q62AadG  bq'2773r7H556>>8W"56	Q!X&A1f((r&   )rD      FFrP   )__doc__numpyr
   scipy.sparse.linalgr   __all__r   r:   r?   rB   rF   r   rM   rY   r^   rd   ri   r{   r   r9   r&   r%   <module>r      s     0 .k\*    % %	=(dNO)r&   