
    _Mh{g                        d Z ddlmZ ddlZddlZddlZddlm	Z	 ddl
mZ ddlmZ ddlmZ ddlmZ d	gZd
 Zd Zd ZdedZd Z	 	 dfdZdgdZdhdZi ddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5i d6d7d8d9d:d;d<d=d>d?d@dAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYiZ	 didZZ G d[ d\          Zd] Zd^ Zdjd_Zd` Z 	 	 	 dkdaZ!db Z"dc Z#dd Z$dS )lz-Compute the action of the matrix exponential.    )warnN)qr)is_pydata_spmatrix)aslinearoperator)IdentityOperator
onenormestexpm_multiplyc                 |   t           j                            |           r5t          t	          |                               d          j                  S t          |           r0t          t	          |                               d                    S t          j	        
                    | t          j                  S )N   axis)scipysparseissparsemaxabssumflatr   nplinalgnorminfAs    b/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/scipy/sparse/linalg/_expm_multiply.py_exact_inf_normr      s    |Q )3q66::1:%%*+++	A		 )3q66::1:%%&&&y~~a(((    c                 h   t           j                            |           r5t          t	          |                               d          j                  S t          |           r0t          t	          |                               d                    S t          j	        
                    | d          S )Nr   r   r   )r   r   r   r   r   r   r   r   r   r   r   r   s    r   _exact_1_normr       s    |Q $3q66::1:%%*+++	A		 $3q66::1:%%&&&y~~a###r   c                     t          |           r&|                                                                 S |                                 S N)r   to_scipy_sparsetracer   s    r   _tracer%   %   s>    !   ""((***wwyyr   c                    t           j                            |          }t          | j                  dk    s| j        d         | j        d         k    rt          d          | j        d         }|                    ddg||g          }t          |                     |          dd	          \  }}t          j	        |
                                j        |                     |          z            }|                    dd
g||g          }	|	||
                                j        |	z  z  z
  }
t          j	        |

                                j        |                     |
          z            }|||z  z   S )a  Estimate `np.trace(A)` using `3*m3` matrix-vector products.

    The result is not deterministic.

    Parameters
    ----------
    A : LinearOperator
        Linear operator whose trace will be estimated. Has to be square.
    m3 : int
        Number of matrix-vector products divided by 3 used to estimate the
        trace.
    seed : optional
        Seed for `numpy.random.default_rng`.
        Can be provided to obtain deterministic results.

    Returns
    -------
    trace : LinearOperator.dtype
        Estimate of the trace

    Notes
    -----
    This is the Hutch++ algorithm given in [1]_.

    References
    ----------
    .. [1] Meyer, Raphael A., Cameron Musco, Christopher Musco, and David P.
       Woodruff. "Hutch++: Optimal Stochastic Trace Estimation." In Symposium
       on Simplicity in Algorithms (SOSA), pp. 142-155. Society for Industrial
       and Applied Mathematics, 2021
       https://doi.org/10.1137/1.9781611976496.16

       z&Expected A to be like a square matrix.g            ?Teconomic)overwrite_amoder   )r   randomdefault_rnglenshape
ValueErrorchoicer   matmatr$   conjT)r   m3seedrngnSQ_trQAQGrighttrGAGs               r   traceestrB   -   s1   D )


%
%C
17||qAGBK172;66ABBB	A

D$<!R))Aahhqkkt*===DAqHQVVXXZ!((1++-..E

B8aW%%A16688:>""EHUZZ\\^ahhuoo566E58r   c                    t           j                            |           rt           j                            | j        d         | j        d         | j                  }t           j                            |           r|                    | j                  S t           j                            |                              | j                  S t          |           r7dd l}|                    | j        d         | j        d         | j                  S t          | t           j        j        j                  rt          | j        | j                  S t          j        | j        d         | j        d         | j                  S )Nr   r   dtype)r   r   r   eyer1   rE   asformatformat	dia_arrayr   
isinstancer   LinearOperatorr   r   )r   outr   s      r   _ident_likerM   \   s+   |Q =lqwqz171:QWEE<  ## 	*<<)))|%%c**33AH===	A		 =zz!'!*agajz@@@	Au|*9	:	: =qw7777vagaj!'!*AG<<<<r   c           	          t          d ||||fD                       rt          | ||          }nt          | ||||||          \  }}|S )a  
    Compute the action of the matrix exponential of A on B.

    Parameters
    ----------
    A : transposable linear operator
        The operator whose exponential is of interest.
    B : ndarray, sparse array
        The matrix or vector to be multiplied by the matrix exponential of A.
    start : scalar, optional
        The starting time point of the sequence.
    stop : scalar, optional
        The end time point of the sequence, unless `endpoint` is set to False.
        In that case, the sequence consists of all but the last of ``num + 1``
        evenly spaced time points, so that `stop` is excluded.
        Note that the step size changes when `endpoint` is False.
    num : int, optional
        Number of time points to use.
    endpoint : bool, optional
        If True, `stop` is the last time point.  Otherwise, it is not included.
    traceA : scalar, optional
        Trace of `A`. If not given the trace is estimated for linear operators,
        or calculated exactly for sparse matrices. It is used to precondition
        `A`, thus an approximate trace is acceptable.
        For linear operators, `traceA` should be provided to ensure performance
        as the estimation is not guaranteed to be reliable for all cases.

        .. versionadded:: 1.9.0

    Returns
    -------
    expm_A_B : ndarray
         The result of the action :math:`e^{t_k A} B`.

    Warns
    -----
    UserWarning
        If `A` is a linear operator and ``traceA=None`` (default).

    Notes
    -----
    The optional arguments defining the sequence of evenly spaced time points
    are compatible with the arguments of `numpy.linspace`.

    The output ndarray shape is somewhat complicated so I explain it here.
    The ndim of the output could be either 1, 2, or 3.
    It would be 1 if you are computing the expm action on a single vector
    at a single time point.
    It would be 2 if you are computing the expm action on a vector
    at multiple time points, or if you are computing the expm action
    on a matrix at a single time point.
    It would be 3 if you want the action on a matrix with multiple
    columns at multiple time points.
    If multiple time points are requested, expm_A_B[0] will always
    be the action of the expm at the first time point,
    regardless of whether the action is on a vector or a matrix.

    References
    ----------
    .. [1] Awad H. Al-Mohy and Nicholas J. Higham (2011)
           "Computing the Action of the Matrix Exponential,
           with an Application to Exponential Integrators."
           SIAM Journal on Scientific Computing,
           33 (2). pp. 488-511. ISSN 1064-8275
           http://eprints.ma.man.ac.uk/1591/

    .. [2] Nicholas J. Higham and Awad H. Al-Mohy (2010)
           "Computing Matrix Functions."
           Acta Numerica,
           19. 159-208. ISSN 0962-4929
           http://eprints.ma.man.ac.uk/1451/

    Examples
    --------
    >>> import numpy as np
    >>> from scipy.sparse import csc_array
    >>> from scipy.sparse.linalg import expm, expm_multiply
    >>> A = csc_array([[1, 0], [0, 1]])
    >>> A.toarray()
    array([[1, 0],
           [0, 1]], dtype=int64)
    >>> B = np.array([np.exp(-1.), np.exp(-2.)])
    >>> B
    array([ 0.36787944,  0.13533528])
    >>> expm_multiply(A, B, start=1, stop=2, num=3, endpoint=True)
    array([[ 1.        ,  0.36787944],
           [ 1.64872127,  0.60653066],
           [ 2.71828183,  1.        ]])
    >>> expm(A).dot(B)                  # Verify 1st timestep
    array([ 1.        ,  0.36787944])
    >>> expm(1.5*A).dot(B)              # Verify 2nd timestep
    array([ 1.64872127,  0.60653066])
    >>> expm(2*A).dot(B)                # Verify 3rd timestep
    array([ 2.71828183,  1.        ])
    c              3      K   | ]}|d u V  	d S r"    ).0args     r   	<genexpr>z expm_multiply.<locals>.<genexpr>   s&      
?
?33$;
?
?
?
?
?
?r   )traceA)all_expm_multiply_simple_expm_multiply_interval)	r   BstartstopnumendpointrT   Xstatuss	            r   r
   r
   m   ss    B 
?
?5$X">
?
?
??? E!!Qv666+Aq%s,4VE E E	6Hr   r*   Fc           
         |rt           t          | j                  dk    s| j        d         | j        d         k    rt          d          | j        d         |j        d         k    r t          d| j         d|j         d          t	          |           }t          | t          j        j        j	                  }| j        d         }t          |j                  dk    rd}n5t          |j                  dk    r|j        d         }nt          d          d	}	|	}
|5|rt          dd           |rt          | d          nt          |           }|t          |          z  }| ||z  z
  } |rt          |           nt          |           }||z  dk    rd\  }}n0d}t!          || z  ||z  |          }t#          |||
|          \  }}t%          | ||||||
|          S )a  
    Compute the action of the matrix exponential at a single time point.

    Parameters
    ----------
    A : transposable linear operator
        The operator whose exponential is of interest.
    B : ndarray
        The matrix to be multiplied by the matrix exponential of A.
    t : float
        A time point.
    traceA : scalar, optional
        Trace of `A`. If not given the trace is estimated for linear operators,
        or calculated exactly for sparse matrices. It is used to precondition
        `A`, thus an approximate trace is acceptable
    balance : bool
        Indicates whether or not to apply balancing.

    Returns
    -------
    F : ndarray
        :math:`e^{t A} B`

    Notes
    -----
    This is algorithm (3.2) in Al-Mohy and Higham (2011).

    r'   r   r   %expected A to be like a square matrixshapes of matrices A  and B  are incompatible*expected B to be like a matrix or a vector      <NdTrace of LinearOperator not available, it will be estimated. Provide `traceA` to ensure performance.   
stacklevelr7   r   r   A_1_normellrn   )NotImplementedErrorr0   r1   r2   rM   rJ   r   r   r   rK   r   rB   r%   floatr	   r    LazyOperatorNormInfo_fragment_3_1_expm_multiply_simple_core)r   rX   trT   balanceidentis_linear_operatorr:   n0u_dtolmurm   m_starsrn   	norm_infos                    r   rV   rV      s   :  "!!
17||qAGAJ!'!*44@AAAwqzQWQZ - - - - - - . . 	.NNE#Au|':'IJJ	
A
17||q	QW		WQZEFFF
C
C~ 	K <HIK K K K '9G!""""fQii	%((	B	BJA 2Hz!}}}a8H8HHzQ	(1qzsKKK	!)R#>>>	%aAr61c7KKKr   c                    |rt           |d}|}|}	t          j        ||z  t          |          z            }
t	          |          D ]}t          |          }t	          |          D ]c}|t          ||dz   z            z  }||                     |          z  }t          |          }|	|z   }	||z   |t          |	          z  k    r n|}d|
|	z  }	|	}|	S )z
    A helper function.
    Nre   r   )rp   r   exprq   ranger   dot)r   rX   ru   r|   r}   r~   r{   rv   rz   Fetaic1jcoeffc2s                   r   rt   rt     s      "!!
{	A
&2a
!
!C1XX  Qv 	 	Aa1g&Ea A ##BAABw# 2 2222BB!GHr   r   gM<r'   g6mٳ[>rg   gYt&>   gq@H6?   ga2U0*c?   g3mJ?   gtF_?   g?	   gǺ?
   g;On?   g1Zd?   g333333?   g?   g r?   gPn?   gˡE?   gn?   gq=
ףp?   g)\(?   g
ףp=
?   gQ?   gQ?   gGz @   g(\@   gq=
ףp@   gQ@   gzG@   gp=
ף@   g{Gz
@   gRQ@#   g@(   g      @-   g@2   g      !@7   g#@c                 D    ddl m}  |t          |           |z            S )a  
    Efficiently estimate the 1-norm of A^p.

    Parameters
    ----------
    A : ndarray
        Matrix whose 1-norm of a power is to be computed.
    p : int
        Non-negative integer power.
    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.

    r   r   )scipy.sparse.linalg._onenormestr	   r   )r   pru   itmax	compute_v	compute_wr	   s          r   _onenormest_matrix_powerr   a  s5    P ;::::::&q))Q.///r   c                   2    e Zd ZdZd
dZd Zd Zd Zd	 ZdS )rr   ab  
    Information about an operator is lazily computed.

    The information includes the exact 1-norm of the operator,
    in addition to estimates of 1-norms of powers of the operator.
    This uses the notation of Computing the Action (2011).
    This class is specialized enough to probably not be of general interest
    outside of this module.

    Nr'   r   c                 L    || _         || _        || _        i | _        || _        dS )a  
        Provide the operator and some norm-related information.

        Parameters
        ----------
        A : linear operator
            The operator of interest.
        A_1_norm : float, optional
            The exact 1-norm of A.
        ell : int, optional
            A technical parameter controlling norm estimation quality.
        scale : int, optional
            If specified, return the norms of scale*A instead of A.

        N)_A	_A_1_norm_ell_d_scale)selfr   rm   rn   scales        r   __init__zLazyOperatorNormInfo.__init__  s+      !	r   c                     || _         dS )z*
        Set the scale parameter.
        N)r   )r   r   s     r   	set_scalezLazyOperatorNormInfo.set_scale  s     r   c                 `    | j         t          | j                  | _         | j        | j         z  S )z+
        Compute the exact 1-norm.
        )r   r    r   r   )r   s    r   onenormzLazyOperatorNormInfo.onenorm  s,     >!*4733DN{4>))r   c                     || j         vr+t          | j        || j                  }|d|z  z  | j         |<   | j        | j         |         z  S )zn
        Lazily estimate :math:`d_p(A) ~= || A^p ||^(1/p)`
        where :math:`||.||` is the 1-norm.
        r*   )r   r   r   r   r   )r   r   ests      r   dzLazyOperatorNormInfo.d  sM    
 DG*47AtyAACq)DGAJ{471:%%r   c                 t    t          |                     |          |                     |dz                       S )z3
        Lazily compute max(d(p), d(p+1)).
        r   )r   r   )r   r   s     r   alphazLazyOperatorNormInfo.alpha  s,     466!99dffQqSkk***r   )Nr'   r   )	__name__
