
    sgH                         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 dlmZ  G d d	e      Zed
        Z G d de      Zy)    )Iterable)singledispatch)Expr)Mul)S)sympify)global_parametersc                   <    e Zd ZdZdZd Zd Zd Zed        Z	d Z
y)	TensorProductz,
    Generic class for tensor products.
    Fc                 J   ddl m}m}m} ddlm} ddlm} ddlm	} |D 	cg c]  }	t        |	       }}	|j                  dt        j                        }
|
st        j                  | g| }|S g }g }t         j"                  }|D ]Q  }	t%        |	t&        ||f      r|j)                   ||	             .t%        |	|f      r|j)                  |	       M||	z  }S | || z  }t+        |      dk(  r|S |dk7  r|g|z   }n|}t        j                  | g|i |} ||      S c c}	w )Nr   )	NDimArraytensorproductArray)
MatrixExpr)
MatrixBase)flattenevaluate   )sympy.tensor.arrayr   r   r   "sympy.matrices.expressions.matexprr   sympy.matrices.matrixbaser   sympy.strategiesr   r   getr	   r   r   __new__r   One
isinstancer   appendlen)clsargskwargsr   r   r   r   r   r   argr   objarraysotherscalarcoeffnewargss                    I/var/www/html/venv/lib/python3.12/site-packages/sympy/tensor/functions.pyr   zTensorProduct.__new__   s   FFA8,(,---::j*;*D*DE,,s*T*CJ 	C#*i@AeCj)C*/S!#	 }f--u:?LA:goGGll333F3s|5 .s   D c                 ,    t        | j                        S N)r   shape)selfs    r)   rankzTensorProduct.rank3   s    4::    c                     ddl m} | j                  D cg c],  }t        |d      r|j                  n ||      j                  . c}S c c}w )Nr   )r   r,   )r   r   r    hasattrr,   )r-   r   is      r)   _get_args_shapeszTensorProduct._get_args_shapes6   s7    ,LPIIVq71g.E!HNNBVVVs   1A	c                 :    | j                         }t        |d      S )N )r3   sum)r-   
shape_lists     r)   r,   zTensorProduct.shape:   s    **,
:r""r/   c                     t              t        j                  fdt        | j                  | j                               D              S )Nc              3   j   K   | ]*  \  }}|j                  t        fd |D                     , yw)c              3   4   K   | ]  }t                y wr+   )next).0r2   indexs     r)   	<genexpr>z6TensorProduct.__getitem__.<locals>.<genexpr>.<genexpr>B   s     !;!$u+!;s   N)__getitem__tuple)r<   r"   shpr=   s      r)   r>   z,TensorProduct.__getitem__.<locals>.<genexpr>A   s1      
S OOE!;s!;;<
s   03)iterr   fromiterzipr    r3   )r-   r=   s    `r)   r?   zTensorProduct.__getitem__?   s>    U|| 
		4+@+@+BC
 
 	
r/   N)__name__
__module____qualname____doc__	is_numberr   r.   r3   propertyr,   r?   r5   r/   r)   r   r      s8     I DW # #
r/   r   c                 N    t        | d      r| j                  S t        d| z        )a  
    Return the shape of the *expr* as a tuple. *expr* should represent
    suitable object such as matrix or array.

    Parameters
    ==========

    expr : SymPy object having ``MatrixKind`` or ``ArrayKind``.

    Raises
    ======

    NoShapeError : Raised when object with wrong kind is passed.

    Examples
    ========

    This function returns the shape of any object representing matrix or array.

    >>> from sympy import shape, Array, ImmutableDenseMatrix, Integral
    >>> from sympy.abc import x
    >>> A = Array([1, 2])
    >>> shape(A)
    (2,)
    >>> shape(Integral(A, x))
    (2,)
    >>> M = ImmutableDenseMatrix([1, 2])
    >>> shape(M)
    (2, 1)
    >>> shape(Integral(M, x))
    (2, 1)

    You can support new type by dispatching.

    >>> from sympy import Expr
    >>> class NewExpr(Expr):
    ...     pass
    >>> @shape.register(NewExpr)
    ... def _(expr):
    ...     return shape(expr.args[0])
    >>> shape(NewExpr(M))
    (2, 1)

    If unsuitable expression is passed, ``NoShapeError()`` will be raised.

    >>> shape(Integral(x, x))
    Traceback (most recent call last):
      ...
    sympy.tensor.functions.NoShapeError: shape() called on non-array object: Integral(x, x)

    Notes
    =====

    Array-like classes (such as ``Matrix`` or ``NDimArray``) has ``shape``
    property which returns its shape, but it cannot be used for non-array
    classes containing array. This function returns the shape of any
    registered object representing array.

    r,   zA%s does not have shape, or its type is not registered to shape().)r1   r,   NoShapeError)exprs    r)   r,   r,   G   s0    z tWzz
KdRT Tr/   c                       e Zd ZdZy)rL   an  
    Raised when ``shape()`` is called on non-array object.

    This error can be imported from ``sympy.tensor.functions``.

    Examples
    ========

    >>> from sympy import shape
    >>> from sympy.abc import x
    >>> shape(x)
    Traceback (most recent call last):
      ...
    sympy.tensor.functions.NoShapeError: shape() called on non-array object: x
    N)rE   rF   rG   rH   r5   r/   r)   rL   rL      s     	r/   rL   N)collections.abcr   	functoolsr   sympy.core.exprr   sympy.core.mulr   sympy.core.singletonr   sympy.core.sympifyr   sympy.core.parametersr	   r   r,   	ExceptionrL   r5   r/   r)   <module>rW      sJ    $ $    " & 39
D 9
x ?T ?TD	9 	r/   