o
    °2úh¬  ã                   @   sp   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d„ZdS )z0Determines if a contraction can use BLAS or not.é    )ÚListÚSequenceÚTupleÚUnion)ÚArrayIndexTypeÚcan_blasNÚinputsÚresultÚidx_removedÚshapesÚreturnc                 C   sº  t | ƒdkrdS | \}}t|| ƒD ]-}| |¡| |¡}}|dks-|dks-|| dkr0 dS || d t||v ƒkr? dS q|dur^|D ]}|d | |¡ |d | |¡ kr] dS qFt |ƒdkrfdS dd„ | D ƒ}	|	d | }
|	d | }t |ƒ}| d | d kr‡d	S |	d |	d kr‘d
S || d… |d|… kr dS |d|… || d… kr¯dS || d… || d… kr¿dS |d|… |d|… krÍdS t |
ƒdksÙt |ƒdkrÛdS dS )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/EINSUMc                 S   s   g | ]}t |ƒ‘qS © )Úset)Ú.0Úxr   r   úJ/var/www/html/chatgem/venv/lib/python3.10/site-packages/opt_einsum/blas.pyÚ
<listcomp>W   s    zcan_blas.<locals>.<listcomp>ÚDOTz
DOT/EINSUMÚGEMMzGEMV/EINSUMÚTDOT)Úlenr   ÚcountÚintÚfind)r   r	   r
   r   Ú
input_leftÚinput_rightÚcÚnlÚnrÚsetsÚ	keep_leftÚ
keep_rightÚrsr   r   r   r   
   sH   /ÿ$ÿ)N)Ú__doc__Útypingr   r   r   r   Úopt_einsum.typingr   Ú__all__Ústrr   Úboolr   r   r   r   r   Ú<module>   s     üÿþýü
û