
    i                     4    S r SSKrSSKJr  SS/rS	S jrS rg)
z1
Determines if a contraction can use BLAS or not
    N   )helperscan_blastensor_blasc                    [        U 5      S:w  a  gU u  pE[        XE-   5       HR  nUR                  U5      UR                  U5      pUS:  d  US:  d  Xx-   S:  a    gXx-   S-
  [        Xa;   5      :X  d  MR    g   Ub;  U H5  nUS   UR	                  U5         US   UR	                  U5         :w  d  M5    g   [        U5      S:X  a  gU  V	s/ s H  n	[        U	5      PM     n
n	U
S   U-
  nU
S   U-
  n[        U5      nU S   U S   :X  a  gU
S   U
S   :X  a  gXM* S USU :X  a  g	USU X]* S :X  a  g	XM* S X]* S :X  a  g	USU USU :X  a  g	[        U5      S:X  d  [        U5      S:X  a  g
gs  sn	f )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
   Fr   Nr   zOUTER/EINSUMDOTz
DOT/EINSUMGEMMzGEMV/EINSUMTDOT)lensetcountintfind)inputsresultidx_removedshapes
input_leftinput_rightcnlnrxsets	keep_left
keep_rightrss                 O/var/www/html/banglarbhumi/venv/lib/python3.13/site-packages/opt_einsum/blas.pyr   r      s   V 6{a$J)*!!!$k&7&7&:BFQBGaK
 7Q;#ak** + Aay+,q	+:J:J1:M0NN  ;1 ##FqCFFD#Q+%Ia;&J	[	B ayF1I 
aDG	 #$;s++ 
CRK-	- 
CD	[.	. 
CRK,	, i.A
3z?a#7 G $s   
E*c                    ^ [        U5      n[        U5      U-
  n[        U5      U-
  n0 m[        XR                  5       H
  u  pU	TU'   M     [        X2R                  5       H
  u  pU	TU'   M     [        U5      n
[        R
                  " UT5      n[        R
                  " UT5      n[        R
                  " UT5      nX-   nU H  n	UR                  U	S5      nM     X:X  a5  [        R                  " U R                  5       UR                  5       5      nGOX* S USU
 :X  a7  [        R                  " U R                  X5      UR                  X5      5      nGO=USU
 X:* S :X  aJ  [        R                  " U R                  X5      R                  UR                  X5      R                  5      nOX* S X:* S :X  a@  [        R                  " U R                  X5      UR                  X5      R                  5      nOUSU
 USU
 :X  a@  [        R                  " U R                  X5      R                  UR                  X5      5      nOOSu  nnU H-  n	UUR                  U	5      4-  nUUR                  U	5      4-  nM/     [        R                  " XUU4S9n[        U4S jU 5       5      nUR                  U:w  a-  [        U5      S:  a  UUl        O[        R                  " U5      nX:w  a  [        R                   " US-   U-   U5      nU$ )a  
Computes the dot product between two tensors, attempts to use np.dot and
then tensordot if that fails.

Parameters
----------
view_left : array_like
    The left hand view
input_left : str
    Indices of the left view
view_right : array_like
    The right hand view
input_right : str
    Indices of the right view
index_result : str
    The resulting indices
idx_removed : set
    Indices removed in the contraction

Returns
-------
type : array
    The resulting BLAS operation.

Notes
-----
Interior function for tensor BLAS.

This function will attempt to use `np.dot` by the iterating through the
four possible transpose cases. If this fails all inner and matrix-vector
operations will be handed off to einsum while all matrix-matrix operations will
first copy the data, perform the DGEMM, and then copy the data to the required
order.

Examples
--------

>>> a = np.random.rand(4, 4)
>>> b = np.random.rand(4, 4)
>>> tmp = tensor_blas(a, 'ij', b, 'jk', 'ik', set('j'))
>>> np.allclose(tmp, np.dot(a, b))

 N) r"   )axesc              3   .   >#    U  H
  nTU   v   M     g 7fNr"   ).0r   dimension_dicts     r   	<genexpr>tensor_blas.<locals>.<genexpr>   s     BMq*Ms   r   z->)r   zipshaper   r   compute_size_by_dictreplacenpdotravelreshapeTr   	tensordottuplesqueezeeinsum)	view_leftr   
view_rightr   index_resultr   r   r   isr   dim_left	dim_rightdim_removedtensor_resultnew_viewleft_pos	right_postensor_shaper'   s                      @r   r   r   {   s   Z k"KJ+-I[!K/J NJ0q 1K!1!12q 3" 
[	B++I~FH,,ZHI..{NKK,M%--a4 
  66)//+Z-=-=-?@ 
CD	["-	-66)++HBJDVDVWbDno 
CRK-	-66)++KBDDjFXFXYbFpFrFrs 
CD	[.	.66)++HBJDVDVW`DnDpDpq 
CRK,	,66)++KBDDjFXFXYdFpq
 %)A+..H+**1-00I  <<	Xy<QR BMBBL~~%}!)HNzz(+H$99]T1L@(KO    r%   )__doc__numpyr.   r!   r   __all__r   r   r"   rD   r   <module>rH      s)     }
%l^xrD   