__module____qualname____doc__r   r   r   r   r   rP   r   r   rr   rr     sn        	 	   ,  * * *& & &+ + + + +r   rr   c                     t          t          j        |                    |          t          |          z                      S )a  
    A helper function for computing bounds.

    This is equation (3.10).
    It measures cost in terms of the number of required matrix products.

    Parameters
    ----------
    m : int
        A valid key of _theta.
    p : int
        A matrix power.
    norm_info : LazyOperatorNormInfo
        Information about 1-norms of related operators.

    Returns
    -------
    cost_div_m : int
        Required number of matrix products divided by m.

    )intr   ceilr   _theta)mr   r   s      r   _compute_cost_div_mr     s1    , rwyq))F1I566777r   c                     t          j                   }t          t          j        |                    }t          t          j        |dz                       }t           fdt          ||dz             D                       S )z
    Compute the largest positive integer p such that p*(p-1) <= m_max + 1.

    Do this in a slightly dumb way, but safe and not too slow.

    Parameters
    ----------
    m_max : int
        A count related to bounds.

    r   c              3   :   K   | ]}||d z
  z  d z   k    |V  dS )r   NrP   )rQ   r   m_maxs     r   rS   z!_compute_p_max.<locals>.<genexpr>  s9      IIQAqsGuqy4H4Hq4H4H4H4HIIr   )r   sqrtr   floorr   r   r   )r   
