L iddlmZddlZejejj dZdaGddadZ Gdde Z dd Z d Z d Zdd Zd Zy)) _ccallback_cNc eZdZy)CDataN)__name__ __module__ __qualname__[/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/scipy/_lib/_ccallback.pyrr sr rc~ty ddl}|jatjay#t$rdaYywxYw)NrF)fficffiFFIr ImportError)rs r _import_cffir s< hhj  s $. <<c|eZdZdZdZd dZdZedZedZ edZ d Z e d d Z e d d Zy) 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 NcZ|j|||}tj||||fSN)_parse_callbacktuple__new__)clsfunction user_data signatureitems r rzLowLevelCallable.__new__hs0""8Y B}}S49"=>>r c<d|jd|jdS)NzLowLevelCallable(, ))rrselfs r __repr__zLowLevelCallable.__repr__ns!"4=="32dnn5GqIIr c.tj|dS)Nrr __getitem__r"s r rzLowLevelCallable.functionq  q))r c.tj|dS)Nr&r"s r rzLowLevelCallable.user_dataur(r cTtjtj|dS)Nr)rget_capsule_signaturerr'r"s r rzLowLevelCallable.signatureys 11%2C2CD!2LMMr ctr) ValueError)r#idxs r r'zLowLevelCallable.__getitem__}s lr c |j|}||||S#t$r}d}t||d}~wt$r}d|d}t||d}~wwxYw)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)rmodulenamerrremessages r from_cythonzLowLevelCallable.from_cythonsq" -**40H8Y 22  -WGW%1 , -$TH,PQGW%1 , -s A2 AAAc,tt|trtj |d}nct|t rt ||\}}nCt|trt||\}}n#tj|r|}n tdt|tjr t|}nDt|tr t|}n(|d}n#tj|r|}n tdtj |||S)NrzMGiven 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 isinstancerrr' PyCFuncPtr_get_ctypes_funcr_get_cffi_funcr check_capsuler.ctypesc_void_p_get_ctypes_data_get_cffi_dataget_raw_capsule)robjrrfunccontexts r rz LowLevelCallable._parse_callbacks c+ ,$$S!,D Z (.sI>OD) U #,S)  . ?FAsAv2377 T$9#$>>>  ? S Y r c|y|tjury|j}d}|jdr|dz }|dd}|jdr|jdr|dd}|dkDr |d d |zzz }|S) Nvoidzvoid *rLP_rc_r* *)r?r@r startswith)rr5 pointer_levels r rNrNs |   ==DM //%  ABx //%  tABxq c-''' Kr c^tj|tjjSr)r?rLr@rMdatas r rArAs ;;tV__ - 3 33r ctjd|}|8tjtj|j dd}||fS)N uintptr_tz(*)rZ)rrLgetctypetypeofreplace)rErrRs r r=r=sIxx T*HLLD!12::5#F Y r c.tjd|S)Nrb)rrLr_s r rBrBs 88K &&r r)rr? CFUNCTYPEr@ __bases__r;rrrrrr<rNrAr=rBr r r rjsj V  foo . 8 8 ;     ]Fu]FH",4'r