L i_ vdZgZddlZddlmZmZGddejjZ ddl m Z d dZ y) zz Matrix square root for general matrices and for upper triangular matrices. This module exists to avoid cyclic imports. N)ztrsyldtrsylc eZdZy) SqrtmErrorN)__name__ __module__ __qualname__b/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/scipy/linalg/_matfuncs_sqrtm.pyrrsr r)within_block_loopc tj|}tj|xrtj|ddk\}|sLtj|tj d}tj|tj }nKtj|tj d}tj|tj }tjtj|}|j\}}t||zd}t||\}}|dz} ||z } | |z|| zz|k7r tdg} d} | |f|| ffD]0\} }t| D]}| j| | |zf| |z } 2 t||| |t|D]}| |\}}t|dz d d D]}| |\}}|||||f}||z dkDr&||||||fj%|||||fz }|||||f}|||||f}|rt'|||\}}}nt)|||\}}}||z|||||f<|S#t$r}t!|j"|d }~wwxYw) 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)initialrC)dtypeorder)rrzinternal inconsistencyN)npdiag isrealobjminasarray complex128float64sqrtshapemaxdivmod Exceptionrangeappendr RuntimeErrorrargsdotrr)T blocksizeT_diag keep_it_realRnnblocksbsmallnlargeblargensmallstart_stop_pairsstartcountsizeiejjstartjstopistartistopSRiiRjjxscaleinfos r _sqrtm_triurBs4WWQZF<<?Frvvfb'AQ'FL  JJq S 9F"--8 JJq # 6F"**5  A 77DAq!y.!$GAw'NFF aZF v F &(A-011 E(66*:; tu A  # #UEDL$9 : TME  )!Q 0': 7^6(+ qsB# 6A,Q/MFE&,u ,-A1uqy&,f 4599!E&LrKs: # && 4W r