sqrt_m_maxp_lowp_highs   `   r   _compute_p_maxr     su     J$$%%Ea(())FIIII%vax00IIIIIIr   c                 P   |dk     rt          d          d}d}t          |                                 |||          rht                                          D ]M\  }}t          t          j        |                                 |z                      }	|||	z  ||z  k     r|}|	}Nn~t          dt          |          dz             D ]M}
t          |
|
dz
  z  dz
  |dz             D ].}|t          v r#t          ||
|           }	|||	z  ||z  k     r|}|	}/Nt          |d          }||fS )a  
    A helper function for the _expm_multiply_* functions.

    Parameters
    ----------
    norm_info : LazyOperatorNormInfo
        Information about norms of certain linear operators of interest.
    n0 : int
        Number of columns in the _expm_multiply_* B matrix.
    tol : float
        Expected to be
        :math:`2^{-24}` for single precision or
        :math:`2^{-53}` for double precision.
    m_max : int
        A value related to a bound.
    ell : int
        The number of columns used in the 1-norm approximation.
        This is usually taken to be small, maybe between 1 and 5.

    Returns
    -------
    best_m : int
        Related to bounds for error control.
    best_s : int
        Amount of scaling.

    Notes
    -----
    This is code fragment (3.1) in Al-Mohy and Higham (2011).
    The discussion of default values for m_max and ell
    is given between the definitions of equation (3.11)
    and the definition of equation (3.12).

    r   z%expected ell to be a positive integerNr'   )r2   _condition_3_13r   r   itemsr   r   r   r   r   r   r   )r   ry   r{   r   rn   best_mbest_sr   thetar~   r   s              r   rs   rs     s^   F Qww@AAAFFy((**Bs;;   	 	HAuBGI--//%78899A~Q&!8!8		 q.//!344 	# 	#A1ac719eAg.. # #;;+Aq)<<A~Q&)@)@!"!"# VQ6>r   c                     t          |          }d|z  |z  |dz   z  }t          |         t          ||z            z  }| ||z  k    S )a]  
    A helper function for the _expm_multiply_* functions.

    Parameters
    ----------
    A_1_norm : float
        The precomputed 1-norm of A.
    n0 : int
        Number of columns in the _expm_multiply_* B matrix.
    m_max : int
        A value related to a bound.
    ell : int
        The number of columns used in the 1-norm approximation.
        This is usually taken to be small, maybe between 1 and 5.

    Returns
    -------
    value : bool
        Indicates whether or not the condition has been met.

    Notes
    -----
    This is condition (3.13) in Al-Mohy and Higham (2011).

    r'   rg   )r   r   rq   )rm   ry   r   rn   p_maxabs          r   r   r   1  sR    8 5!!E	C%519%A 	ub5j)))Aq1ur   c	                    |rt           t          | j                  dk    s| j        d         | j        d         k    rt          d          | j        d         |j        d         k    r t          d| j         d|j         d          t	          |           }	t          | t          j        j        j	                  }
| j        d         }t          |j                  dk    rd}n5t          |j                  dk    r|j        d         }nt          d          d	}|}|5|
rt          dd           |
rt          | d          nt          |           }|t          |          z  }ddi}|||d<   |||d<   t          j        ||fi |\  }}t          |          }|dk     rt          d          |dz
  }|}|d         }||         }|f|j        z   }t          j        |t          j        | j        |j        t                              }||z
  }| ||	z  z
  } |
rt'          |           nt)          |           }d}t+          || z  ||z  |          }||z  dk    rd\  }}nt-          ||||          \  }}t/          | |||||          } t          j                            |           r|                                 } n#t5          |           r|                                 } | |d<   ||k    r|rdS t9          | ||||||||	  	        S ||z  s|rdS t;          | |||||||          S ||z  r|rdS t=          | |||||||          S t?          d          )aB  
    Compute the action of the matrix exponential at multiple time points.

    Parameters
    ----------
    A : transposable linear operator
        The operator whose exponential is of interest.
    B : ndarray
        The matrix to be multiplied by the matrix exponential of A.
    start : scalar, optional
        The starting time point of the sequence.
    stop : scalar, optional
        The end time point of the sequence, unless `endpoint` is set to False.
        In that case, the sequence consists of all but the last of ``num + 1``
        evenly spaced time points, so that `stop` is excluded.
        Note that the step size changes when `endpoint` is False.
    num : int, optional
        Number of time points to use.
    traceA : scalar, optional
        Trace of `A`. If not given the trace is estimated for linear operators,
        or calculated exactly for sparse matrices. It is used to precondition
        `A`, thus an approximate trace is acceptable
    endpoint : bool, optional
        If True, `stop` is the last time point. Otherwise, it is not included.
    balance : bool
        Indicates whether or not to apply balancing.
    status_only : bool
        A flag that is set to True for some debugging and testing operations.

    Returns
    -------
    F : ndarray
        :math:`e^{t_k A} B`
    status : int
        An integer status for testing and debugging.

    Notes
    -----
    This is algorithm (5.2) in Al-Mohy and Higham (2011).

    There seems to be a typo, where line 15 of the algorithm should be
    moved to line 6.5 (between lines 6 and 7).

    r'   r   r   r`   ra   rb   rc   rd   re   Nrf   rg   rh   r   rj   retstepTr[   r\   z%at least two time points are requiredrD   rl   rk   ro   zinternal error) rp   r0   r1   r2   rM   rJ   r   r   r   rK   r   rB   r%   rq   r   linspaceemptyresult_typerE   r	   r    rr   rs   rt   r   toarrayr   todense_expm_multiply_interval_core_0_expm_multiply_interval_core_1_expm_multiply_interval_core_2	Exception)!r   rX   rY   rZ   r[   r\   rT   rv   status_onlyrw   rx   r:   ry   rz   r{   r|   linspace_kwargssamplesstepnsamplesqht_0t_qX_shaper]   ru   rm   rn   r   r}   r~   	action_t0s!                                    r   rW   rW   U  s   ^  "!!
