
    Opf                     (    d Z ddlZddlZddlZd ZdS )zN
Functions for performing contractions with array elements which are objects.
    Nc                 x   |                      d          \  }|                     d          i t                    D ]%\  }}t          ||j                  D ]
\  }}||<   &t          fdD                       }t	          j        |t                    }t          fdD                       t          fdD                       t	          j        | D ]R}	t          t          |	                    fd}
t          j
        t          j         |
                      ||	<   S|S )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   (   K   | ]}|         V  d S N .0ksizess     a/var/www/html/nettyfy-visnx/env/lib/python3.11/site-packages/opt_einsum/backends/object_arrays.py	<genexpr>z object_einsum.<locals>.<genexpr>)   s'      ..!U1X......    )dtypec              3   $   K   | ]
}|v|V  d S r   r   )r	   r
   outputs     r   r   z object_einsum.<locals>.<genexpr>,   s'      66avoo!oooo66r   c              3   (   K   | ]}|         V  d S r   r   r   s     r   r   z object_einsum.<locals>.<genexpr>-   s'      //AuQx//////r   c            	   3      K   t          j         D ]{}                     t          t	          |                                fdD             }d t	          |          D             }t          j        t          j        |          V  |d S )Nc              3   N   K   | ]}t          fd |D                       V   dS )c              3   (   K   | ]}|         V  d S r   r   )r	   r
   coords     r   r   zAobject_einsum.<locals>.gen_inner_sum.<locals>.<genexpr>.<genexpr>6   s'      551eAh555555r   N)tuple)r	   termr   s     r   r   z7object_einsum.<locals>.gen_inner_sum.<locals>.<genexpr>6   s@      II$555555555IIIIIIr   c              3   ,   K   | ]\  }}||         V  d S r   r   )r	   arraylocs      r   r   z7object_einsum.<locals>.gen_inner_sum.<locals>.<genexpr>7   s*      KK:5#E#JKKKKKKr   )	npndindexupdatedictzip	functoolsreduceoperatormul)coo_ilocselementsarraysr   inner
inner_sizeinputss      r   gen_inner_sumz$object_einsum.<locals>.gen_inner_sum3   s      Z0 ? ?T#eU"3"344555IIII&IIIKKVT9J9JKKK&x|X>>>>>>	? ?r   )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_einsumr8   
   s}   . ((4..KCYYs^^FE66**  eek** 	 	DAqE!HH	 ....v.....H
(86
*
*
*C6666U66666E/////////JX& E ES''((	? 	? 	? 	? 	? 	? 	? 	? 	? %hlMMOODDE

Jr   )__doc__numpyr   r!   r#   r8   r   r   r   <module>r;      sK             2 2 2 2 2r   