Ë
    ÏÍ:jÊ  ã                   ó$   — d Z ddlZddlZd„ Zd„ Zy)z4Helpers for producing efficient wrappers of ufuncs.
é    Nc                 óz   — | j                  d«      d   }t        j                  d|«      }t        d„ |D «       «      S )z>Return tuple of num core dims per input from gufunc signature.z->r   z	\((.*?)\)c              3   óh   K  — | ]*  }|j                  «       sd n|j                  d«      dz   –— Œ, y­w)r   ú,é   N)ÚstripÚcount)Ú.0Úgs     úo/home/mcse/projects/srt_converter/srt-converter-venv/lib/python3.12/site-packages/scipy/special/_ufunc_tools.pyú	<genexpr>z$_parse_core_ndims.<locals>.<genexpr>   s*   è ø€ ÒJ¸a˜!Ÿ'™'œ)‘¨¯©°«¸Ñ)9Ó9ÑJùs   ‚02)ÚsplitÚreÚfindallÚtuple)Ú	signatureÚ	input_sigÚgroupss      r   Ú_parse_core_ndimsr      s6   € à—‘ Ó% aÑ(€IÜ�Z‰Z˜ iÓ0€FÜÑJÀ6ÔJÓJÐJó    c                 óì   ‡‡‡
— ‰j                   �t        ‰j                   «      nd‰j                  z  Š
ˆˆ
ˆfd„}dj                  |«      }d| › d|› d|› d�}d|i}t	        ||«       ||    }	||	_        |	S )	a7
  Helper to ensure optimal iteration order for ufuncs that use caching.

    This concerns internal caches which are only live over the course of one
    call to a ufunc to avoid repeated computations during the course of the
    loops. See the notes below for more information.

    Parameters
    ----------
    name : str
    arg_names : list[str]
        The function name and arg names are passed in so that the wrapper
        can be generated with the create name and argument names, improving
        documentation and autocomplete.
    docstring : str
    ufunc : numpy.ufunc
    cache_arg_indices : list[int]
       Arguments to ufunc which are used in the kernel to compute an output
       which is being cached for reuse when iterating over other arguments.

    Returns
    -------
    callable
        A wrapper for ufunc which transposes the axes of the inputs to ensure
        iteration precedes in such a way to allow the cache within the ufunc
        kernel to eliminate redundant computation.

    Notes
    -----
    There is a common pattern in ufunc kernels exemplified by the situation
    where some of the arguments are used to compute coeffients of an expansion
    that is taken over one or more of the other arguments. A classic example is
    Mathieu functions, which compute coefficients corresponding to the shape
    parameter q and order m which in principle could be reused for varying
    values of the parameter x.

    It had long been the case that the expensive computation of coefficients is
    repeated unnecessarily across values of x. It is possible to add a cache to
    the ufunc kernel which stores the expansion coefficients and only updates
    if the pointers into the q and m arrays advance during the course of the
    ufunc loops. Such a cache is instantiated each time a ufunc is called and
    only lives during the course of the loops that are carried out for that
    particular call.

    Whether such a cache actually helps depends on the order in which iteration
    occurs. Ideally, one would want q and m to advance most slowly and for the
    iterations over x for fixed q and m to be pushed to the inner most loops.
    This helper replaces each input array (and a pre-allocated output array)
    with a view where the axes which should vary most slowly are transposed to
    the ends and forces computation in C order. This ensures iteration proceeds
    in the optimal order.

    Note that because the pre-allocated output array used internally is C
    contiguous, the output will be C contiguous regardless of contiguity of
    the inputs.

    )r   c                  ód  •‡ ‡‡— ‰ D �cg c]  }t        j                  |«      ‘Œ c}Š t        ˆ ˆfd„‰D «       «      r ‰‰ Ž S t        ‰ «      D ��cg c],  \  }}‰|   dkD  r|j                  d ‰|     n|j                  ‘Œ. }}}t        j
                  |Ž }t        |«      }t        ‰ «      D ��cg c]M  \  }}‰|   dkD  r*t        j                  |||j                  ‰|    d  z   «      nt        j                  ||«      ‘ŒO c}}Šg }g }t        |«      D ]<  Št        ˆˆfd„‰D «       «      }|r|j                  ‰«       Œ,|j                  ‰«       Œ> ||z   }	g }
