
    i                     &    S r SSKrSSKrSSKrS rg)zN
Functions for performing contractions with array elements which are objects.
    Nc                 L  ^^^^^^^ U R                  S5      u  nmUR                  S5      m0 m[        TT5       H(  u  p4[        X4R                  5       H
  u  pVUTU'   M     M*     [        U4S jT 5       5      n[        R
                  " U[        S9n[        U4S jT 5       5      m[        U4S jT 5       5      m[        R                  " U6  HN  n	[        [        TU	5      5      mUUUUU4S jn
[        R                  " [        R                  U
" 5       5      X'   MP     U$ )a  A ``einsum`` implementation for ``numpy`` arrays with object dtype.
The loop is performed in python, meaning the objects themselves need
only to implement ``__mul__`` and ``__add__`` for the contraction to be
computed. This may be useful when, for example, computing expressions of
tensors with symbolic elements, but note it will be very slow when compared
to ``numpy.einsum`` and numeric data types!

Parameters
----------
eq : str
    The contraction string, should specify output.
arrays : sequence of arrays
    These can be any indexable arrays as long as addition and
    multiplication is defined on the elements.

Returns
-------
out : numpy.ndarray
    The output tensor, with ``dtype=object``.
z->,c              3   .   >#    U  H
  nTU   v   M     g 7fN .0ksizess     a/var/www/html/banglarbhumi/venv/lib/python3.13/site-packages/opt_einsum/backends/object_arrays.py	<genexpr> object_einsum.<locals>.<genexpr>)   s     .v!U1Xv   )dtypec              3   6   >#    U  H  oT;  d  M
  Uv   M     g 7fr   r   )r	   r
   outputs     r   r   r   ,   s     6Uvo!!Us   		c              3   .   >#    U  H
  nTU   v   M     g 7fr   r   r   s     r   r   r   -   s     /AuQxr   c            	   3     >#    [         R                  " T6  Hm  n TR                  [        [	        TU 5      5      5        U4S jT 5       nS [	        TU5       5       n[
        R                  " [        R                  U5      v   Mo     g 7f)Nc              3   N   >#    U  H  n[        U4S  jU 5       5      v   M     g7f)c              3   .   >#    U  H
  nTU   v   M     g 7fr   r   )r	   r
   coords     r   r   Aobject_einsum.<locals>.gen_inner_sum.<locals>.<genexpr>.<genexpr>6   s     51eAhr   N)tuple)r	   termr   s     r   r   7object_einsum.<locals>.gen_inner_sum.<locals>.<genexpr>6   s     I&$5555&s   "%c              3   .   #    U  H  u  pX   v   M     g 7fr   r   )r	   arraylocs      r   r   r   7   s     K9J:5EJ9Js   )	npndindexupdatedictzip	functoolsreduceoperatormul)coo_ilocselementsarraysr   inner
inner_sizeinputss      r   gen_inner_sum$object_einsum.<locals>.gen_inner_sum3   sc     Z0T#eU"345I&IKVT9JK&&x||X>>	 1s   BB	)splitr#   shaper   r   emptyobjectr    r"   r$   r%   r&   add)eqr+   lhsr   r   r
   dout_sizeoutcoo_or/   r   r,   r-   r.   r   r   s    `         @@@@@@r   object_einsumr<   
   s    . ((4.KCYYs^FE66*kk*DAE!H + + .v..H
((86
*C6U66E///JX&S'(	? 	? %%hllMOD
 ' J    )__doc__numpyr   r$   r&   r<   r   r=   r   <module>r@      s      2r=   