
    Sh                     b    d Z ddlmZ ddlmZ g dZ ed          dd            Zd	 Zd
 ZdS )zKRequired functions for optimized contractions of numpy arrays using theano.    )has_array_interface)to_backend_cache_wrap)	to_theanobuild_expressionevaluate_constantsT)	constantsFc                     ddl }t          |           r[|r|j                            |           S  |j                            | j        dgt          | j                  z                        S | S )z?Convert a numpy array to ``theano.tensor.TensorType`` instance.r   NF)dtypebroadcastable)theanor   tensorconstant
TensorTyper
   lenshape)arrayr   r   s      `/var/www/html/movieo_spanner_bot/venv/lib/python3.11/site-packages/opt_einsum/backends/theano.pyr   r   	   sz     MMM5!! 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 )z9Build 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   
isinstancer   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 )NTr/   )r   evalr0   s     r   r   z&evaluate_constants.<locals>.<listcomp>.   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   N)F)	__doc__opt_einsum.helpersr   opt_einsum.sharingr   __all__r   r   r   r   r   r   <module>r:      s    Q Q 2 2 2 2 2 2 4 4 4 4 4 4
A
A
A &&&
 
 
 '&
  ") ) ) ) )r   