
    OpfD                        d Z ddlZddl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ZddZej        ej        ej        ej        ej        ej        dZddZi Zd Zi Z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 Z dS )z
Handles dispatching array operations to the correct backend library, as well
as converting arrays to backend formats and then potentially storing them as
constants.
    N   )object_arrays)cupy)jax)
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   autogradmarsc                 
   	 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)funcbackenddefaultlib	error_msgs        \/var/www/html/nettyfy-visnx/env/lib/python3.11/site-packages/opt_einsum/backends/dispatch.py_import_funcr!      s    >%hll7G&D&DEE%,_wsD!!!'#tW:U:UU > > >[	 Y--gt<<===	>s   AA 0B))	tensordotnumpy)	transposer#   )einsumr#   )r"   object)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.
    )_cached_funcsKeyErrorr!   )r   r   r   fns       r    r
   r
   <   sY    T7]++   $11')dGm$			s    )==c                     	 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)zHCheck if ``{backend}.einsum`` exists, cache result for performance.
    r%   TF)_has_einsumr)   r
   r   r   s    r    r   r   L   s    	$7## $ $ $	)Xw'''#'K   	) 	) 	)#(K   	) 7####$/    
A5AA	AAAAc                     	 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)zKCheck if ``{backend}.tensordot`` exists, cache result for performance.
    r"   TF)_has_tensordotr)   r
   r   r-   s    r    r   r   ^   s    	'g&& ' ' '	,['***&*N7## 	, 	, 	,&+N7###	, g&&&&'r.   )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_BACKENDSr3   s      r    r   r      s      (666r6   c                 8    |                                  t          v S )z$Checks if the backend is known.
    )lowerr2   r-   s    r    r   r      s     ==??...r6   )N)r#   N)!__doc__r   r#    r   r   _cupyr   _jaxr   _tensorflowr   _theanor	   _torch__all__r   r!   r"   r$   r%   object_einsumr(   r
   r,   r   r0   r   r   r2   r   r8   r    r6   r    <module>rE      s                           ' ' ' ' ' '            
n
n
n (  > > > >& "O!O"_"_'5 	 	 	 	 $ $ $ ' ' '$ .&"$    0($&"  3 3 37 7 7/ / / / /r6   