U
    ;qLeF  ã                   @   s„   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	„ d	eƒZed
d„ ƒZG dd„ deƒZdS )é    )ÚIterable)Úsingledispatch)ÚExpr)ÚMul)ÚS©Úsympify)Úglobal_parametersc                   @   s@   e Zd ZdZdZdd„ Zdd„ Zdd„ Zed	d
„ ƒZ	dd„ Z
dS )ÚTensorProductz,
    Generic class for tensor products.
    Fc                 O   s  ddl m}m}m} ddlm} ddlm} ddlm	} dd„ |D ƒ}| 
dtj¡}	|	sltj| f|žŽ }
|
S g }g }tj}|D ]D}t|t||fƒr¢| ||ƒ¡ q~t||fƒrº| |¡ q~||9 }q~|||Ž  }t|ƒdkrà|S |d	krô|g| }n|}tj| f|ž|Ž}
||
ƒS )
Nr   )Ú	NDimArrayÚtensorproductÚArray)Ú
MatrixExpr)Ú
MatrixBase)Úflattenc                 S   s   g | ]}t |ƒ‘qS © r   )Ú.0Úargr   r   úm/home/p21-0144/sympy/latex2sympy2solve-back-end/sympyEq/lib/python3.8/site-packages/sympy/tensor/functions.pyÚ
<listcomp>   s     z)TensorProduct.__new__.<locals>.<listcomp>Úevaluateé   )Úsympy.tensor.arrayr   r   r   Ú"sympy.matrices.expressions.matexprr   Úsympy.matrices.matricesr   Zsympy.strategiesr   Úgetr	   r   r   Ú__new__r   ÚOneÚ
isinstancer   ÚappendÚlen)ÚclsÚargsÚkwargsr   r   r   r   r   r   r   ÚobjZarraysÚotherZscalarr   ÚcoeffÚnewargsr   r   r   r      s4    
zTensorProduct.__new__c                 C   s
   t | jƒS ©N)r    Úshape©Úselfr   r   r   Úrank3   s    zTensorProduct.rankc                    s    ddl m‰  ‡ fdd„| jD ƒS )Nr   ©r   c                    s&   g | ]}t |d ƒr|jnˆ |ƒj‘qS )r)   )Úhasattrr)   ©r   Úir-   r   r   r   8   s     z2TensorProduct._get_args_shapes.<locals>.<listcomp>)r   r   r"   r*   r   r-   r   Ú_get_args_shapes6   s    zTensorProduct._get_args_shapesc                 C   s   |   ¡ }t|dƒS )Nr   )r1   Úsum)r+   Z
shape_listr   r   r   r)   :   s    zTensorProduct.shapec                    s,   t ˆ ƒ‰ t ‡ fdd„t| j|  ¡ ƒD ƒ¡S )Nc                 3   s.   | ]&\}}|  t‡ fd d„|D ƒƒ¡V  qdS )c                 3   s   | ]}t ˆ ƒV  qd S r(   )Únextr/   ©Úindexr   r   Ú	<genexpr>B   s     z6TensorProduct.__getitem__.<locals>.<genexpr>.<genexpr>N)Ú__getitem__Útuple)r   r   Zshpr4   r   r   r6   A   s   ÿz,TensorProduct.__getitem__.<locals>.<genexpr>)Úiterr   ÚfromiterÚzipr"   r1   )r+   r5   r   r4   r   r7   ?   s    þzTensorProduct.__getitem__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú	is_numberr   r,   r1   Úpropertyr)   r7   r   r   r   r   r
      s   "
r
   c                 C   s    t | dƒr| jS td|  ƒ‚dS )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().N)r.   r)   ÚNoShapeError)Úexprr   r   r   r)   G   s
    =
ÿr)   c                   @   s   e Zd ZdZdS )rB   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)r<   r=   r>   r?   r   r   r   r   rB   Š   s   rB   N)Úcollections.abcr   Ú	functoolsr   Úsympy.core.exprr   Zsympy.core.mulr   Úsympy.core.singletonr   Úsympy.core.sympifyr   Úsympy.core.parametersr	   r
   r)   Ú	ExceptionrB   r   r   r   r   Ú<module>   s   <
B