
    Opfy                     ^    d Z ddlZddlmZ g dZ ed          dd	            Zd
 Zd ZdS )zM
Required functions for optimized contractions of numpy arrays using theano.
    N   )to_backend_cache_wrap)	to_theanobuild_expressionevaluate_constantsT)	constantsFc                     ddl }t          | t          j                  r[|r|j                            |           S  |j                            | j        dgt          | j	                  z                        S | S )zDConvert a numpy array to ``theano.tensor.TensorType`` instance.
    r   NF)dtypebroadcastable)
theano
isinstancenpndarraytensorconstant
TensorTyper
   lenshape)arrayr   r   s      Z/var/www/html/nettyfy-visnx/env/lib/python3.11/site-packages/opt_einsum/backends/theano.pyr   r      s~     MMM%$$ g 	1=))%000dv}''ek%SVW\WbScScIc'ddfffL    c                     ddl d | D             }|                    |d          }fd|D             }                    ||          fd}|S )z>Build a theano function based on ``arrays`` and ``expr``.
    r   Nc                 ,    g | ]}t          |          S  r   ).0r   s     r   
<listcomp>z$build_expression.<locals>.<listcomp>    s     444Ey444r   r   )backendc                 H    g | ]}t          |j        j                  |S r   r   r   TensorConstantr   xr   s     r   r   z$build_expression.<locals>.<listcomp>$   s-    WWWq:a9U+V+VWWWWr   c                  &     fd| D              S )Nc                 H    g | ]}t          |j        j                  |S r   r    r"   s     r   r   z=build_expression.<locals>.theano_contract.<locals>.<listcomp>(   s-    \\\Q
1fm>Z0[0[\q\\\r   r   )arraysgraphr   s    r   theano_contractz)build_expression.<locals>.theano_contract'   s%    u\\\\&\\\]]r   )r   	_contractfunction)r&   exprin_varsout_var	graph_insr(   r'   r   s         @@r   r   r      s     MMM44V444GnnWhn77G XWWWGWWWIOOIw//E^ ^ ^ ^ ^ ^ r   c                 R    d | D             }  || ddd\  }}d |D             }||fS )Nc                 0    g | ]}t          |d           S )Tr   r   r   r#   s     r   r   z&evaluate_constants.<locals>.<listcomp>/   s%    FFFAIa$///FFFr   r   T)r   r   c                 \    g | ])}|d n"t          |                                d          *S )NTr1   )r   evalr2   s     r   r   z&evaluate_constants.<locals>.<listcomp>3   s5    ZZZQqytti4&H&H&HZZZr   r   )const_arraysr+   new_opsnew_contraction_lists       r   r   r   -   sU    FFFFFL$(D,]a$b$b$b!G! [ZRYZZZG(((r   )F)	__doc__numpyr   sharingr   __all__r   r   r   r   r   r   <module>r<      s         + + + + + +
A
A
A &&&   '&  $) ) ) ) )r   