o
    ey                     @   sH   d Z ddlZddlmZ g dZedddd	d
Zdd Zd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                 C   sH   ddl }t| tjr"|r|j| S |jj| jdgt| j	 d S | S )zDConvert a numpy array to ``theano.tensor.TensorType`` instance.
    r   NF)dtypeZbroadcastable)
theano
isinstancenpZndarraytensorconstantZ
TensorTyper   lenshape)arrayr   r	    r   JD:\Projects\ConvertPro\env\Lib\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 )
z>Build 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   r
   r   Z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	   Z	_contractfunction)r   exprZin_varsZout_varZ	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   3   s   ( r   )Zconst_arraysr"   Znew_opsZnew_contraction_listr   r   r   r   -   s   r   )F)	__doc__numpyr   Zsharingr   __all__r   r   r   r   r   r   r   <module>   s    