o
    2h                     @   sL   d Z ddlmZ ddlmZ g dZeddddd	Zd
d Zd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                 C   sD   ddl }t| r |r|j| S |jj| jdgt| j d S | S )z?Convert a numpy array to ``theano.tensor.TensorType`` instance.r   NF)dtypebroadcastable)theanor   tensorconstant
TensorTyper   lenshape)arrayr   r
    r   U/var/www/html/chatgem/venv/lib/python3.10/site-packages/opt_einsum/backends/theano.pyr   	   s    r   c                    sT   ddl dd | D }|j|dd}fdd|D }||  fdd	}|S )
z9Build a theano function based on ``arrays`` and ``expr``.r   Nc                 S   s   g | ]}t |qS r   r   ).0r   r   r   r   
<listcomp>   s    z$build_expression.<locals>.<listcomp>r
   )backendc                       g | ]}t | jjs|qS r   
isinstancer   TensorConstantr   xr
   r   r   r          c                     s    fdd| D  S )Nc                    r   r   r   r   r   r   r   r   #   r   z=build_expression.<locals>.theano_contract.<locals>.<listcomp>r   )arraysgraphr
   r   r   theano_contract"   s   z)build_expression.<locals>.theano_contract)r
   	_contractfunction)r   exprin_varsout_var	graph_insr"   r   r    r   r      s   r   c                 C   s8   dd | D } || ddd\}}dd |D }||fS )Nc                 S   s   g | ]}t |d dqS )Tr   r   r   r   r   r   r   *   s    z&evaluate_constants.<locals>.<listcomp>r
   T)r   r   c                 S   s(   g | ]}|d u r
d nt | ddqS )NTr)   )r   evalr   r   r   r   r   .   s   ( r   )const_arraysr%   new_opsnew_contraction_listr   r   r   r   (   s   r   N)F)	__doc__opt_einsum.helpersr   opt_einsum.sharingr   __all__r   r   r   r   r   r   r   <module>   s    