
    ,Vh                     T    d Z ddlmZ ddlmZ g dZ ed      dd       Zd Zd	 Zy
)zKRequired functions for optimized contractions of numpy arrays using theano.    )has_array_interface)to_backend_cache_wrap)	to_theanobuild_expressionevaluate_constantsT)	constantsc                     ddl }t        |       r`|r|j                  j                  |       S  |j                  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      J/home/dcms/DCMS/lib/python3.12/site-packages/opt_einsum/backends/theano.pyr   r   	   sc     5!==))%00dv}}''ekk%SVW\WbWbScIc'dffL    c                   	 ddl 	| D cg c]  }t        |       }}|j                  |d      }|D cg c]%  }t        |	j                  j
                        r$|' }}	j                  ||      	fd}|S c c}w c c}w )z9Build a theano function based on ``arrays`` and ``expr``.r   Nr   )backendc            	      v     | D cg c]%  }t        |j                  j                        r$|' c} S c c}w )N)
isinstancer   TensorConstant)arraysxgraphr   s     r   theano_contractz)build_expression.<locals>.theano_contract"   s/    &\Q
1fmm>Z>Z0[q\]]\s   %66)r   r   	_contractr   r   r   function)
r   exprr   in_varsout_varr   	graph_insr   r   r   s
           @@r   r   r      s    -34Ey4G4nnWhn7G $Wq:a9U9U+VWIWOOIw/E^  5 Xs   A<%BBc                     | D cg c]  }t        |d       } } || ddd\  }}|D cg c]!  }|d nt        |j                         d      # }}||fS c c}w c c}w )NT)r   r   )r   r   )r   eval)const_arraysr    r   new_opsnew_contraction_lists        r   r   r   (   sv    9EFAIa$/FLF$(,]a$b!G! SZZQqyti4&HHZGZ((( G [s
   A&AN)F)	__doc__opt_einsum.helpersr   opt_einsum.sharingr   __all__r   r   r    r   r   <module>r.      s6    Q 2 4
A &
 '
")r   