
    ^Mh                         d dl mZ ddlZ ej        ej                  j        d         Zda G d d          ad Z	 G d de
          Zdd	Zd
 Zd ZddZd ZdS )   )_ccallback_c    Nc                       e Zd ZdS )CDataN)__name__
__module____qualname__     U/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/scipy/_lib/_ccallback.pyr   r   	   s        Dr   r   c                      t           d S 	 dd l} |                                 a t           j        ad S # t          $ r da Y d S w xY w)Nr   F)fficffiFFIr   ImportError)r   s    r   _import_cffir      sZ     hhjj	   s   $1 A Ac                       e Zd ZdZdZddZd Zed             Zed             Z	ed             Z
d	 Zedd
            Zedd            ZdS )LowLevelCallablea  
    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                 l    |                      |||          }t                              | |||f          S N)_parse_callbacktuple__new__)clsfunction	user_data	signatureitems        r   r   zLowLevelCallable.__new__h   s6     ""8Y	BB}}S49"=>>>r   c                 (    d| j         d| j        dS )NzLowLevelCallable(, ))r   r   selfs    r   __repr__zLowLevelCallable.__repr__n   s    I4=IIdnIIIIr   c                 8    t                               | d          S )Nr   r   __getitem__r"   s    r   r   zLowLevelCallable.functionq         q)))r   c                 8    t                               | d          S )N   r&   r"   s    r   r   zLowLevelCallable.user_datau   r(   r   c                 \    t          j        t                              | d                    S )Nr   )r   get_capsule_signaturer   r'   r"   s    r   r   zLowLevelCallable.signaturey   s#    1%2C2CD!2L2LMMMr   c                     t                      r   )
ValueError)r#   idxs     r   r'   zLowLevelCallable.__getitem__}   s    llr   c                     	 |j         |         }nG# t          $ r}d}t          |          |d}~wt          $ r}d|d}t          |          |d}~ww xY w | |||          S )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__AttributeErrorr.   KeyError)r   modulenamer   r   r   emessages           r   from_cythonzLowLevelCallable.from_cython   s    "	-*40HH 	- 	- 	-WGW%%1, 	- 	- 	-QTQQQGW%%1,	- s8Y	222s    
A,AAAc                    t                       t          |t                    rt                              |d          }nxt          |t
                    rt          ||          \  }}nOt          |t                    rt          ||          \  }}n&t          j
        |          r|}nt          d          t          |t          j                  rt          |          }nPt          |t                    rt          |          }n+|d}n&t          j
        |          r|}nt          d          t          j        |||          S )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_capsuler.   ctypesc_void_p_get_ctypes_data_get_cffi_dataget_raw_capsule)r   objr   r   funccontexts         r   r   z LowLevelCallable._parse_callback   s^   c+,, 
	K$$S!,,DDZ(( 	K.sI>>OD))U## 	K,S)<<OD))',, 	KDD J K K K i11 
	P&y11GG	5)) 	P$Y//GGGG'	22 	PGG O P P P +D)WEEEr   )NN)r   r   r	   __doc__	__slots__r   r$   propertyr   r   r   r'   classmethodr8   r   r
   r   r   r   r      s        H HV I? ? ? ?J J J * * X* * * X* N N XN   3 3 3 [34 F F F [F F Fr   r   c                    t          j        | t           j                  j        }|dt	          | j                  dz   }t          | j                  D ]3\  }}|dk    r|t	          |          z  }|dt	          |          z   z  }4|dz  }||fS )Nz (r   r    r!   )r?   castr@   value_typename_from_ctypesrestype	enumerateargtypes)rE   r   func_ptrjargs        r   r<   r<      s    {4117H )$,77$>	.. 	? 	?FAsAvv23777		T$9#$>$>>>		S	Yr   c                    | dS | t           j        u rdS | j        }d}|                    d          r$|dz  }|dd          }|                    d          $|                    d          r
|dd          }|dk    r|d	d
|z  z   z  }|S )Nvoidzvoid *r   LP_r      c_r*    *)r?   r@   r   
startswith)r   r5   pointer_levels      r   rN   rN      s    |v		 	 x=DM
//%
 
  ABBx //%
 
   t ABBxqc-'''Kr   c                 J    t          j        | t           j                  j        S r   )r?   rL   r@   rM   datas    r   rA   rA      s    ;tV_--33r   c                     t                               d|           }|Ft                               t                               |                                         dd          }||fS )N	uintptr_tz(*)rZ   )r   rL   getctypetypeofreplace)rE   r   rR   s      r   r=   r=      sU    xxT**H LLD!1!122::5#FF	Yr   c                 8    t                               d|           S )Nrb   )r   rL   r_   s    r   rB   rB      s    88K&&&r   r   ) r   r?   	CFUNCTYPEr@   	__bases__r;   r   r   r   r   r   r<   rN   rA   r=   rB   r
   r   r   <module>rj      s         Vfo..8;

	 	 	 	 	 	 	 	  ]F ]F ]F ]F ]Fu ]F ]F ]FH   "  ,4 4 4   ' ' ' ' 'r   