KGRKJGETMRETU895U-589TY5MIGM5JGB5SDFESFREWTGR54TY
Server : Apache
System : Linux server112.speedpacket.com 3.10.0-962.3.2.lve1.5.36.el7.x86_64 #1 SMP Mon May 18 02:16:06 EDT 2020 x86_64
User : equistyl ( 1341)
PHP Version : 8.1.30
Disable Function : NONE
Directory :  /lib64/python2.7/site-packages/numpy/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //lib64/python2.7/site-packages/numpy/ctypeslib.pyc
�
E�`Qc@s�dZdddddddgZdd	lZdd	lZdd
lmZmZmZm	Z	m
Z
ddlmZm
Z
ydd	lZWnek
r�d	ZnXed	kr�d�ZeZeZeZeZdd
lmZeZnEdd	ljjZej�Z[ejZd�Ze	edd�Zd�Z ddddddgZ!d�Z"defd��YZ#iZ$d	d	d	d	d�Z%ed	k	r�eZ&iZ'd�Z(e&j)e&j*e&j+e&j,e&j-fdfe&j.e&j/e&j0e&j1e&j2fdfe&j3e&j4fdfgZ5xEe5D]=\Z6Z7x.e6D]&Z8e(e8de7e&j9e8�f�q+WqWe:e&j+d�Z;d �Z<d!�Z=d	d"�Zd#�Znd	S($s
============================
``ctypes`` Utility Functions
============================

See Also
---------
load_library : Load a C library.
ndpointer : Array restype/argtype with verification.
as_ctypes : Create a ctypes array from an ndarray.
as_array : Create an ndarray from a ctypes array.

References
----------
.. [1] "SciPy Cookbook: ctypes", http://www.scipy.org/Cookbook/Ctypes

Examples
--------
Load the C library:

>>> _lib = np.ctypeslib.load_library('libmystuff', '.')     #doctest: +SKIP

Our result type, an ndarray that must be of type double, be 1-dimensional
and is C-contiguous in memory:

>>> array_1d_double = np.ctypeslib.ndpointer(
...                          dtype=np.double,
...                          ndim=1, flags='CONTIGUOUS')    #doctest: +SKIP

Our C-function typically takes an array and updates its values
in-place.  For example::

    void foo_func(double* x, int length)
    {
        int i;
        for (i = 0; i < length; i++) {
            x[i] = i*i;
        }
    }

We wrap it using:

>>> lib.foo_func.restype = None                 #doctest: +SKIP
>>> lib.foo.argtypes = [array_1d_double, c_int] #doctest: +SKIP

Then, we're ready to call ``foo_func``:

>>> out = np.empty(15, dtype=np.double)
>>> _lib.foo_func(out, len(out))                #doctest: +SKIP

tload_libraryt	ndpointerttesttctypes_load_librarytc_intpt	as_ctypestas_arrayi����N(tintegertndarraytdtypet	deprecatetarray(t	_flagdicttflagsobjcOstd��dS(s�
        Dummy object that raises an ImportError if ctypes is not available.

        Raises
        ------
        ImportError
            If ctypes is not available.

        sctypes is not available.N(tImportError(targstkwds((s5/usr/lib64/python2.7/site-packages/numpy/ctypeslib.pyt_dummyAs
(tintpc
Cs�tjdkr+ddl}|jd�ntjj|�d}|sddlm}|�}||g}t	j
d dkr�|dt�}||ks�|jd	||�q�nt	j
d
kr�|jd	d|�q
t	j
dkr
|jd	d
|�q
n	|g}tjj|�}tjj|�sFtjj|�}n|}d}	xN|D]F}
y$tjj||
�}tj|SWqYtk
r�}|}	qYXqYW|	�dS(Ns1.0.1i����sAAll features of ctypes interface may not work with ctypes < 1.0.1i(tget_shared_lib_extensionis3.2t
is_python_extitwin32s%s.dlltdarwins%s.dylib(tctypest__version__twarningstwarntostpathtsplitexttnumpy.distutils.misc_utilRtsystversiontTruetinserttplatformtabspathtisdirtdirnametNonetjointcdlltOSError(
tlibnametloader_pathRtextRtso_exttlibname_exttso_ext2tlibdirtexctlntlibpathte((s5/usr/lib64/python2.7/site-packages/numpy/ctypeslib.pyRYs:	
	
cCs)d}x|D]}|t|7}q
W|S(Ni(R(tflaglisttnumtval((s5/usr/lib64/python2.7/site-packages/numpy/ctypeslib.pyt_num_fromflags�s
tC_CONTIGUOUStF_CONTIGUOUStALIGNEDt	WRITEABLEtOWNDATAtUPDATEIFCOPYcCs?g}x2tD]*}t|}||@r
|j|�q
q
W|S(N(t
_flagnamesRtappend(R7trestkeytvalue((s5/usr/lib64/python2.7/site-packages/numpy/ctypeslib.pyt_flags_fromnum�s


t_ndptrcBs/eZd�Zed��Zed��ZRS(cCs
t|�S(s�This method is called when this class is used as the .restype
        asttribute for a shared-library function.   It constructs a numpy
        array from a void pointer.(R(tself((s5/usr/lib64/python2.7/site-packages/numpy/ctypeslib.pyt_check_retval_�scCsUi|jjd6|d6dd6|jd6dd6|jjddd	6|jtfd
6S(Ntdescrt__reftstridestshapeiR iittypestrtdata(t_dtype_RIR't_shape_RDtFalse(RG((s5/usr/lib64/python2.7/site-packages/numpy/ctypeslib.pyt__array_interface__�s
cCst|t�std��n|jdk	rU|j|jkrUtd|j��n|jdk	r�|j|jkr�td|j��n|jdk	r�|j	|jkr�tdt
|j���n|jdk	r|jj
|j@|jkrtdt|j���n|jS(Nsargument must be an ndarraysarray must have data type %ssarray must have %d dimension(s)sarray must have shape %ssarray must have flags %s(t
isinstanceRt	TypeErrorROR'R	t_ndim_tndimRPRLtstrt_flags_tflagsR7RER(tclstobj((s5/usr/lib64/python2.7/site-packages/numpy/ctypeslib.pyt
from_param�s (t__name__t
__module__RHtpropertyRRtclassmethodR\(((s5/usr/lib64/python2.7/site-packages/numpy/ctypeslib.pyRF�s	c	Csq|dk	rt|�}nd}|dk	r�t|t�rN|jd�}nQt|ttf�rx|}t|�}n't|t�r�|j	}t|�}n|dkr�y)g|D]}|j
�j�^q�}Wntd��nXt
|�}q�nyt||||fSWntk
r'nX|dkr=d}n'|jr[tt|��}n	|j}|dk	r�|d|7}n|dk	ry#g|D]}t|�^q�}Wn)tk
r�t|�g}|f}nXt|�}|ddj|�7}n|dk	r(|ddj|�7}ng}td|tfi|d6|d	6|d
6|d6�}|t|<|S(
sC
    Array-checking restype/argtypes.

    An ndpointer instance is used to describe an ndarray in restypes
    and argtypes specifications.  This approach is more flexible than
    using, for example, ``POINTER(c_double)``, since several restrictions
    can be specified, which are verified upon calling the ctypes function.
    These include data type, number of dimensions, shape and flags.  If a
    given array does not satisfy the specified restrictions,
    a ``TypeError`` is raised.

    Parameters
    ----------
    dtype : data-type, optional
        Array data-type.
    ndim : int, optional
        Number of array dimensions.
    shape : tuple of ints, optional
        Array shape.
    flags : str or tuple of str
        Array flags; may be one or more of:

          - C_CONTIGUOUS / C / CONTIGUOUS
          - F_CONTIGUOUS / F / FORTRAN
          - OWNDATA / O
          - WRITEABLE / W
          - ALIGNED / A
          - UPDATEIFCOPY / U

    Returns
    -------
    klass : ndpointer type object
        A type object, which is an ``_ndtpr`` instance containing
        dtype, ndim, shape and flags information.

    Raises
    ------
    TypeError
        If a given array does not satisfy the specified restrictions.

    Examples
    --------
    >>> clib.somefunc.argtypes = [np.ctypeslib.ndpointer(dtype=np.float64,
    ...                                                  ndim=1,
    ...                                                  flags='C_CONTIGUOUS')]
    ... #doctest: +SKIP
    >>> clib.somefunc(np.array([1, 2, 3], dtype=np.float64))
    ... #doctest: +SKIP

    t,sinvalid flags specificationtanys_%ddt_txsndpointer_%sRORPRURXN(R't_dtypeRSRWtsplittintRRER
R7tstriptupperRTR9t_pointer_type_cachetKeyErrortnamestidttupleR(ttypeRF(	R	RVRLRYR7Rdtnametstrshapetklass((s5/usr/lib64/python2.7/site-packages/numpy/ctypeslib.pyR�s^4	)
			#




cs^y|jWntk
rnXdSt|�j�|t�<�fd�}t|�|_dS(s�Given a ctypes simple type, construct and attach an
        __array_interface__ property to it if it does not yet have one.
        NcsMid�fgd6|d6dd6d
d6dd6�d6tj|�tfd	6S(NtRIRJRKRLiR RMRN((R'tctt	addressofRQ(RG(RM(s5/usr/lib64/python2.7/site-packages/numpy/ctypeslib.pyRR=s(RRtAttributeErrorReRWt
_typecodesR_(tsimple_typeR	RR((RMs5/usr/lib64/python2.7/site-packages/numpy/ctypeslib.pytprep_simple2s


titutfs%c%dics�y|jWntk
rnXdSg�|}x/t|�tkr`�j|j�|j}q2Wt���|�j}|d�|d����fd�}t|�|_dS(s�Given a ctypes array type, construct and attach an
        __array_interface__ property to it if it does not yet have one.
        NRIRMcsDi�d6|d6dd6�d6dd6�d6tj|�tfd6S(	NRIRJRKRLiR RMRN(R'RtRuRQ(RG(RIRLRM(s5/usr/lib64/python2.7/site-packages/numpy/ctypeslib.pyRRks
(	RRRvRot_ARRAY_TYPERAt_length_t_type_RnR_(t
array_typetobtaiRR((RIRLRMs5/usr/lib64/python2.7/site-packages/numpy/ctypeslib.pyt
prep_arrayYs 




cCsy|jWntk
rnXdS|j}tt|��}idd6|jd6tj|�tfd6|d6}||_dS(s�Given a ctypes pointer object, construct and
        attach an __array_interface__ property to it if it does not
        yet have one.
        NiR RMRNRL(	RRRvtcontentsReRoRWRtRuRQ(tpointer_objRLR�R	tinter((s5/usr/lib64/python2.7/site-packages/numpy/ctypeslib.pytprep_pointerws
	


cCsdt|�}y|jWn:tk
rSt|d�rFt||�qTt|�nXt|dt�S(sCreate a numpy array from a ctypes array or a ctypes POINTER.
        The numpy array shares the memory with the ctypes object.

        The size parameter must be given if converting from a ctypes POINTER.
        The size parameter is ignored if converting from a ctypes array
        R�tcopy(RoRRRvthasattrR�R�RRQ(R[RLttp((s5/usr/lib64/python2.7/site-packages/numpy/ctypeslib.pyR�s
cCs�|j}|dr"td��n|ddkrAtd��n|d\}}|rftd��nt|d}x)|d	d
d
d�D]}||}q�W|j|�}||_|S(s�Create and return a ctypes object from a numpy array.  Actually
        anything that exposes the __array_interface__ is accepted.RKsstrided arrays not supportedR is,only __array_interface__ version 3 supportedRNsreadonly arrays unsupportedRMRLNi����(RRRTRwtfrom_addresst__keep(R[R�taddrtreadonlyR�tdimtresult((s5/usr/lib64/python2.7/site-packages/numpy/ctypeslib.pyR�s	
	(>t__doc__t__all__RRtnumpyRRR	ReR
Rtnumpy.core.multiarrayRR
RRR'RRRRRRRtobjectt_ndptr_basetnumpy.core._internaltcoret	_internaltnict_getintp_ctypetc_void_pR9R@RERFRjRRtRwRytc_bytetc_shorttc_inttc_longt
c_longlongtc_ubytetc_ushorttc_uinttc_ulongtc_ulonglongtc_floattc_doubletsimple_typesttypestcodeR�tsizeofRoR}R�R�(((s5/usr/lib64/python2.7/site-packages/numpy/ctypeslib.pyt<module>3s\(

				,					)f	''
(		

Anon7 - 2021