
    \hH                         S SK Jr  S SKJr  S SKJr  S SKJr  S SKJ	r	  S SK
Jr  S SKJr   " S S	\5      r\S
 5       r " S S\5      rg)    )Iterable)singledispatch)Expr)Mul)S)sympify)global_parametersc                   D    \ rS rSrSrSrS rS rS r\	S 5       r
S rS	rg
)TensorProduct   z$
Generic class for tensor products.
Fc                 v   SSK JnJnJn  SSKJn  SSKJn  SSKJ	n  U V	s/ s H  n	[        U	5      PM     nn	UR                  S[        R                  5      n
U
(       d  [        R                  " U /UQ76 nU$ / n/ n[         R"                  nU H[  n	[%        U	[&        Xs45      (       a  UR)                  U" U	5      5        M3  [%        X45      (       a  UR)                  U	5        MW  X-  nM]     X" U6 -  n[+        U5      S:X  a  U$ US:w  a  U/U-   nOUn[        R                  " U /UQ70 UD6nU" U5      $ s  sn	f )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                    N/var/www/auris/envauris/lib/python3.13/site-packages/sympy/tensor/functions.pyr   TensorProduct.__new__   s   FFA8,(,--::j*;*D*DE,,s*T*CJC#*@AAeCj)C//S!  }f--u:?LA:goGGll333F3s|5 .s   D6c                 ,    [        U R                  5      $ N)r   shape)selfs    r*   rankTensorProduct.rank3   s    4::    c                     SSK Jn  U R                   Vs/ s H2  n[        US5      (       a  UR                  OU" U5      R                  PM4     sn$ s  snf )Nr   )r   r.   )r   r   r!   hasattrr.   )r/   r   is      r*   _get_args_shapesTensorProduct._get_args_shapes6   s>    ,LPIIVIq71g..E!HNNBIVVVs   9Ac                 :    U R                  5       n[        US5      $ )N )r6   sum)r/   
shape_lists     r*   r.   TensorProduct.shape:   s    **,
:r""r2   c                    ^ [        T5      m[        R                  " U4S j[        U R                  U R                  5       5       5       5      $ )Nc              3   p   >#    U  H+  u  pUR                  [        U4S  jU 5       5      5      v   M-     g7f)c              3   :   >#    U  H  n[        T5      v   M     g 7fr-   )next).0r5   indexs     r*   	<genexpr>6TensorProduct.__getitem__.<locals>.<genexpr>.<genexpr>B   s     !;s!$u++ss   N)__getitem__tuple)rA   r#   shprB   s      r*   rC   ,TensorProduct.__getitem__.<locals>.<genexpr>A   s1      
C OOE!;s!;;<<Cs   36)iterr   fromiterzipr!   r6   )r/   rB   s    `r*   rE   TensorProduct.__getitem__?   s>    U|| 
		4+@+@+BC
 
 	
r2   r9   N)__name__
__module____qualname____firstlineno____doc__	is_numberr   r0   r6   propertyr.   rE   __static_attributes__r9   r2   r*   r   r      s8     I DW # #
r2   r   c                 X    [        U S5      (       a  U R                  $ [        SU -  5      e)a0  
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().)r4   r.   NoShapeError)exprs    r*   r.   r.   G   s3    z tWzz
KdRT Tr2   c                       \ rS rSrSrSrg)rV      aB  
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
r9   N)rM   rN   rO   rP   rQ   rT   r9   r2   r*   rV   rV      s     	r2   rV   N)collections.abcr   	functoolsr   sympy.core.exprr   sympy.core.mulr   sympy.core.singletonr   sympy.core.sympifyr   sympy.core.parametersr	   r   r.   	ExceptionrV   r9   r2   r*   <module>rb      sJ    $ $    " & 39
D 9
x ?T ?TD	9 	r2   