+
    nDj                     &    R t ^ RIt^ RItR tR tR# )z4Helpers for producing efficient wrappers of ufuncs.
Nc                    V P                  R4      ^ ,          p\        P                  ! RV4      p\        ;QJ d    . R V 4       F  NK  	  5# ! R V 4       4      # )z>Return tuple of num core dims per input from gufunc signature.z->z	\((.*?)\)c              3      "   T F4  qP                  4       '       g   ^ MVP                  R4      ^,           x  K6  	  R# 5i)    ,N)stripcount).0gs   & T/data/cameron/venvs/s3viz/lib/python3.14/site-packages/scipy/special/_ufunc_tools.py	<genexpr>$_parse_core_ndims.<locals>.<genexpr>   s*     J6a'')))996s   <>)splitrefindalltuple)	signature	input_siggroupss   &  r
   _parse_core_ndimsr      sG    %a(IZZi0F5J6J5J5J6JJJ    c                   aaa
 SP                   e   \        SP                   4      MRSP                  ,          o
VV
V3R lpRP                  V4      pRV  RV RV R2pRV/p\	        Wx4       W,          p	W)n        V	# )	a{	  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.

c                    <a aa S  Uu. uF  p\         P                  ! V4      NK  	  upo \        ;QJ d     V V3R  lS 4       F  '       d   K   RM	  RM! V V3R  lS 4       4      '       d   S! S !  # \        S 4       UUu. uF6  w  r!SV,          ^ 8  d   VP                  RSV,          )  MVP                  NK8  	  ppp\         P
                  ! V!  p\        V4      p\        S 4       UUu. uF[  w  r!SV,          ^ 8  d3   \         P                  ! WVP                  SV,          ) R ,           4      M\         P                  ! W4      NK]  	  uppo. p. p\        V4       Fk  o\        ;QJ d     VV3R lS 4       F  '       d   K   RM	  RM! VV3R lS 4       4      pV'       d   VP                  S4       KZ  VP                  S4       Km  	  Wg,           p	. p
\        S4       FT  w  r+V	\        \        WUSV,          ,           4      4      ,           pV
P                  \         P                  ! WR7      4       KV  	  \        ;QJ d    . R V
 4       F  NK  	  5M! R V
 4       4      RSP                  ,          ,           pSP                  V4      R,          p\         P                  ! WNRR7      p\         P                  ! WR7      pS! V
R	VR
R/  V# u upi u uppi u uppi )c              3   ^   <"   T F"  pSV,          P                   SV,          8H  x  K$  	  R # 5iN)ndim)r   iargs
core_ndimss   & r
   r   =_with_cache_optimization.<locals>._wrapper.<locals>.<genexpr>]   s$     H6GtAw||z!},6G   *-FTNc              3   ^   <"   T F"  pSV,          P                   S,          ^ 8H  x  K$  	  R# 5i)r   N)strides)r   r   args_baxs   & r
   r   r   x   s)      4Eqq	!!"%*4Er   )axesc              3   8   "   T F  qP                   x  K  	  R # 5ir   )dtype)r   args   & r
   r   r      s     9&3YY&s   C)r&   orderoutr)   r   )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   j                @@r
   _wrapper*_with_cache_optimization.<locals>._wrapperX   sl   +/04C

340 3H6GH333H6GHHH$< $D/
) +5Q-!*;CIIo
1~&J) 	 
 ))<8%
 $D/
 * !}q  OOCsyy*Q-/I!IJ&(ooc&GH)
 
#B# 4E### 4E K $$R(##B' $ )8 !&)HA$tjz!}"<=( D MM",,u89	 * u9&9uu9&99GEJJ<NN((6r:	HH[E	Y? 	v,5,,w 1

s   K<K-A!Kz, zdef (z):
            return _wrapper(z
)
        rJ   )r   )r   r   ninjoinexec__doc__)name	arg_names	docstringrI   rH   rJ   arg_strcode	namespacewrapperr   s   $$$dd     @r
   _with_cache_optimizationrX      s    J ??& 	%//*%))^ <@ ii	"Gay !$I &		 	
 X&IoGONr   )rP   r   numpyr,   r   rX    r   r
   <module>r[      s    
 KSr   