
    (ph                         S SK Jr  SSKr\R                  " \R                  5      R
                  S   rSq " S S5      qS r	 " S S\
5      rSS	 jrS
 rS rSS jrS rg)   )_ccallback_c    Nc                       \ rS rSrSrg)CData	    N)__name__
__module____qualname____firstlineno____static_attributes__r       H/var/www/html/venv/lib/python3.13/site-packages/scipy/_lib/_ccallback.pyr   r   	   s    r   r   c                      [         b  g  SS Kn U R                  5       q [         R                  qg ! [         a    Sq  g f = f)Nr   F)fficffiFFIr   ImportError)r   s    r   _import_cffir      s<     hhj		 s   $/ >>c                       \ rS rSrSrSrSS jrS r\S 5       r	\S 5       r
\S	 5       rS
 r\SS j5       r\SS j5       rSrg)LowLevelCallable   a  
Low-level callback function.

Some functions in SciPy take as arguments callback functions, which
can either be python callables or low-level compiled functions. Using
compiled callback functions can improve performance somewhat by
avoiding wrapping data in Python objects.

Such low-level functions in SciPy are wrapped in `LowLevelCallable`
objects, which can be constructed from function pointers obtained from
ctypes, cffi, Cython, or contained in Python `PyCapsule` objects.

.. seealso::

   Functions accepting low-level callables:

   `scipy.integrate.quad`, `scipy.ndimage.generic_filter`,
   `scipy.ndimage.generic_filter1d`, `scipy.ndimage.geometric_transform`

   Usage examples:

   :ref:`ndimage-ccallbacks`, :ref:`quad-callbacks`

Parameters
----------
function : {PyCapsule, ctypes function pointer, cffi function pointer}
    Low-level callback function.
user_data : {PyCapsule, ctypes void pointer, cffi void pointer}
    User data to pass on to the callback function.
signature : str, optional
    Signature of the function. If omitted, determined from *function*,
    if possible.

Attributes
----------
function
    Callback function given.
user_data
    User data given.
signature
    Signature of the function.

Methods
-------
from_cython
    Class method for constructing callables from Cython C-exported
    functions.

Notes
-----
The argument ``function`` can be one of:

- PyCapsule, whose name contains the C function signature
- ctypes function pointer
- cffi function pointer

The signature of the low-level callback must match one of those expected
by the routine it is passed to.

If constructing low-level functions from a PyCapsule, the name of the
capsule must be the corresponding signature, in the format::

    return_type (arg1_type, arg2_type, ...)

For example::

    "void (double)"
    "double (double, int *, void *)"

The context of a PyCapsule passed in as ``function`` is used as ``user_data``,
if an explicit value for ``user_data`` was not given.

r   Nc                 T    U R                  XU5      n[        R                  XX45      $ N)_parse_callbacktuple__new__)clsfunction	user_data	signatureitems        r   r   LowLevelCallable.__new__h   s*     ""8	B}}S"=>>r   c                 @    SU R                   < SU R                  < S3$ )NzLowLevelCallable(, ))r   r    selfs    r   __repr__LowLevelCallable.__repr__n   s!    "4=="32dnn5GqIIr   c                 .    [         R                  U S5      $ )Nr   r   __getitem__r'   s    r   r   LowLevelCallable.functionq         q))r   c                 .    [         R                  U S5      $ )N   r,   r'   s    r   r    LowLevelCallable.user_datau   r/   r   c                 V    [         R                  " [        R                  U S5      5      $ )Nr   )r   get_capsule_signaturer   r-   r'   s    r   r!   LowLevelCallable.signaturey   s     11%2C2CD!2LMMr   c                     [        5       er   )
ValueError)r(   idxs     r   r-   LowLevelCallable.__getitem__}   s
    lr   c                      UR                   U   nU " XSU5      $ ! [         a  nSn[        U5      UeSnAf[         a  nSU< S3n[        U5      UeSnAff = f)a  
