+
    i                         R t ^ RIHt ^ RIHt ^ RIHt ^ RIHt ^ RI	H
t
Ht ^ RIHt . R'Ot]! R	4      t]'       g    ! R
 R4      tM]P"                  t]! RRR./R7      t]'       g    ! R R4      tRtM]P(                  t]P*                  tR tR tR tR tR tR tR tR tR tR tR t R t!R t"R t#R t$R  t%R! t&R" t'R# t(R$ t)R% t*R& t+R# )(z<Utilities to deal with sympy.Matrix, numpy and scipy.sparse.)Expr)I)S
MatrixBase)eyezeros)import_modulenumpy_ndarrayscipy_sparse_matrixnumpyc                       ] tR t^tRtR# )r
    N__name__
__module____qualname____firstlineno____static_attributes__r       ځ/Users/tonyclaw/.openclaw/workspace/skills/math-calculator/venv/lib/python3.14/site-packages/sympy/physics/quantum/matrixutils.pyr
   r
          r   scipyfromlistsparse)import_kwargsc                       ] tR t^&tRtR# )r   r   Nr   r   r   r   r   r   &   r   r   Nc                   \         '       g   \        hVP                  RR4      p\        V \        4      '       d&   \         P                  V P                  4       VR7      # \        V \        4      '       d;   V P                  '       g   V P                  '       g   V \        8X  d   \        V 4      # \        RV ,          4      hzBConvert a SymPy Matrix/complex number to a numpy matrix or scalar.dtypecomplexr   z.Expected MatrixBase or complex scalar, got: %r)npImportErrorget
isinstancer   arraytolistr   	is_Numberis_NumberSymbolr   r    	TypeErrormoptionsr   s   &, r   sympy_to_numpyr.   .   s    2KK+E!Z  xx
%x00	At		;;;!+++qAv1:
DqH
IIr   c                   \         '       d   \        '       g   \        hVP                  RR4      p\	        V \
        4      '       d9   \        P                  \         P                  V P                  4       VR7      4      # \	        V \        4      '       d;   V P                  '       g   V P                  '       g   V \        8X  d   \        V 4      # \        RV ,          4      hr   )r"   r   r#   r$   r%   r   
csr_matrixr&   r'   r   r(   r)   r   r    r*   r+   s   &, r   sympy_to_scipy_sparser1   ;   s    2VVKK+E!Z    !((*E!BCC	At		;;;!+++qAv1:
DqH
IIr   c                4    \        V P                  4       4      # )z0Convert a scipy.sparse matrix to a SymPy matrix.)r   todenser,   r-   s   &,r   scipy_sparse_to_sympyr5   H   s    aiik""r   c                    \        V 4      # )z)Convert a numpy matrix to a SymPy matrix.r   r4   s   &,r   numpy_to_sympyr7   M   s    a=r   c                
   \        V \        4      '       d   V # \        V \        4      '       d   \        V 4      # \        V \        4      '       d   \        V 4      # \        V \        4      '       d   V # \        RV ,          4      h)z6Convert a numpy/scipy.sparse matrix to a SymPy matrix.1Expected sympy/numpy/scipy.sparse matrix, got: %r)r%   r   r
   r7   r   r5   r   r*   r4   s   &,r   to_sympyr:   R   sh    !Z  	A}	%	%a  	A*	+	+$Q''	At		
G!K
LLr   c                   VP                  RR4      p\        V \        \        34      '       d   \	        WR7      # \        V \
        4      '       d   V # \        V \        4      '       d   V P                  4       # \        RV ,          4      h)z6Convert a sympy/scipy.sparse matrix to a numpy matrix.r   r    r!   r9   )	r$   r%   r   r   r.   r
   r   r3   r*   r+   s   &, r   to_numpyr<   _   sl    KK+E!j$'((a--	A}	%	%	A*	+	+yy{
