
    >qj8                     r    d Z g ZddlZddlmZ  G d dej                  j                        Zddl	m
Z
 d	dZy)
zz
Matrix square root for general matrices and for upper triangular matrices.

This module exists to avoid cyclic imports.

    N   )get_lapack_funcsc                       e Zd Zy)
SqrtmErrorN)__name__
__module____qualname__     [/opt/rentech/trading_bot/.venv/lib/python3.12/site-packages/scipy/linalg/_matfuncs_sqrtm.pyr   r      s    r   r   )within_block_loopc           	         t        j                  |       }t        j                  |       xr t        j                  |d      dk\  }|sLt        j                  | t         j
                  d      } t        j                  |t         j
                        }nKt        j                  | t         j                  d      } t        j                  |t         j                        }t        j                  t        j                  |            }t        d|fd	      }| j                  \  }}t        ||z  d
      }t        ||      \  }}	|d
z   }
||	z
  }||z  |	|
z  z   |k7  rt        d      g }d}||f|	|
ffD ]0  \  }}t        |      D ]  }|j                  |||z   f       ||z  } 2 	 t        || ||       t        |      D ]  }||   \  }}t        |d
z
  dd      D ]u  }||   \  }}| ||||f   }||z
  d
kD  r&||||||f   j'                  |||||f         z
  }|||||f   }|||||f   } ||||      \  }}}||z  |||||f<   w  |S # t         $ r}t#        |j$                   |d}~ww xY w)a  
    Matrix square root of an upper triangular matrix.

    This is a helper function for `sqrtm` and `logm`.

    Parameters
    ----------
    T : (N, N) array_like upper triangular
        Matrix whose square root to evaluate
    blocksize : int, optional
        If the blocksize is not degenerate with respect to the
        size of the input array, then use a blocked algorithm. (Default: 64)

    Returns
    -------
    sqrtm : (N, N) ndarray
        Value of the sqrt function at `T`

    References
    ----------
    .. [1] Edvin Deadman, Nicholas J. Higham, Rui Ralha (2013)
           "Blocked Schur Algorithms for Computing the Matrix Square Root,
           Lecture Notes in Computer Science, 7782. pp. 171-182.

    g        )initialr   C)dtypeorder)r   trsyl	preferred)ilp64r   zinternal inconsistencyN)npdiag	isrealobjminasarray
complex128float64sqrtr   shapemaxdivmod	Exceptionrangeappendr   RuntimeErrorr   argsdot)T	blocksizeT_diagkeep_it_realRr   nnblocksbsmallnlargeblargensmallstart_stop_pairsstartcountsizeiejjstartjstopistartistopSRiiRjjxscaleinfos                                r   _sqrtm_triurD      s   4 WWQZF<<?Frvvfb'AQ'FL JJqS9F"--8JJq

#6F"**5
 AWqd+>E 77DAq!y.!$G Aw'NFFaZFvF&(A-011 E(66*:; tu 	A##UEDL$9:TME	)!Q 0':
 7^ 6(+qsB# 	6A,Q/MFE&,u,-A1uqy&,f4599!E&L<B5L=I ;J K K F5L&,./CF5L&,./C"3Q/NAud,-IAfUlF5L()	66$ H-  )!&&!q()s   'I 	I8 I33I8)@   )__doc____all__numpyr   lapackr   linalgLinAlgErrorr   _matfuncs_sqrtm_triur   rD   r
   r   r   <module>rM      s:      %	&& 	 4Vr   