Create a low-level callback function from an exported Cython function.

Parameters
----------
module : module
    Cython module where the exported function resides
name : str
    Name of the exported function
user_data : {PyCapsule, ctypes void pointer, cffi void pointer}, optional
    User data to pass on to the callback function.
signature : str, optional
    Signature of the function. If omitted, determined from *function*.

z?Given module is not a Cython module with __pyx_capi__ attributeNzNo function z$ found in __pyx_capi__ of the module)__pyx_capi__AttributeErrorr7   KeyError)r   modulenamer    r!   r   emessages           r   from_cythonLowLevelCallable.from_cython   so    "	-**40H 8	22  	-WGW%1, 	-$TH,PQGW%1,	-s    
A2AAAc                 p   [        5         [        U[        5      (       a  [        R	                  US5      nOo[        U[
        5      (       a  [        X5      u  pCOL[        U[        5      (       a  [        X5      u  pCO)[        R                  " U5      (       a  UnO[        S5      e[        U[        R                  5      (       a  [        U5      nOP[        U[        5      (       a  [        U5      nO/Uc  SnO)[        R                  " U5      (       a  UnO[        S5      e[        R                   " XCU5      $ )Nr   zMGiven input is not a callable or a low-level callable (pycapsule/ctypes/cffi)zNGiven user data is not a valid low-level void* pointer (pycapsule/ctypes/cffi))r   
isinstancer   r   r-   
PyCFuncPtr_get_ctypes_funcr   _get_cffi_funcr   check_capsuler7   ctypesc_void_p_get_ctypes_data_get_cffi_dataget_raw_capsule)r   objr    r!   funccontexts         r   r    LowLevelCallable._parse_callback   s   c+,,$$S!,DZ((.s>OD)U##,S<OD)'',,D J K K i11&y1G	5))$Y/GG''	22G O P P ++DWEEr   )NN)r	   r
   r   r   __doc__	__slots__r   r)   propertyr   r    r!   r-   classmethodrB   r   r   r   r   r   r   r      s    HV I?J * * * * N N 3 34 F Fr   r   c                 0   [         R                  " U [         R                  5      R                  nUcb  [	        U R
                  5      S-   n[        U R                  5       H,  u  p4US:X  a  U[	        U5      -  nM  US[	        U5      -   -  nM.     US-  nX!4$ )Nz (r   r%   r&   )rJ   castrK   value_typename_from_ctypesrestype	enumerateargtypes)rP   r!   func_ptrjargs        r   rG   rG      s    {{4177H )$,,7$>	.FAAv2377	T$9#$>>>		 /
 	S	r   c                    U c  gU [         R                  L a  gU R                  nSnUR                  S5      (       a"  US-  nUSS  nUR                  S5      (       a  M"  UR                  S5      (       a  USS  nUS:  a  US	S
U-  -   -  nU$ )Nvoidzvoid *r   LP_r      c_r1    *)rJ   rK   r	   
startswith)r"   r?   pointer_levels      r   rZ   rZ      s    |		 ==DM
//%
 
 ABx //%
 
  tABxqc-'''Kr   c                 `    [         R                  " U [         R                  5      R                  $ r   )rJ   rX   rK   rY   datas    r   rL   rL      s    ;;tV__-333r   c                     [         R                  SU 5      nUc8  [         R                  [         R                  U 5      5      R	                  SS5      nX!4$ )N	uintptr_tz(*)rf   )r   rX   getctypetypeofreplace)rP   r!   r^   s      r   rH   rH      sG    xxT*H LLD!12::5#F	r   c                 .    [         R                  SU 5      $ )Nrn   )r   rX   rk   s    r   rM   rM      s    88K&&r   r   ) r   rJ   	CFUNCTYPErK   	__bases__rF   r   r   r   r   r   rG   rZ   rL   rH   rM   r   r   r   <module>rv      sh     foo.88;

	 	]Fu ]FH",4'r   