
    \hJ                    	   % S r SSKJr  SSKrSSKJr  SSKJr  SSKJ	r	  SSK
Jr  SSKrSSKJr  SS	KJr  SS
KJr  SS/0r\" S5      r\(       Gak  \R*                  r\R.                  rSSKJr  0 \R8                  \R:                  _\R<                  \R>                  _\R@                  \RB                  _\RD                  \RF                  _\RH                  \RJ                  _\RL                  \RL                  _\RN                  \RN                  _\RP                  \RP                  _\RR                  \RR                  _\RT                  \RT                  _\RV                  \RX                  _\RZ                  \RZ                  _\R\                  \R^                  _\R`                  \R`                  _\Rb                  \Rd                  _\Rf                  \Rh                  _\Rj                  \Rj                  _0 \Rl                  \Rn                  _\Rp                  \Rp                  _\Rr                  \Rt                  _\Rv                  \Rv                  _\Rx                  \Rz                  _\R|                  \R~                  _\R                  \R                  _\R                  \R                  _\R                  \R                  _\R                  \R                  _\R                  \R                  _\R                  \R                  _\R                  \R                  _\R                  \R                  _\R                  \R                  _\R                  \R                  _\R                  \R                  _E\R                  \R                  \R                  \R                  \R                  \R                  \R                  \R                  \R                  \R                  \R                  R                  R                  S \R                  \R                  \R:                  5      \R                  \R                  \R>                  5      \R                  \R                  \R                  \R                  \R                  \R                  \R                  \R                  SSS/5      0Erl " S S\	5      rm0 rnS\oS'   SS jrpSS jrq\" SS9SSSSS.S jj5       rrg)z
.. deprecated:: 1.8

  ``sympy.printing.theanocode`` is deprecated. Theano has been renamed to
  Aesara. Use ``sympy.printing.aesaracode`` instead. See
  :ref:`theanocode-deprecated` for more information.

    )annotationsN)Any)import_module)Printer)is_sequence)partial)doctest_depends_on)sympy_deprecation_warning)theano_functiontheano)linalgc                 .    [         R                  SS5      $ Nr      )ttcomplex     Q/var/www/auris/envauris/lib/python3.13/site-packages/sympy/printing/theanocode.py<lambda>r   J   s    RZZ!_r   )FFr   c                     ^  \ rS rSrSrSrU 4S jrSS jrSS jrS r	S r
S	 rS
 rS rS r\=rrS rS rS rS rS rS rS rS rS rS rS rS rS rSS jrSrU =r $ )TheanoPrinterU   ae  Code printer which creates Theano 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:`.theano_code` or :func:`.theano_function` means
    the cache is shared between all these applications.

Attributes
==========

cache : dict
    A cache of Theano 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 Theano 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.
_theanoc                T   > UR                  S0 5      U l        [        TU ]  " U0 UD6  g )Ncache)popr   super__init__)selfargskwargs	__class__s      r   r   TheanoPrinter.__init__r   s'    ZZ,
$)&)r   c                R    Uc  UR                   nU[        U5      UR                  X44$ )zGet 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.
)nametyper!   )r    sr&   dtypebroadcastables        r   _get_keyTheanoPrinter._get_keyv   s)     <66Dd1gqvvu<<r   c                    Uc  UR                   nUc  SnUc  SnU R                  XX4S9nXPR                  ;   a  U R                  U   $ [        R	                  X#US9nX`R                  U'   U$ )z_
Get the Theano variable for a SymPy symbol from the cache, or create it
if it does not exist.
floatXr   r)   r*   r&   r)   r*   )r&   r+   r   r   tensor)r    r(   r&   r)   r*   keyvalues          r   _get_or_createTheanoPrinter._get_or_create   ss     <66D=E MmmA5mN**::c?"		t	N