t        ‰«      D ]I  \  }}|	t        t        ||‰|   z   «      «      z   }|
j                  t        j                  ||¬«      «       ŒK t        d„ |
D «       «      d‰j                  z  z   }‰j                  |«      d   }t        j                  ||d¬	«      }t        j                  ||	¬«      } ‰|
|dd
œŽ |S c c}w c c}}w c c}}w )Nc              3   óH   •K  — | ]  }‰|   j                   ‰|   k(  –— Œ y ­w©N)Úndim)r	   ÚiÚargsÚ
core_ndimss     €€r   r   z=_with_cache_optimization.<locals>._wrapper.<locals>.<genexpr>]   s"   øè ø€ ÒH°ˆt�A‰w�|‰|˜z¨!™}Õ,ÑHùó   ƒ"r   c              3   óH   •K  — | ]  }‰|   j                   ‰   d k(  –— Œ y­w)r   N)Ústrides)r	   r   Úargs_bÚaxs     €€r   r   z=_with_cache_optimization.<locals>._wrapper.<locals>.<genexpr>x   s*   øè ø€ ò Ø/0��q‘	×!Ñ! "Ñ%¨Õ*ñùr   )Úaxesc              3   ó4   K  — | ]  }|j                   –— Œ y ­wr   )Údtype)r	   Úargs     r   r   z=_with_cache_optimization.<locals>._wrapper.<locals>.<genexpr>‹   s   è ø€ Ò9¨3˜SŸY�YÑ9ùs   ‚r   éÿÿÿÿÚC)r%   Úorder)Úoutr)   )ÚnpÚasarrayÚallÚ	enumerateÚshapeÚbroadcast_shapesÚlenÚbroadcast_toÚrangeÚappendÚlistÚ	transposer   ÚnoutÚresolve_dtypesÚempty)r   r&   r   Úbatch_shapesÚbatch_shapeÚ
batch_ndimÚvarying_axesÚconstant_axesÚis_constantÚsorted_batch_axesÚargs_tÚarg_br#   Úinput_dtypesÚ	out_dtypeÚ	out_finalÚout_tr!   r"   Úcache_arg_indicesr   Úufuncs   `                @@€€€r   Ú_wrapperz*_with_cache_optimization.<locals>._wrapperX   sB  û€ Ø+/Ö0 C”—
‘
˜3•Ò0ˆô ÔHÐ6GÔHÔHÙ˜$�<Ðô $ D›/÷
á��3ð +5°Q©-¸!Ò*;ˆC�I‰I�o˜
 1™�~Ñ&ÀÇÁÑJð
ˆñ 
ô ×)Ñ)¨<Ð8ˆÜ˜Ó%ˆ
ô $ D›/÷
ñ ��3ð ˜!‰}˜qÒ ô �O‰O˜C ¨s¯y©y¸*ÀQ¹-¸¸Ð/IÑ!IÔJÜ&(§o¡o°c¸;Ó&GñHó
ˆð ˆØˆä˜
Ó#ò 	(ˆBÜô Ø4Eôó ˆKñ Ø×$Ñ$ RÕ(à×#Ñ# BÕ'ð	(ð )¨=Ñ8Ðð ˆÜ! &Ó)ò 	:‰HˆAˆuØ$¤tÜ�j *¨z¸!©}Ñ"<Ó=ó(ñ ˆDð �M‰Mœ"Ÿ,™, u°4Ô8Õ9ð		:ô Ñ9°&Ô9Ó9¸GÀEÇJÁJÑ<NÑNˆØ×(Ñ(¨Ó6°rÑ:ˆ	Ü—H‘H˜[°	ÀÔEˆ	ä—‘˜YÐ->Ô?ˆñ 	ˆv˜5¨Ó,ØÐùòw 1ùó
ùó
s   ‰H!Á1H&Â/AH,z, zdef ú(z):
            return _wrapper(z
)
        rI   )r   r   ÚninÚjoinÚexecÚ__doc__)ÚnameÚ	arg_namesÚ	docstringrH   rG   rI   Úarg_strÚcodeÚ	namespaceÚwrapperr   s      ``     @r   Ú_with_cache_optimizationrV      s•   ú€ ðJ �?‰?Ð&ô 	˜%Ÿ/™/Ô*à�%—)‘)‰^ð ö<ð@ �i‰i˜	Ó"€Gà���a˜�yð !Ø$˜Ið &	ð	ð 	ð
 ˜XÐ&€IÜˆˆyÔØ˜‰o€GØ€G„OØ€Nr   )rN   r   Únumpyr+   r   rV   © r   r   ú<module>rY      s   ðñó 
Û òKóSr   