K i nddlmZddlmZmZddlmZddlmZm Z ddl m Z ddl m Z mZGdd eZy ) ) MatrixExpr) FunctionClassLambda)Dummy)_sympifysympify)Matrix)reimcTeZdZdZfdZedZedZdZdZ dZ xZ S)FunctionMatrixaRepresents a matrix using a function (``Lambda``) which gives outputs according to the coordinates of each matrix entries. Parameters ========== rows : nonnegative integer. Can be symbolic. cols : nonnegative integer. Can be symbolic. lamda : Function, Lambda or str If it is a SymPy ``Function`` or ``Lambda`` instance, it should be able to accept two arguments which represents the matrix coordinates. If it is a pure string containing Python ``lambda`` semantics, it is interpreted by the SymPy parser and casted into a SymPy ``Lambda`` instance. Examples ======== Creating a ``FunctionMatrix`` from ``Lambda``: >>> from sympy import FunctionMatrix, symbols, Lambda, MatPow >>> i, j, n, m = symbols('i,j,n,m') >>> FunctionMatrix(n, m, Lambda((i, j), i + j)) FunctionMatrix(n, m, Lambda((i, j), i + j)) Creating a ``FunctionMatrix`` from a SymPy function: >>> from sympy import KroneckerDelta >>> X = FunctionMatrix(3, 3, KroneckerDelta) >>> X.as_explicit() Matrix([ [1, 0, 0], [0, 1, 0], [0, 0, 1]]) Creating a ``FunctionMatrix`` from a SymPy undefined function: >>> from sympy import Function >>> f = Function('f') >>> X = FunctionMatrix(3, 3, f) >>> X.as_explicit() Matrix([ [f(0, 0), f(0, 1), f(0, 2)], [f(1, 0), f(1, 1), f(1, 2)], [f(2, 0), f(2, 1), f(2, 2)]]) Creating a ``FunctionMatrix`` from Python ``lambda``: >>> FunctionMatrix(n, m, 'lambda i, j: i + j') FunctionMatrix(n, m, Lambda((i, j), i + j)) Example of lazy evaluation of matrix product: >>> Y = FunctionMatrix(1000, 1000, Lambda((i, j), i + j)) >>> isinstance(Y*Y, MatPow) # this is an expression object True >>> (Y**2)[10,10] # So this is evaluated lazily 342923500 Notes ===== This class provides an alternative way to represent an extremely dense matrix with entries in some form of a sequence, in a most sparse way. ct|t|}}|j||j|t|}t|tt fst dj|d|jvrt dj|t|t s+tdtd}}t ||f|||}t|-||||S)Nz4{} should be compatible with SymPy function classes.z({} should be able to accept 2 arguments.ij) r _check_dimr isinstancerr ValueErrorformatnargsrsuper__new__)clsrowscolslamdarr __class__s k/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/matrices/expressions/funcmatrix.pyrzFunctionMatrix.__new__Psd^Xd^d t t%-!89F   EKK :AA%HJ J%(:uSzqAAq65A;/EwsD$66c |jddS)Nrrargsselfs rshapezFunctionMatrix.shapeesyy1~r c |jdS)Nrr"r$s rrzFunctionMatrix.lamdaisyy|r c &|j||SN)r)r%rrkwargss r_entryzFunctionMatrix._entrymszz!Qr cdddlm}ddlm}||j |j S)Nr)Trace)Sum) sympy.matrices.expressions.tracer-sympy.concrete.summationsr.rewritedoit)r%r-r.s r _eval_tracezFunctionMatrix._eval_traceps&:1T{""3',,..r cRtt|tt|fSr))r r r r$s r_eval_as_real_imagz!FunctionMatrix._eval_as_real_imagus6$< "VD\"233r ) __name__ __module__ __qualname____doc__rpropertyr&rr+r3r5 __classcell__)rs@rrr sFEL7* / 4r rN)matexprrsympy.core.functionrrsympy.core.symbolrsympy.core.sympifyrr sympy.matricesr $sympy.functions.elementary.complexesr r rr rrCs%5#0!7m4Zm4r