3r   c                    UR                  S0 5      R                  U5      nUR                  S0 5      R                  U5      nU R                  XUS9$ )Ndtypesbroadcastablesr/   getr4   )r    r(   r"   r)   bcs        r   _print_SymbolTheanoPrinter._print_Symbol   sO    

8R(,,Q/ZZ("-11!4""1"DDr   c                   [        [        U5      5      S-   [        UR                  S   5      -   nUR                  S0 5      R                  U5      nUR                  S0 5      R                  U5      nU R	                  XXES9$ )N_r   r7   r8   r0   )strr'   r!   r:   r4   )r    r(   r"   r&   r)   r;   s         r   _print_AppliedUndef!TheanoPrinter._print_AppliedUndef   sr    47|c!Cq	N2

8R(,,Q/ZZ("-11!4""1u"OOr   c                    [         [        U5         nUR                   Vs/ s H  o@R                  " U40 UD6PM     nnU" U6 $ s  snf N)mappingr'   r!   _print)r    exprr"   opargchildrens         r   _print_BasicTheanoPrinter._print_Basic   sD    T$Z :>))D)3KK.v.)D8} Es   Ac                4    [        UR                  5       5      $ rD   )floatevalf)r    nr"   s      r   _print_NumberTheanoPrinter._print_Number   s    QWWYr   c                d    UR                  S0 5      R                  U5      nU R                  XSS9$ )Nr7   NNr/   r9   )r    Xr"   r)   s       r   _print_MatrixSymbol!TheanoPrinter._print_MatrixSymbol   s3    

8R(,,Q/""1"NNr   c                   [        [        S5      (       d  [        S5      e[        R                  UR	                  5        VVs/ s H&  nU Vs/ s H  o@R
                  " U40 UD6PM     snPM(     snn5      $ s  snf s  snnf )N
stacklistsz>Matrix translation not yet supported in this version of Theano)hasattrr   NotImplementedErrorrY   tolistrF   )r    rU   r"   LrI   s        r   _print_DenseMatrix TheanoPrinter._print_DenseMatrix   sx    r<((%OQ Q }}XXZ
 4551C[[''15
  	5
s   
A=
A8)A=
8A=
c                    UR                    Vs/ s H  o0R                  " U40 UD6PM     nnUS   nUSS   H  n[        R                  XV5      nM     U$ s  snf r   )r!   rF   r   dot)r    rG   r"   rI   rJ   resultchilds          r   _print_MatMulTheanoPrinter._print_MatMul   sX    :>))D)3KK.v.)D!ab\EVVF*F "	 Es   Ac                   UR                    Vs/ s H  o0R                  " U40 UD6PM     nnSn[        US   [        5      (       a8  US   S:  a/  [	        US   5       H  n[
        R                  XTS   5      nM     U$ [        S5      es  snf )Nr   r   z^Only non-negative integer
           powers of matrices can be handled by Theano at the moment)r!   rF   
isinstanceintranger   ra   r[   )r    rG   r"   rI   rJ   rb   is          r   _print_MatPowTheanoPrinter._print_MatPow   s    :>))D)3KK.v.)Dhqk3''HQK!O8A;'4 (
  & 'H I I Es   B
c                    U R                   " UR                  40 UD6nU R                   " [        UR                  6 40 UD6nU R                   " [        UR                  6 40 UD6nX4U4   $ rD   )rF   parentslicerowslicecolslice)r    rG   r"   rn   rp   rq   s         r   _print_MatrixSlice TheanoPrinter._print_MatrixSlice   s_    T[[3F3;;udmm4??;;udmm4??())r   c                x   UR                   R                  u  p4[        U5       VVs/ s H>  n[        U5       Vs/ s H$  nU R                  " UR                   XV4   40 UD6PM&     snPM@     nnn[        R
                  " S/U Vs/ s H  n[        R
                  " S/UQ76 PM     snQ76 $ s  snf s  snnf s  snf r   )blocksshaperi   rF   r   join)	r    rG   r"   nrowsncolsrcru   rows	            r   _print_BlockMatrix TheanoPrinter._print_BlockMatrix   s    {{(( "'u/!-A "'u/!-A ;;t{{140;F;!-/!- 	 / wwq@?BGGA,,?@@/ / @s   B1+B,%B1!B7
,B1c           
         [        UR                  UR                  UR                  4 Vs/ s H7  n[	        U[
        R                  5      (       a  U R                  " U40 UD6OUPM9     sn6 $ s  snf rD   )ro   startstopsteprg   sympyBasicrF   )r    rG   r"   rj   s       r   _print_sliceTheanoPrinter._print_slice   sp    "&**dii!CE!CA &a55 {{1//;<=!CE F 	F Es   >A-c                "    [         R                  $ rD   )mathpir    rG   r"   s      r   	_print_PiTheanoPrinter._print_Pi   s    wwr   c                ,    [         R                  S5      $ )Nr   )tsexpr   s      r   _print_Exp1TheanoPrinter._print_Exp1   s    vvayr   c                   SS K nUR                  S   R                  u  pEU R                  " U40 UD6nU R                  " U40 UD6n[        UR                  5      S:X  a   [        R                  XgUR                  5      $ U R                  " [        R                  " UR                  SS  6 40 UD6n[        R                  XgU5      $ r   )	numpyr!   rF   lenr   switchnanr   	Piecewise)	r    rG   r"   npecondp_condp_ep_remainings	            r   _print_PiecewiseTheanoPrinter._print_Piecewise   s    ))A,## T,V,kk!&v& tyy>Q99V"&&11 kk%//499QR="ALVLyyk22r   c                    [         R                  U R                  " UR                  40 UD6U R                  " UR                  40 UD65      $ rD   )r   true_divrF   pqr   s      r   _print_RationalTheanoPrinter._print_Rational   s<    {{4;;tvv88;;tvv88: 	:r   c                    UR                   $ rD   )r   r   s      r   _print_IntegerTheanoPrinter._print_Integer  s    vvr   c                p    U R                   " [        R                  " UR                  S   S-   5      40 UD6$ r   )rF   r   gammar!   r   s      r   _print_factorialTheanoPrinter._print_factorial  s,    {{5;;tyy|a'78CFCCr   c                    U R                   " UR                  40 UD6nUR                   H?  nU R                   " U40 UD6n[        R	                  X4[        R                  U5      5      nMA     U$ rD   )rF   rG   	variablesr   Rop	ones_like)r    derivr"   rvvars        r   _print_DerivativeTheanoPrinter._print_Derivative	  sZ    [[.v.??C++c,V,Cc!23B # 	r   c                    U$ rD   r   )r    rG   s     r   emptyPrinterTheanoPrinter.emptyPrinter  s    r   c                6    Uc  0 nUc  0 nU R                  XUS9$ )a"  Convert a SymPy expression to a Theano graph variable.

The ``dtypes`` and ``broadcastables`` arguments are used to specify the
data type, dimension, and broadcasting behavior of the Theano variables
corresponding to the free symbols in ``expr``. Each is a mapping from
SymPy symbols to the value of the corresponding argument to
``theano.tensor.Tensor``.

See the corresponding `documentation page`__ for more information on
broadcasting in Theano.

.. __: http://deeplearning.net/software/theano/tutorial/broadcasting.html

Parameters
==========

expr : sympy.core.expr.Expr
    SymPy expression to print.

dtypes : dict
    Mapping from SymPy symbols to Theano datatypes to use when creating
    new Theano variables for those symbols. Corresponds to the ``dtype``
    argument to ``theano.tensor.Tensor``. Defaults to ``'floatX'``
    for symbols not included in the mapping.

broadcastables : dict
    Mapping from SymPy symbols to the value of the ``broadcastable``
    argument to ``theano.tensor.Tensor`` to use when creating Theano
    variables for those symbols. Defaults to the empty tuple for symbols
    not included in the mapping (resulting in a scalar).

Returns
=======

theano.gof.graph.Variable
    A variable corresponding to the expression's value in a Theano
    symbolic expression graph.

)r7   r8   )rF   )r    rG   r7   r8   s       r   doprintTheanoPrinter.doprint  s-    P >F!N{{4~{NNr   )r   NNNrT   )!__name__
__module____qualname____firstlineno____doc__printmethodr   r+   r4   r<   rA   rK   rQ   rV   r^   _print_ImmutableMatrix_print_ImmutableDenseMatrixrd   rk   rr   r}   r   r   r   r   r   r   r   r   r   r   __static_attributes____classcell__)r#   s   @r   r   r   U   s    4 K*=$.E
P
 O <NM8	*AF
3":D-O -Or   r   zdict[Any, Any]global_cachec                    [        SSSS9  [        (       d  [        S5      eUc  [        n[	        U0 S9R
                  " U 40 UD6$ )a  
Convert a SymPy expression into a Theano graph variable.

.. deprecated:: 1.8

  ``sympy.printing.theanocode`` is deprecated. Theano has been renamed to
  Aesara. Use ``sympy.printing.aesaracode`` instead. See
  :ref:`theanocode-deprecated` for more information.

Parameters
==========

expr : sympy.core.expr.Expr
    SymPy expression object to convert.

cache : dict
    Cached Theano variables (see :class:`TheanoPrinter.cache
    <TheanoPrinter>`). Defaults to the module-level global cache.

dtypes : dict
    Passed to :meth:`.TheanoPrinter.doprint`.

broadcastables : dict
    Passed to :meth:`.TheanoPrinter.doprint`.

Returns
=======

theano.gof.graph.Variable
    A variable corresponding to the expression's value in a Theano symbolic
    expression graph.

z
        sympy.printing.theanocode is deprecated. Theano has been renamed to
        Aesara. Use sympy.printing.aesaracode instead.1.8theanocode-deprecateddeprecated_since_versionactive_deprecations_targetz"theano is required for theano_code)r   settings)r
   r   ImportErrorr   r   r   )rG   r   r"   s      r   theano_coder   F  sT    D 	: "'68 6>??}ur2::4J6JJr   c           	         Ub  [         R                  U SU-  5      $ UbJ  [        UR                  5       5      nUR	                  5        VVs0 s H  u  pVUSU-  SXF-
  -  -   _M     snn$ Ub  U$ 0 $ s  snnf )a  
Get value of ``broadcastables`` argument to :func:`.theano_code` from
keyword arguments to :func:`.theano_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:`.TheanoPrinter.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)dictfromkeysmaxvaluesitems)inputsdimdimsr8   maxdimr(   ds          r   dim_handlingr   x  s    > }}VX^44T[[]# 


$ x!|g444$
 	

 !I
s   A1)r   )modulesr   r   r8   c                 ^^ [        SSSS9  [        (       d  [        S5      eUR                  S0 5      nUR                  S0 5      n[	        XXES9n[        [        XxUS	9n	[        [        X5      5      n
[        [        X5      5      nU Vs/ s H9  n[        U[        R                  5      (       a  UO[        R                  U5      PM;     nn[        U5      S
:X  a  US   n[        R                  " X40 UD6mTR                   Vs/ s H%  n[        UR                   R"                  5      S:H  PM'     snmU(       a  [%        T5      (       d	  TTl        T$ UU4S jnTUl        TR*                  Ul        TUl        U$ s  snf s  snf )a>  
Create a Theano function from SymPy expressions.

.. deprecated:: 1.8

  ``sympy.printing.theanocode`` is deprecated. Theano has been renamed to
  Aesara. Use ``sympy.printing.aesaracode`` instead. See
  :ref:`theanocode-deprecated` for more information.

The inputs and outputs are converted to Theano variables using
:func:`.theano_code` and then passed to ``theano.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 Theano function object.

cache : dict
    Cached Theano variables (see :class:`TheanoPrinter.cache
    <TheanoPrinter>`). Defaults to the module-level global cache.

dtypes : dict
    Passed to :meth:`.TheanoPrinter.doprint`.

broadcastables : dict
    Passed to :meth:`.TheanoPrinter.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.
    ``theano_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
    ``theano.compile.function_module.Function`` or a Python wrapper
    function around one. In both cases, the returned value will have a
    ``theano_function`` attribute which points to the return value of
    ``theano.function``.

Examples
========

>>> from sympy.abc import x, y, z
>>> from sympy.printing.theanocode import theano_function

A simple function with one input and one output:

>>> f1 = theano_function([x], [x**2 - 1], scalar=True)
>>> f1(3)
8.0

A function with multiple inputs and one output:

>>> f2 = theano_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 = theano_function([x, y], [x**2 + y**2, x**2 - y**2], scalar=True)
>>> f3(2, 3)
[13.0, -5.0]

See also
========

dim_handling

zz
        sympy.printing.theanocode is deprecated. Theano has been renamed to Aesara. Use sympy.printing.aesaracode insteadr   r   r   z&theano is required for theano_functionr   r7   r   )r   r7   r8   r   r   c                    > T" U 6 n[        U5      (       a/  [        U5       VVs/ s H  u  p#TU   (       a  US   OUPM     snn$ US   $ s  snnf )Nr   )r   	enumerate)r!   outrj   ofuncis_0ds       r   wrapper theano_function.<locals>.wrapper/  sR    Dk s9B3HU1XAbE1,HHr7N Is   A)r
   r   r   r   r   r   r   listmaprg   Variabler   as_tensor_variabler   functionoutputsvariabler*   anyr   __wrapped__r   )r   r   scalarr   r   r8   r"   r   r7   codetinputstoutputsoutputr   r   r   r   s                  @@r   r   r     sn   @ 	}!&6	8 6BCC JJw#EZZ"%F!dN
 ;e"02D3t$%GC&'H pxxowek*VV__==2CXCXY_C``owHx
8}A; ??777D9=FAS))*a/FE U# GllGO"GN9 y Gs   A E?,FrD   r   r   )sr   
__future__r   r   typingr   sympy.externalr   sympy.printing.printerr   sympy.utilities.iterablesr   r   	functoolsr   sympy.utilities.decoratorr	   sympy.utilities.exceptionsr
   __doctest_requires__r   r   r   r1   r   theano.sandboxr   tlinalgAddaddMulmulAbsabs_signsgnceilingceilfloorlogr   sqrtcosacosarccossinasinarcsintanatanarctanatan2arctan2coshacosharccoshsinhasinharcsinhtanhatanharctanhrerealimimagrI   angleerfr   loggammagammalnPowpowEqeqStrictGreaterThangtStrictLessThanltLessThanleGreaterThangeAndand_Oror_MaxmaximumMinminimum	conjugateconjcorenumbersImaginaryUnitMatAddElemwiseHadamardProductTracetraceDeterminantdetInversematrix_inverse	Transpose
DimShufflerE   r   r   __annotations__r   r   r   r   r   r   <module>rP     s:   #   ( * 1   8 @ -xj9  
x	  
	B	B00IIrvv0IIrvv0 IIrww0 JJ	0
 MM2770 KK0 IIrvv0 IIrvv0 JJ0 IIrvv0 JJ		0 IIrvv0 JJ		0 IIrvv0 JJ		0  KK!0" JJ#0$ KK%0& JJ'0( KK)0* JJ+0, KK-0. HHbgg/00 HHbgg102 IIrxx304 IIrvv506 KK708 NNBJJ90: IIrvv;0< HHbee=0> ##RUU?0@   "%%A0B NNBEEC0D ruuE0F IIrwwHHbffIIrzzIIrzzOORWWJJ,,.DLL"++bff-!!2;;rvv#6KKMM711OOR]]>Aq6B_0GfkOG kO\  "n !/Kd,^ K(StDS )Sr   