
    ,Vh                     x    d Z ddlmZmZmZmZ ddlmZ dgZ	 ddee	   de	ded	eeee
      df   d
ee	ef   f
dZy)z0Determines if a contraction can use BLAS or not.    )ListSequenceTupleUnion)ArrayIndexTypecan_blasNinputsresultidx_removedshapesreturnc                    t        |       dk7  ry| \  }}t        ||z         D ]P  }|j                  |      |j                  |      }}|dkD  s|dkD  s||z   dkD  r y||z   dz
  t        ||v       k(  sP y |8|D ]3  }|d   |j	                  |         |d   |j	                  |         k7  s3 y t        |      dk(  ry| D 	cg c]  }	t        |	       }
}	|
d   |z
  }|
d   |z
  }t        |      }| d   | d   k(  ry|
d   |
d   k(  ry|| d |d| k(  ry	|d| || d k(  ry	|| d || d k(  ry	|d| |d| k(  ry	t        |      dk(  st        |      dk(  ry
yc c}	w )a  Checks if we can use a BLAS call.

    Parameters
    ----------
    inputs : list of str
        Specifies the subscripts for summation.
    result : str
        Resulting summation.
    idx_removed : set
        Indices that are removed in the summation
    shapes : sequence of tuple[int], optional
        If given, check also that none of the indices are broadcast dimensions.

    Returns:
    -------
    type : str or bool
        The type of BLAS call to be used or False if none.

    Notes:
    -----
    We assume several operations are not efficient such as a transposed
    DDOT, therefore 'ijk,jki->' should prefer einsum. These return the blas
    type appended with "/EINSUM" to differentiate when they can still be done
    with tensordot if required, e.g. when a backend has no einsum.

    Examples:
    --------
    >>> can_blas(['ij', 'jk'], 'ik', set('j'))
    'GEMM'

    >>> can_blas(['ijj', 'jk'], 'ik', set('j'))
    False

    >>> can_blas(['ab', 'cd'], 'abcd', set())
    'OUTER/EINSUM'

    >>> # looks like GEMM but actually 'j' is broadcast:
    >>> can_blas(['ij', 'jk'], 'ik', set('j'), shapes=[(4, 1), (5, 6)])
    False
       F   Nr   zOUTER/EINSUMDOTz
DOT/EINSUMGEMMzGEMV/EINSUMTDOT)lensetcountintfind)r	   r
   r   r   
input_leftinput_rightcnlnrxsets	keep_left
keep_rightrss                 ?/home/dcms/DCMS/lib/python3.12/site-packages/opt_einsum/blas.pyr   r   
   s   ^ 6{a$Jk)* 
!!!$k&7&7&:BFQBGaK
 7Q;#a6k**
  	Aay+,q	+:J:J1:M0NN	 ;1 ##qCF#D#Q+%Ia;&J	[	B ayF1I 
aDG	 2#$;s++ 
CRK-	- 
RCD	[".	. 
CRK,	, i.A
3z?a#7 G $s   E)N)__doc__typingr   r   r   r   opt_einsum.typingr   __all__strr   boolr        r#   <module>r,      sv    6 / / ,, 15	pIpp  p (5:&,-	p
 39pr+   