
    4[g                         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y)   )_ccallback_c    Nc                       e Zd Zy)CDataN)__name__
__module____qualname__     P/var/www/html/bid-api/venv/lib/python3.12/site-packages/scipy/_lib/_ccallback.pyr   r   	   s    r   r   c                  ~    t         y 	 dd l} | j                         a t         j                  ay # t        $ r da Y y w xY w)Nr   F)fficffiFFIr   ImportError)r   s    r   _import_cffir      s<     hhj		 s   $. <<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y)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                 Z    | j                  |||      }t        j                  | |||f      S N)_parse_callbacktuple__new__)clsfunction	user_data	signatureitems        r   r   zLowLevelCallable.__new__h   s0     ""8Y	B}}S49"=>>r   c                 <    d| j                   d| j                  dS )NzLowLevelCallable(, ))r   r   selfs    r   __repr__zLowLevelCallable.__repr__n   s!    "4=="32dnn5GqIIr   c                 .    t         j                  | d      S )Nr   r   __getitem__r"   s    r   r   zLowLevelCallable.functionq         q))r   c                 .    t         j                  | d      S )N   r&   r"   s    r   r   zLowLevelCallable.user_datau   r(   r   c                 T    t        j                  t        j                  | d            S )Nr   )r   get_capsule_signaturer   r'   r"   s    r   r   zLowLevelCallable.signaturey   s     11%2C2CD!2LMMr   c                     t               r   )
ValueError)r#   idxs     r   r'   zLowLevelCallable.__getitem__}   s
    lr   c                     	 |j                   |   } | |||      S # t        $ r}d}t        |      |d}~wt        $ r}d|d}t        |      |d}~ww xY w)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   sq    "	-**40H 8Y	22  	-WGW%1, 	-$TH,PQGW%1,	-s    	A2AAAc                 ,   t                t        |t              rt        j	                  |d      }nct        |t
              rt        ||      \  }}nCt        |t              rt        ||      \  }}n#t        j                  |      r|}nt        d      t        |t        j                        rt        |      }nDt        |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+,$$S!,DZ(.sI>OD)U#,S)<OD)'',D J K K i1&y1G	5)$Y/GG''	2G O P P ++D)WEEr   )NN)r   r   r	   __doc__	__slots__r   r$   propertyr   r   r   r'   classmethodr8   r   r
   r   r   r   r      s    HV I?J * * * * N N 3 34 F Fr   r   c                 (   t        j                  | t         j                        j                  }|_t	        | j
                        dz   }t        | j                        D ]*  \  }}|dk(  r|t	        |      z  }|dt	        |      z   z  }, |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77H )$,,7$>	.FAsAv2377	T$9#$>>>		 /
 	S	Yr   c                     | y| t         j                  u ry| j                  }d}|j                  d      r|dz  }|dd  }|j                  d      r|j                  d      r|dd  }|dkD  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    |		 ==DM
//%
 ABx //%
  tABxqc-'''Kr   c                 ^    t        j                  | t         j                        j                  S r   )r?   rL   r@   rM   datas    r   rA   rA      s    ;;tV__-333r   c                     t         j                  d|       }|8t         j                  t         j                  |             j	                  dd      }||fS )N	uintptr_tz(*)rZ   )r   rL   getctypetypeofreplace)rE   r   rR   s      r   r=   r=      sI    xxT*H LLD!12::5#F	Yr   c                 .    t         j                  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      sj     Vfoo.88;

	 	]Fu ]FH",4'r   