
    wg                        d dl mZ d dlmZmZmZ d dlmZ d dlm	Z	 d dl
mZm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 dlmZ d Zeee<   d Zeee<    G d dee      Z G d dee      ZeZ G d dee      Z eee      d        Z y)    )_matrix)BasicDictTuple)Integer)cacheit)_sympy_converter_sympify)DenseMatrix)
MatrixExpr)
MatrixBase)	RepMatrix)SparseRepMatrix)dispatchc                 "    | j                         S N)as_immutable)args    ]/home/mcse/projects/flask/flask-venv/lib/python3.12/site-packages/sympy/matrices/immutable.pysympify_matrixr      s        c                 ~    | D cg c]  }t        |       }}t        | j                  | j                  |      S c c}w r   )r
   ImmutableDenseMatrixrowscols)r   xmats      r   sympify_mpmath_matrixr      s5     #
$18A;
$C
$#((C88 %s   :c                        e Zd ZdZd Zej                  Zd Zed        Z	ed        Z
ed        Zd Zd Zd	 Zd fd
	Zej                  j                  e_         ee      Zd Z xZS )ImmutableRepMatrixz_Immutable matrix based on RepMatrix

    Uses DomainMAtrix as the internal representation.
    c                 &     | j                   |i |S r   )_new)clsargskwargss      r   __new__zImmutableRepMatrix.__new__*   s    sxx(((r   c                     | S r    selfs    r   copyzImmutableRepMatrix.copy/       r   c                     | j                   S r   )_colsr)   s    r   r   zImmutableRepMatrix.cols2       zzr   c                     | j                   S r   )_rowsr)   s    r   r   zImmutableRepMatrix.rows6   r/   r   c                 2    | j                   | j                  fS r   )r1   r.   r)   s    r   shapezImmutableRepMatrix.shape:   s    zz4::%%r   c                     | S r   r(   r)   s    r   r   zImmutableRepMatrix.as_immutable>   r,   r   c                     | ||f   S r   r(   )r*   ijr%   s       r   _entryzImmutableRepMatrix._entryA   s    AqDzr   c                 J    t        dj                  | j                              )NzCannot set values of {})	TypeErrorformat	__class__)r*   r$   s     r   __setitem__zImmutableRepMatrix.__setitem__D   s    188HIIr   c                 &    t        |   dd|i|S )N
reals_onlyr(   )superis_diagonalizable)r*   r?   r%   r<   s      r   rA   z$ImmutableRepMatrix.is_diagonalizableG   s%    w( -!-%+- 	-r   c                 ^    | j                         j                  ||      j                         S r   )
as_mutableanalytic_funcr   )r*   fr   s      r   rD   z ImmutableRepMatrix.analytic_funcN   s%     ..q!4AACCr   )F)__name__
__module____qualname____doc__r&   r   __hash__r+   propertyr   r   r3   r   r8   r=   rA   r   r   rD   __classcell__)r<   s   @r   r    r       s    ) ""H     & &J- !0 A A I I 12Dr   r    c                   <    e Zd ZdZdZdZdZed        Zed        Z	y)r   aP  Create an immutable version of a matrix.

    Examples
    ========

    >>> from sympy import eye, ImmutableMatrix
    >>> ImmutableMatrix(eye(3))
    Matrix([
    [1, 0, 0],
    [0, 1, 0],
    [0, 0, 1]])
    >>> _[0, 0] = 42
    Traceback (most recent call last):
    ...
    TypeError: Cannot set values of ImmutableDenseMatrix
    T   gn $@c                 @   t        |      dk(  rt        |d   t              r|d   S |j                  dd      du r t        |      dk7  rt	        d      |\  }}}n! | j
                  |i |\  }}}t        |      }| j                  |||      }| j                  |      S )N   r   r+   TF   zA'copy=False' requires a matrix be initialized as rows,cols,[list])	len
isinstancer   getr:   _handle_creation_inputslist_flat_list_to_DomainMatrix_fromrep)r#   r$   r%   r   r   	flat_listreps          r   r"   zImmutableDenseMatrix._newj   s    t9>ja2FG7N::fd#u,4yA~ cdd$(!D$	$?C$?$?$P$P!D$	YI,,T4C||C  r   c           
          |j                   \  }}|j                         j                         }t        j                  | t        |      t        |      t        |ddi      }||_        ||_        ||_	        |S )NsympifyF)
r3   to_sympyto_list_flatr   r&   r   r   r1   r.   _rep)r#   rZ   r   r   rY   objs         r   rX   zImmutableDenseMatrix._fromrepz   sj    YY
dLLN//1	mmCDMDM9,e,. 		
r   N)
rF   rG   rH   rI   	_iterable_class_priority_op_priorityclassmethodr"   rX   r(   r   r   r   r   R   s>    & IOL! ! 
 
r   r   c                   8    e Zd ZdZdZdZed        Zed        Zy)ImmutableSparseMatrixa  Create an immutable version of a sparse matrix.

    Examples
    ========

    >>> from sympy import eye, ImmutableSparseMatrix
    >>> ImmutableSparseMatrix(1, 1, {})
    Matrix([[0]])
    >>> ImmutableSparseMatrix(eye(3))
    Matrix([
    [1, 0, 0],
    [0, 1, 0],
    [0, 0, 1]])
    >>> _[0, 0] = 42
    Traceback (most recent call last):
    ...
    TypeError: Cannot set values of ImmutableSparseMatrix
    >>> _.shape
    (3, 3)
    T	   c                 v     | j                   |i |\  }}}| j                  |||      }| j                  |      S r   )rU   _smat_to_DomainMatrixrX   )r#   r$   r%   r   r   smatrZ   s          r   r"   zImmutableSparseMatrix._new   sC    6366GGdD''dD9||C  r   c                     |j                   \  }}|j                         j                         }t        j                  | t        |      t        |      t        |            }||_        ||_        ||_	        |S r   )
r3   r]   to_dokr   r&   r   r   r1   r.   r_   )r#   rZ   r   r   rj   r`   s         r   rX   zImmutableSparseMatrix._fromrep   s]    YY
d||~$$&mmCtDzJ		
r   N)	rF   rG   rH   rI   	is_Matrixrb   rd   r"   rX   r(   r   r   rf   rf      s9    ( IO! !  r   rf   c                 T    | j                   |j                   k7  ry| |z
  j                  S )a  Helper method for Equality with matrices.sympy.

    Relational automatically converts matrices to ImmutableDenseMatrix
    instances, so this method only applies here.  Returns True if the
    matrices are definitively the same, False if they are definitively
    different, and None if undetermined (e.g. if they contain Symbols).
    Returning None triggers default handling of Equalities.

    F)r3   is_zero_matrix)lhsrhss     r   _eval_is_eqrr      s'     yyCII#I%%%r   N)!mpmath.matrices.matricesr   
sympy.corer   r   r   sympy.core.numbersr   sympy.core.cacher   sympy.core.sympifyr	   sympify_converterr
   sympy.matrices.denser   sympy.matrices.expressionsr   sympy.matrices.matrixbaser   sympy.matrices.repmatrixr   sympy.matrices.sparser   sympy.multipledispatchr   r   r   r    r   ImmutableMatrixrf   rr   r(   r   r   <module>r      s    , ) ) & $ N , 1 0 . 1 + !/ * 9
 3 ' 1DJ 1Dh3;(: 3n '(O-? (V 

 45& 6&r   