K iI! UddlmZddlZddlmZddlmZddlmZddl m Z ddl m Z ddl Z ddlmZed Zerej"Zej&Zdd lmZdd lmZdd lmZeed dZe ej8Zie j:ej<e j>ej@e jBejDe jFejHe jJejLe jNejNe jPejPe jRejRe jTejTe jVejVe jXejZe j\ej\e j^ej`e jbejbe jdejfe jhejje jlejlie jnejpe jrejre jtejve jxejxe jzej|e j~eje jeje jeje jeje jeje jeje jeje jeje jeje jeje jeje jeje jeje jeje jeje jeje jeje jeje jeje jjjde jeej<e jeej@e jeje jeje jeje jedddgiZoGddeZpiZqderd<ddZsddZtddddddZuy)) annotationsN)Any) import_module)Printer)sympy_deprecation_warning) is_sequence)partialaesara)nlinalg)Elemwise) DimShuffle true_dividec.tjddSNr)aetcomplex_/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/printing/aesaracode.pyrGsS[[15Er)FFrceZdZdZdZfdZddZddZdZdZ dZ d Z d Z d Z e xZZd Zd ZdZdZdZdZdZdZdZdZdZdZddZxZS) AesaraPrinteraq .. deprecated:: 1.14. The ``Aesara Code printing`` is deprecated.See its documentation for more information. See :ref:`deprecated-aesaraprinter` for details. Code printer which creates Aesara symbolic expression graphs. Parameters ========== cache : dict Cache dictionary to use. If None (default) will use the global cache. To create a printer which does not depend on or alter global state pass an empty dictionary. Note: the dictionary is not copied on initialization of the printer and will be updated in-place, so using the same dict object when creating multiple printers or making multiple calls to :func:`.aesara_code` or :func:`.aesara_function` means the cache is shared between all these applications. Attributes ========== cache : dict A cache of Aesara variables which have been created for SymPy symbol-like objects (e.g. :class:`sympy.core.symbol.Symbol` or :class:`sympy.matrices.expressions.MatrixSymbol`). This is used to ensure that all references to a given symbol in an expression (or multiple expressions) are printed as the same Aesara variable, which is created only once. Symbols are differentiated only by name and type. The format of the cache's contents should be considered opaque to the user. _aesaracR|jdi|_t| |i|y)Ncache)poprsuper__init__)selfargskwargs __class__s rrzAesaraPrinter.__init__ts'ZZ,  $)&)rcR| |j}|t||j||fS)z Get the cache key for a SymPy object. Parameters ========== s : sympy.core.basic.Basic SymPy object to get key for. name : str Name of object, if it does not have a ``name`` attribute. )nametyper!)r sr%dtype broadcastables r_get_keyzAesaraPrinter._get_keyxs+ <66Dd1gqvvum<))D3KDKK.v.DD8}EsAc 4t|jSr?)floatevalf)r nr"s r _print_NumberzAesaraPrinter._print_NumbersQWWYrc l|jdij|}|j||dS)Nr4NNr-r6)r Xr"r(s r_print_MatrixSymbolz!AesaraPrinter._print_MatrixSymbols5 8R(,,Q/""1E"NNrc ttds tdtj|j Dcgc]#}|Dcgc]}|j |fi|c}%c}}Scc}wcc}}w)N stacklistsz>Matrix translation not yet supported in this version of Aesara)hasattrrNotImplementedErrorrQtolistrA)r rNr"LrDs r_print_DenseMatrixz AesaraPrinter._print_DenseMatrixspsL)%OQ Q~~XXZ 45 5C[T[[ ' ' 5   5 s A3 A.!A3 .A3 c |jDcgc]}|j|fi|}}|d}|ddD]}tj||}|Scc}wr)r!rArdot)r rBr"rDrEresultchilds r _print_MatMulzAesaraPrinter._print_MatMulsb:>))D3KDKK.v.DD!ab\ ,EWWVU+F , EsAc  |jDcgc]}|j|fi|}}d}t|dtr6|ddkDr.t |dD]}t j ||d}|Stdcc}w)Nrrz^Only non-negative integer powers of matrices can be handled by Aesara at the moment)r!rA isinstanceintrangerrXrS)r rBr"rDrErYis r _print_MatPowzAesaraPrinter._print_MatPows:>))D3KDKK.v.DD hqk3 'HQK!O8A;' 6!5 6  &'HI I EsBc |j|jfi|}|jt|jfi|}|jt|jfi|}|||fSr?)rAparentslicerowslicecolslice)r rBr"rcrerfs r_print_MatrixSlicez AesaraPrinter._print_MatrixSlicesgT[[3F34;;udmm4??4;;udmm4??h())rc f|jj\}}t|Dcgc];}t|Dcgc]$}|j|j||ffi|&c}=}}}t j dg|Dcgc]}t j dg|c}Scc}wcc}}wcc}wr)blocksr.r_rArjoin) r rBr"nrowsncolsrcrirows r_print_BlockMatrixz AesaraPrinter._print_BlockMatrixs{{(( u"'u/"'u/4;;t{{1a40;F;///xxB&A3SXXa.#.ABB//BsB()B# #B(B. #B(c t|j|j|jfDcgc]1}t |t j r|j|fi|n|3c}Scc}wr?)rdstartstopstepr]sympyBasicrA)r rBr"r`s r _print_slicezAesaraPrinter._print_slicesj"&**dii!CE&a5#t{{1//;<=EF FEs6A%c "tjSr?)mathpir rBr"s r _print_PizAesaraPrinter._print_Pis wwrc ddl}|jdj\}}|j|fi|}|j|fi|}t|jdk(r!tj |||j S|jtj|jddfi|}tj |||Sr) numpyr!rAlenrswitchnanru Piecewise) r rBr"npecondp_condp_e p_remainings r_print_PiecewisezAesaraPrinter._print_Piecewises))A,##4T,V,dkk!&v& tyy>Q ::fc2662 2"dkk%//499QR="ALVL zz&#{33rc t|j|jfi||j|jfi|Sr?)rrApqr{s r_print_RationalzAesaraPrinter._print_Rationals<;4;;tvv88&4;;tvv88: :rc |jSr?)rr{s r_print_IntegerzAesaraPrinter._print_Integers vv rc n|jtj|jddzfi|Sr)rArugammar!r{s r_print_factorialzAesaraPrinter._print_factorials.t{{5;;tyy|a'78CFCCrc ddlm}|j|jfi|}|jD]2}|j|fi|}|||t j |}4|S)Nr)Rop)aesara.gradientrrArB variablesr ones_like)r derivr"rrvvars r_print_DerivativezAesaraPrinter._print_Derivativesd' T[[ .v .?? 2C$++c,V,CRcmmC01B 2 rc|Sr?r)r rBs r emptyPrinterzAesaraPrinter.emptyPrinters rc:|i}|i}|j|||S)a9 Convert a SymPy expression to a Aesara graph variable. The ``dtypes`` and ``broadcastables`` arguments are used to specify the data type, dimension, and broadcasting behavior of the Aesara variables corresponding to the free symbols in ``expr``. Each is a mapping from SymPy symbols to the value of the corresponding argument to ``aesara.tensor.var.TensorVariable``. See the corresponding `documentation page`__ for more information on broadcasting in Aesara. .. __: https://aesara.readthedocs.io/en/latest/reference/tensor/shapes.html#broadcasting Parameters ========== expr : sympy.core.expr.Expr SymPy expression to print. dtypes : dict Mapping from SymPy symbols to Aesara datatypes to use when creating new Aesara variables for those symbols. Corresponds to the ``dtype`` argument to ``aesara.tensor.var.TensorVariable``. Defaults to ``'floatX'`` for symbols not included in the mapping. broadcastables : dict Mapping from SymPy symbols to the value of the ``broadcastable`` argument to ``aesara.tensor.var.TensorVariable`` to use when creating Aesara variables for those symbols. Defaults to the empty tuple for symbols not included in the mapping (resulting in a scalar). Returns ======= aesara.graph.basic.Variable A variable corresponding to the expression's value in a Aesara symbolic expression graph. )r4r5)rA)r rBr4r5s rdoprintzAesaraPrinter.doprints/R >F  !N{{4~{NNrNNNrM)__name__ __module__ __qualname____doc__ printmethodrr*r2r9r=rFrKrOrV_print_ImmutableMatrix_print_ImmutableDenseMatrixr[rargrprwr|rrrrrrr __classcell__)r#s@rrrRs>K*=$.E P   O `). Defaults to the module-level global cache. dtypes : dict Passed to :meth:`.AesaraPrinter.doprint`. broadcastables : dict Passed to :meth:`.AesaraPrinter.doprint`. Returns ======= aesara.graph.basic.Variable A variable corresponding to the expression's value in a Aesara symbolic expression graph. z9 The aesara_code function is deprecated. 1.14deprecated-aesaraprinterdeprecated_since_versionactive_deprecations_targetz"aesara is required for aesara_code)rsettings)rr ImportErrorrrr)rBrr"s r aesara_coderHsS8 "(#=  >?? } :=ur 2 : :4 J6 JJrc |tj|d|zS|It|j}|j Dcic]\}}|d|zd||z zzc}}S||SiScc}}w)a6 Get value of ``broadcastables`` argument to :func:`.aesara_code` from keyword arguments to :func:`.aesara_function`. Included for backwards compatibility. Parameters ========== inputs Sequence of input symbols. dim : int Common number of dimensions for all inputs. Overrides other arguments if given. dims : dict Mapping from input symbols to number of dimensions. Overrides ``broadcastables`` argument if given. broadcastables : dict Explicit value of ``broadcastables`` argument to :meth:`.AesaraPrinter.doprint`. If not None function will return this value unchanged. Returns ======= dict Dictionary mapping elements of ``inputs`` to their "broadcastable" values (tuple of ``bool``\ s). F)T)dictfromkeysmaxvaluesitems)inputsdimdimsr5maxdimr'ds r dim_handlingrus> }}VX^44 T[[]#  1 x!|g!44 4  ! I s A-rrr5c tdddts td|jdi}|jdi}t ||||}t t ||| } tt| |} tt| |} | D cgc]G} t| tjjjr| ntj| I} } t| d k(r| d } tj | | fi|j"D cgc]$} t| j$j&d k(&c} |r t)s _Sfd }|_j.|_|_|Scc} wcc} w) ao Create a Aesara function from SymPy expressions. The inputs and outputs are converted to Aesara variables using :func:`.aesara_code` and then passed to ``aesara.function``. Parameters ========== inputs Sequence of symbols which constitute the inputs of the function. outputs Sequence of expressions which constitute the outputs(s) of the function. The free symbols of each expression must be a subset of ``inputs``. scalar : bool Convert 0-dimensional arrays in output to scalars. This will return a Python wrapper function around the Aesara function object. cache : dict Cached Aesara variables (see :class:`AesaraPrinter.cache `). Defaults to the module-level global cache. dtypes : dict Passed to :meth:`.AesaraPrinter.doprint`. broadcastables : dict Passed to :meth:`.AesaraPrinter.doprint`. dims : dict Alternative to ``broadcastables`` argument. Mapping from elements of ``inputs`` to integers indicating the dimension of their associated arrays/tensors. Overrides ``broadcastables`` argument if given. dim : int Another alternative to the ``broadcastables`` argument. Common number of dimensions to use for all arrays/tensors. ``aesara_function([x, y], [...], dim=2)`` is equivalent to using ``broadcastables={x: (False, False), y: (False, False)}``. Returns ======= callable A callable object which takes values of ``inputs`` as positional arguments and returns an output array for each of the expressions in ``outputs``. If ``outputs`` is a single expression the function will return a Numpy array, if it is a list of multiple expressions the function will return a list of arrays. See description of the ``squeeze`` argument above for the behavior when a single output is passed in a list. The returned object will either be an instance of ``aesara.compile.function.types.Function`` or a Python wrapper function around one. In both cases, the returned value will have a ``aesara_function`` attribute which points to the return value of ``aesara.function``. Examples ======== >>> from sympy.abc import x, y, z >>> from sympy.printing.aesaracode import aesara_function A simple function with one input and one output: >>> f1 = aesara_function([x], [x**2 - 1], scalar=True) >>> f1(3) 8.0 A function with multiple inputs and one output: >>> f2 = aesara_function([x, y, z], [(x**z + y**z)**(1/z)], scalar=True) >>> f2(3, 4, 2) 5.0 A function with multiple inputs and multiple outputs: >>> f3 = aesara_function([x, y], [x**2 + y**2, x**2 - y**2], scalar=True) >>> f3(2, 3) [13.0, -5.0] See also ======== dim_handling z= The aesara_function function is deprecated. rrrz&Aesara is required for aesara_functionrr4r)rr4r5rrc|}t|r(t|Dcgc]\}}|r|dn|c}}S|dScc}}w)Nr)r enumerate)r!outr`ofuncis_0ds rwrapperz aesara_function..wrapper'sMDk s 9B3HAU1XAbE1,H Hr7NIs?)rr rrrr rlistmapr]graphbasicVariableras_tensor_variablerfunctionoutputsvariabler)anyaesara_function __wrapped__r)rrscalarrrr5r"rr4codetinputstoutputsoutputrrrrs @@rrrsr "(#=  BCC JJw #E ZZ" %F!Cd>N ;eF"0 2D3tV$%GCg&'H}EFrx*VV\\-?-?-H-HIsOeOeflOmmFHF 8}A; ??7H 7 7D9= FAS)) *a / FE U# GllGO"G N9F Gs A F)F r?rr)v __future__rrytypingrsympy.externalrsympy.printing.printerrsympy.utilities.exceptionsrsympy.utilities.iterablesrru functoolsr r raesr/r aesara.tensorr aesara.tensor.elemwiser r getattrrtrue_divAddaddMulmulAbsabssignsgnceilingceilfloorlogexpsqrtcosacosarccossinasinarcsintanatanarctanatan2arctan2coshacosharccoshsinhasinharcsinhtanhatanharctanhrerealimimagrDangleerfrloggammagammalnPowpowEqeqStrictGreaterThangtStrictLessThanltLessThanle GreaterThangeAnd bitwise_andOr bitwise_orNotinvertXor bitwise_xorMaxmaximumMinminimum conjugateconjcorenumbers ImaginaryUnitMatAddHadamardProductTracetrace DeterminantdetInversematrix_inverse Transposer@rr__annotations__rrrrrrr7s=" (*@1  x  --C --C%/1 #}d3Kll 2 IIsww2 IIsww2 IIsww2 JJ 2 MM388 2 KK 2 IIsww2 IIsww2 JJ2 IIsww2 JJ 2 IIsww2 JJ 2 IIsww2 JJ 2 KK!2" JJ#2$ KK%2& JJ'2( KK)2* JJ+2, KK-2. HHchh/20 HHchh122 IIsyy324 IIsww526 KK728 NNCKK92: IIsww;2< HHcff=2>  # #SVV?2@  #&&A2B NNCFFC2D   svvE2F IIs HHcnn IIszz IIs IIs{{ IIs{{ OOSXX JJ   , ,.E LL(377+  ! !8CGG#4 KK    MM711 OOZA?c2GjpOGpOf " n!*KZ,^O tDOr