17||qAGAJ!'!*44@AAAwqzQWQZ - - - - - - . . 	.NNE#Au|':'IJJ	
A
17||q	QW		WQZEFFF
C
C~ 	K <HIK K K K
 '9G!""""fQii	%((	B !$'O
!$&.
#Kt????MGT 7||H!||@AAA1AA
!*C
!*C
 kAG#G
qw G GHHHAc	A	BJA 2Hz!}}}a8H8HH
C$QqS1X:3GGGIzQ	!)R#>>>	 +1ab&!DDI|Y'' (%%''			I	&	& (%%''	AaD 	Avv 	611!Qr1ic"6 6 6!e * 	.11!Qr61a. . .
a% * 	.11!Qr61a. . . ()))r   c	           	      0   |                                 dk    rd\  }	}
nC|                    d|z             t          ||||          \  }	}
|                    d           t          |          D ]"}t	          | ||         |||	|
          ||dz   <   #|dfS )z1
    A helper function, for the case q <= s.
    r   rk   r*   ro   r   )r   r   rs   r   rt   )r   r]   r   r|   r   r   r{   rn   ry   r}   r~   ks               r   r   r     s     a	BqD!!!!)R#>>>	A1XX G G+AqtQFAFF!A#a4Kr   c           	         ||z  }|j         dd         }	|dz   f|	z   }
