
    EdF                         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dS )    )Iterable)singledispatch)Expr)Mul)Ssympify)global_parametersc                   D    e Zd ZdZdZd Zd Zd Zed             Z	d Z
dS )	TensorProductz,
    Generic class for tensor products.
    Fc                 F   ddl m}m}m} ddlm} ddlm} ddlm	} d |D             }|
                    dt          j                  }	|	st          j        | g|R  }
|
S g }g }t          j        }|D ]e}t#          |t$          ||f          r|                     ||                     9t#          ||f          r|                    |           `||z  }f| || z  }t)          |          dk    r|S |dk    r|g|z   }n|}t          j        | g|R i |}
 ||
          S )	Nr   )	NDimArraytensorproductArray)
MatrixExpr)
MatrixBase)flattenc                 ,    g | ]}t          |          S  r   ).0args     6lib/python3.11/site-packages/sympy/tensor/functions.py
<listcomp>z)TensorProduct.__new__.<locals>.<listcomp>   s    ------    evaluate   )sympy.tensor.arrayr   r   r   "sympy.matrices.expressions.matexprr   sympy.matrices.matricesr   sympy.strategiesr   getr
   r   r   __new__r   One
isinstancer   appendlen)clsargskwargsr   r   r   r   r   r   r   objarraysotherscalarr   coeffnewargss                    r   r"   zTensorProduct.__new__   s   FFFFFFFFFFAAAAAA666666,,,,,,-----::j*;*DEE 	,s*T***CJ 	 	C#*i@AA eeCjj))))C*// S!!!!#}}f--u::? 	LA: 	goGGGl33333F33ws||r   c                 *    t          | j                  S N)r&   shape)selfs    r   rankzTensorProduct.rank3   s    4:r   c                 6    ddl m fd| j        D             S )Nr   )r   c                 ^    g | ])}t          |d           r|j        n |          j        *S )r2   )hasattrr2   )r   ir   s     r   r   z2TensorProduct._get_args_shapes.<locals>.<listcomp>8   s8    VVVq71g..BEE!HHNVVVr   )r   r   r(   )r3   r   s    @r   _get_args_shapeszTensorProduct._get_args_shapes6   s1    ,,,,,,VVVVDIVVVVr   c                 J    |                                  }t          |d          S )Nr   )r9   sum)r3   
shape_lists     r   r2   zTensorProduct.shape:   s#    **,,
:r"""r   c                     t                    t          j        fdt          | j        |                                           D                       S )Nc              3   z   K   | ]5\  }}|                     t          fd |D                                 V  6dS )c              3   6   K   | ]}t                    V  d S r1   )next)r   r8   indexs     r   	<genexpr>z6TensorProduct.__getitem__.<locals>.<genexpr>.<genexpr>B   s)      !;!;!$u++!;!;!;!;!;!;r   N)__getitem__tuple)r   r   shprA   s      r   rB   z,TensorProduct.__getitem__.<locals>.<genexpr>A   sd       
 
S OOE!;!;!;!;s!;!;!;;;<<
 
 
 
 
 
r   )iterr   fromiterzipr(   r9   )r3   rA   s    `r   rC   zTensorProduct.__getitem__?   s`    U| 
 
 
 
	4+@+@+B+BCC
 
 
 
 
 	
r   N)__name__
__module____qualname____doc__	is_numberr"   r4   r9   propertyr2   rC   r   r   r   r   r      s          I     D  W W W # # X#
 
 
 
 
r   r   c                 T    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.

    r2   zA%s does not have shape, or its type is not registered to shape().)r7   r2   NoShapeError)exprs    r   r2   r2   G   s<    z tW z
KdRT T Tr   c                       e Zd ZdZdS )rP   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)rI   rJ   rK   rL   r   r   r   rP   rP      s          	Dr   rP   N)collections.abcr   	functoolsr   sympy.core.exprr   sympy.core.mulr   sympy.core.singletonr   sympy.core.sympifyr	   sympy.core.parametersr
   r   r2   	ExceptionrP   r   r   r   <module>r[      s   $ $ $ $ $ $ $ $ $ $ $ $                   " " " " " " & & & & & & 3 3 3 3 3 39
 9
 9
 9
 9
D 9
 9
 9
x ?T ?T ?TD	 	 	 	 	9 	 	 	 	 	r   