
    Sh              	       ~   U d Z ddlZddlmZmZmZ ddlmZ ddlm	Z
 ddlmZ ddlmZ ddlmZ dd	lmZ g d
ZddddddddZd(dedededefdZdej        iZeeeef         ef         ed<   	 ddlZej        ed<   ej        ed<   ej        ed<   ej        ed<   ej        ed<   n# e$ r Y nw xY wd)dedededefdZi Z eee!f         ed <   dede!fd!Z"i Z#eee!f         ed"<   dede!fd#Z$ej%        ej%        ej%        ej%        e
j%        d$Z&ej'        ej'        ej'        ej'        e
j'        d$Z(d% Z%d& Z'dede!fd'Z)dS )*zHandles dispatching array operations to the correct backend library, as well
as converting arrays to backend formats and then potentially storing them as
constants.
    N)AnyDictTuple)cupy)jax)object_arrays)
tensorflow)theano)torch)get_func
has_einsumhas_tensordotbuild_expressionevaluate_constantshas_backendz
dask.arrayztheano.tensorzopt_einsum.backends.torchz	jax.numpyzautograd.numpyzmars.tensor)daskr
   r   r   jaxlibautogradmarsfuncbackenddefaultreturnc                 
   	 t          j        t                              ||                    }|t	          ||           nt	          || |          S # t
          $ r& d}t          |                    ||                     w xY w)zTry and import ``{backend}.{func}``.
    If library is installed and func is found, return the func;
    otherwise if default is provided, return default;
    otherwise raise an error.
    Nz{} doesn't seem to provide the function {} - see https://optimized-einsum.readthedocs.io/en/latest/backends.html for details on which functions are required for which contractions.)	importlibimport_module_aliasesgetgetattrAttributeErrorformat)r   r   r   lib	error_msgs        b/var/www/html/movieo_spanner_bot/venv/lib/python3.11/site-packages/opt_einsum/backends/dispatch.py_import_funcr%   %   s    	>%hll7G&D&DEE%,_wsD!!!'#tW:U:UU > > >R 	
 Y--gt<<===>s   AA 0B)einsumobject_cached_funcs)	tensordotnumpy)	transposer*   )r&   r*   )r)   r'   )r+   r'   r*   c                     	 t           | |f         S # t          $ r" t          | ||          }|t           | |f<   |cY S w xY w)ziReturn ``{backend}.{func}``, e.g. ``numpy.einsum``,
    or a default func if provided. Cache result.
    )r(   KeyErrorr%   )r   r   r   fns       r$   r   r   J   sY    T7]++   $11')dGm$			s    )==_has_einsumc                     	 t           |          S # t          $ rF 	 t          d|            dt           | <   n# t          $ r dt           | <   Y nw xY wt           |          cY S w xY w)zCCheck if ``{backend}.einsum`` exists, cache result for performance.r&   TF)r/   r-   r   r    r   s    r$   r   r   Z   s    	$7## $ $ $	)Xw'''#'K   	) 	) 	)#(K   	) 7####$/    
A5AA	AAAA_has_tensordotc                     	 t           |          S # t          $ rF 	 t          d|            dt           | <   n# t          $ r dt           | <   Y nw xY wt           |          cY S w xY w)zFCheck if ``{backend}.tensordot`` exists, cache result for performance.r)   TF)r3   r-   r   r    r1   s    r$   r   r   k   s    	'g&& ' ' '	,['***&*N7## 	, 	, 	,&+N7###	, g&&&&'r2   )r	   r
   r   r   r   c                 .    t          |          ||          S )zxBuild an expression, based on ``expr`` and initial arrays ``arrays``,
    that evaluates using backend ``backend``.
    )CONVERT_BACKENDSr   arraysexprs      r$   r   r      s     G$VT222    c                 .    t          |          ||          S )zConvert constant arrays to the correct backend, and perform as much of
    the contraction of ``expr`` with these as possible.
    )EVAL_CONSTS_BACKENDSr7   s      r$   r   r      s      (666r:   c                 8    |                                  t          v S )zChecks if the backend is known.)lowerr6   r1   s    r$   r   r      s    ==??...r:   )N)r*   N)*__doc__r   typingr   r   r   opt_einsum.backendsr   _cupyr   _jaxr   r	   _tensorflowr
   _theanor   _torch__all__r   strr%   object_einsumr(   __annotations__r*   npr)   r+   r&   ModuleNotFoundErrorr   r/   boolr   r3   r   r   r6   r   r<   r    r:   r$   <module>rO      s    
     # # # # # # # # # # - - - - - - + + + + + + - - - - - - 9 9 9 9 9 9 1 1 1 1 1 1 / / / / / /   (  > >s >S >3 ># > > > >* -5-tE#s(OS()   
	,.LM(),.LM())+M%&-/\M)*-/\M)** 	 	 	D		 	3 	 	 	 	 	 	 	  "T#t)_ ! ! !$ $ $ $ $ $ #%S$Y $ $ $'3 '4 ' ' ' '" .&"$    0($&"  3 3 37 7 7/ / / / / / / /s   06B' 'B/.B/