t          j        |
|j                  }t	          |          D ]}|||z           }||d<   d}t	          d|dz             D ]}|d         }t          |          }t	          d|dz             D ]}||k    r4||                     ||dz
                     z  t          |          z  ||<   t          t          ||                    }||||         z  z   }t          ||                   }||z  }||z   |t          |          z  k    r n|}t          j	        ||z  |z            |z  ||||z  z   <   |dfS )z?
    A helper function, for the case q > s and q % s == 0.
    r   NrD   r   
r1   r   r   rE   r   r   r   rq   powr   )r   r]   r   r|   r}   r~   r   r{   r   input_shapeK_shapeKr   Zhigh_pr   r   r   r   r   inf_norm_K_p_1r   s                         r   r   r     s    	
QA'!""+Kzn{*G
(((A1XX , ,acF!q!A# 	, 	,A!A ##B1fQh'' 	 	v::quuQqsV}},uQxx7AaDc!Qii((!$!01!6!6^+7cOA$6$6666E!B!+Aa!A#gJJ	, a4Kr   c           	         ||z  }||z  }	|||	z  z
  }
|j         dd         }|dz   f|z   }t          j        ||j                  }t	          |	dz             D ]*}|||z           }||d<   d}||	k     r|}n|
}t	          d|dz             D ]}|d         }t          |          }t	          d|dz             D ]}||dz   k    r6||                     ||dz
                     z  t          |          z  ||<   |}t          t          ||                    }||||         z  z   }t          ||                   }||z  }||z   |t          |          z  k    r n|}t          j	        ||z  |z            |z  ||||z  z   <   ,|dfS )z>
    A helper function, for the case q > s and q % s > 0.
    r   NrD   r   r'   r   )r   r]   r   r|   r}   r~   r   r{   r   r   rr   r   r   r   r   r  effective_dr   r   r   r   r   r  r   s                            r   r   r     s    	