G!K
LLr   c                D   VP                  RR4      p\        V \        \        34      '       d   \	        WR7      # \        V \
        4      '       d(   \        '       g   \        h\        P                  V 4      # \        V \        4      '       d   V # \        RV ,          4      h)z6Convert a sympy/numpy matrix to a scipy.sparse matrix.r   r    r!   r9   )r$   r%   r   r   r1   r
   r   r#   r0   r   r*   r+   s   &, r   to_scipy_sparser>   k   s|    KK+E!j$'(($Q44	A}	%	%v  ##	A*	+	+
G!K
LLr   c                    \        V \        4      '       d   V P                  R8X  d
   V ^ ,          p \        V \        \        34      '       d$   V P                  R8X  d   \        V R,          4      p V # )zCFlatten a 1x1 matrix to a scalar, return larger matrices unchanged.)   r@   )    rA   )r%   r   shaper
   r   r    es   &r   flatten_scalarrE   y   sV    !Z  77f!A!m%89::77f$ AHr   c                    \        V \        4      '       d   V P                  # \        V \        \        34      '       d   V P                  4       P                  4       # \        RV ,          4      h)z7Return the dagger of a sympy/numpy/scipy.sparse matrix.r9   )r%   r   Hr
   r   	conjugate	transposer*   rC   s   &r   matrix_daggerrJ      sQ    !Z  ss
	A':;	<	<{{}&&((
G!K
LLr   c                     ^ RI Hp V! V !  # )zCCompute the kronecker product of a sequence of SymPy Matrices.
    )matrix_kronecker_product)$sympy.matrices.expressions.kroneckerrL   )matricesrL   s   * r   _sympy_tensor_productrO      s     N#X..r   c                     \         '       g   \        hV ^ ,          pV R,           F  p\         P                  W4      pK  	  V# )z6numpy version of tensor product of multiple arguments.r@   NN)r"   r#   kronproductansweritems   *  r   _numpy_tensor_productrW      s9    2QZF& Mr   c                     \         '       g   \        hV ^ ,          pV R,           F  p\         P                  W4      pK  	  \         P                  V4      # )z=scipy.sparse version of tensor product of multiple arguments.rQ   )r   r#   rR   r0   rS   s   *  r   _scipy_sparse_tensor_productrY      sG    6QZFV*  V$$r   c                     \        V ^ ,          \        4      '       d
   \        V !  # \        V ^ ,          \        4      '       d
   \	        V !  # \        V ^ ,          \
        4      '       d
   \        V !  # R# )zGCompute the matrix tensor product of sympy/numpy/scipy.sparse matrices.N)r%   r   rO   r
   rW   r   rY   )rT   s   *r   matrix_tensor_productr[      s\    '!*j))$g..	GAJ	.	.$g..	GAJ 3	4	4+W55 
5r   c                z    \         '       g   \        h\         P                  \         P                  V RR7      4      # )znumpy version of complex eye.r    r!   )r"   r#   r&   r   ns   &r   
_numpy_eyer_      s)    288BFF1IF.//r   c                T    \         '       g   \        h\         P                  W RR7      # )z$scipy.sparse version of complex eye.r    r!   )r   r#   r   r]   s   &r   _scipy_sparse_eyera      s     6::a):,,r   c                    VP                  RR4      pVR8X  d   \        V 4      # VR8X  d   \        V 4      # VR8X  d   \        V 4      # \	        RV,          4      h)z=Get the version of eye and tensor_product for a given format.formatsympyr   scipy.sparsezInvalid format: %r)r$   r   r_   ra   NotImplementedError)r^   r-   rc   s   &, r   
matrix_eyerg      sY    [[7+F1v	7	!}	>	! ##
2V;
<<r   c                z    VP                  RR4      p\        '       g   \        h\        P                  W3VR7      # )znumpy version of zeros.r   float64r!   )r$   r"   r#   r   )r,   r^   r-   r   s   &&, r   _numpy_zerosrj      s2    KK+E288QF%8((r   c                    VP                  RR4      pVP                  RR4      p\        '       g   \        hVR8X  d   \        P                  W3VR7      # VR8X  d   \        P	                  W3VR7      # R# )zscipy.sparse version of zeros.spmatrixcsrr   ri   lilr!   N)r$   r   r#   
lil_matrixr0   )r,   r^   r-   rl   r   s   &&,  r   _scipy_sparse_zerosrp      sr    {{:u-HKK+E65  !u 55	U	  !u 55 
r   c                    VP                  RR4      pVR8X  d   \        W4      # VR8X  d   \        W3/ VB # VR8X  d   \        W3/ VB # \	        RV,          4      h)z'"Get a zeros matrix for a given format.rc   rd   r   re   zInvaild format: %r)r$   r   rj   rp   rf   )r,   r^   r-   rc   s   &&, r   matrix_zerosrr      se    [[7+FQ{	7	A,G,,	>	!"13733
2V;
<<r   c                    \         '       g   \        h\         P                  V 4      p\         P                  W4      '       d   R# V # )z/Convert a numpy zero matrix to the zero scalar.        )r"   r#   
zeros_likeallclose)rD   tests   & r   _numpy_matrix_to_zerorx      s2    2==D	{{1r   c                    \         '       g   \        hV P                  4       p\         P                  V4      p\         P	                  W4      '       d   R# V # )z6Convert a scipy.sparse zero matrix to the zero scalar.rt   )r"   r#   r3   ru   rv   )rD   edenserw   s   &  r   _scipy_sparse_matrix_to_zeror{      s=    2YY[F== D	{{6  r   c                   \        V \        4      '       d+   \        V P                  !  V 8X  d   \        P
                  p V # \        V \        4      '       d   \        V 4      p V # \        V \        4      '       d   \        V 4      p V # )z)Convert a zero matrix to the scalar zero.)
r%   r   r   rB   r   Zeror
   rx   r   r{   rC   s   &r   matrix_to_zeror~     sn    !Z  !''?aA
 H	 
A}	%	%!!$ H 
A*	+	+(+Hr   )r
   r   r.   r1   r7   r5   rE   rJ   r:   r<   r>   r[   rr   ),__doc__sympy.core.exprr   sympy.core.numbersr   sympy.core.singletonr   sympy.matrices.matrixbaser   sympy.matricesr   r   sympy.externalr	   __all__r"   r
   ndarrayr   r   r   rl   r.   r1   r5   r7   r:   r<   r>   rE   rJ   rO   rW   rY   r[   r_   ra   rg   rj   rp   rr   rx   r{   r~   r   r   r   <module>r      s    B     " 0 % (& 7	  JJMgj8*-EF F\\F //
J
J#


M	MMM/	%60-	=)	6	=		r   