K iHddlmZddlmZddlmZddlmZddlm Z ddl m Z ddl m Z Gdd eZed ZGd d eZy ))Iterable)singledispatch)Expr)Mul)S)sympify)global_parametersc<eZdZdZdZdZdZdZedZ dZ y) TensorProductz, Generic class for tensor products. FcJddlm}m}m}ddlm}ddlm}ddlm }|D cgc] } t| }} |jdtj} | stj|g|} | Sg} g} t j"}|D]Q} t%| t&||fr| j)|| .t%| |fr| j)| M|| z}S||| z}t+| dk(r|S|dk7r|g| z}n| }tj|g|i|} || Scc} w)Nr) NDimArray tensorproductArray) MatrixExpr) MatrixBase)flattenevaluate)sympy.tensor.arrayr rr"sympy.matrices.expressions.matexprrsympy.matrices.matrixbasersympy.strategiesrrgetr rr__new__rOne isinstancerappendlen)clsargskwargsr rrrrrargrobjarraysotherscalarcoeffnewargss \/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/tensor/functions.pyrzTensorProduct.__new__sFFA8,(,- --::j*;*D*DE,,s*T*CJ C#*i@A eCj)C*/ S!#   }f-- u:?L A:goGGll333F3s|5.sD c,t|jSN)rshape)selfs r)rankzTensorProduct.rank3s4::cddlm}|jDcgc],}t|dr |jn||j.c}Scc}w)Nr)rr,)rrr hasattrr,)r-ris r)_get_args_shapeszTensorProduct._get_args_shapes6s7,LPIIVq71g.E!HNNBVVVs1A c:|j}t|dS)N)r3sum)r- shape_lists r)r,zTensorProduct.shape:s**, :r""r/cttjfdt|j|j DS)Nc3jK|]*\}}|jtfd|D,yw)c34K|]}tywr+)next).0r2indexs r) z6TensorProduct.__getitem__...Bs!;!$u+!;sN) __getitem__tuple)r<r"shpr=s r)r>z,TensorProduct.__getitem__..As1 S OOE!;s!;; < s03)iterrfromiterzipr r3)r-r=s `r)r?zTensorProduct.__getitem__?s>U ||  4+@+@+BC   r/N) __name__ __module__ __qualname____doc__ is_numberrr.r3propertyr,r?r5r/r)r r s8I DW## r/r cNt|dr |jStd|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().)r1r, NoShapeError)exprs r)r,r,Gs0ztWzz KdR TTr/ceZdZdZy)rLan 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)rErFrGrHr5r/r)rLrLs  r/rLN)collections.abcr functoolsrsympy.core.exprrsympy.core.mulrsympy.core.singletonrsympy.core.sympifyrsympy.core.parametersr r r, ExceptionrLr5r/r)rWsJ$$ "&39 D9 x?T?TD 9 r/