QA	QA	AE	A'!""+Kzn{*G
(((A1q5\\ , ,acF!q55KKKq+a-(( 	, 	,A!A ##B1fQh'' 
 

??quuQqsV}},uQxx7AaDFc!Qii((!$!01!6!6^+7cOA$6$6666E!B!+Aa!A#gJJ	, a4Kr   r"   )NNNNN)r*   NF)NF)r'   r   FF)r   r'   )NNNNNFF)%r   warningsr   numpyr   scipy.linalgr   scipy.sparse.linalgscipy.linalg._decomp_qrr   scipy.sparse._sputilsr   r   scipy.sparse.linalg._interfacer   r   r	   __all__r   r    r%   rB   rM   r
   rV   rt   r   r   rr   r   r   rs   r   rW   r   r   r   rP   r   r   <module>r     s   3 3                   & & & & & & 4 4 4 4 4 4 0 0 0 0 0 0 ; ; ; ; ; ; 6 6 6 6 6 6
) ) )$ $ $  , , , ,^= = =" 48(,f f f fR?L ?L ?L ?LD   :)

	8)

 	
7)

 	
7	)


 	
7)

 	
7)

 	
7)

 	
7)

 	
7)

 	
7)

 	G)

 	G)

 	G)

 	G)

  	G!)

" 	G#)

$ 	G%)

& 	G')

 )

( 	D))

* 	D+)

, 	D-)

0 	D1)

2 	D3)

4 	D5)

6 	D7)

8 	D9)

: 	D;)

< 	D=)

> 	D?)

@ 	DA)

B 	DC)

H 	CI)

J 	CK)

L 	CM)

N 	CO)

 )

P 	CQ)

 )

Z 27)0 )0 )0 )0V>+ >+ >+ >+ >+ >+ >+ >+@8 8 82J J J$7 7 7 7t! ! !H >B@E(-G* G* G* G*T  &  :! ! ! ! !r   