HEX
Server: LiteSpeed
System: Linux standart9.isimtescil.net 3.10.0-962.3.2.lve1.5.26.7.el7.x86_64 #1 SMP Wed Oct 2 07:53:12 EDT 2019 x86_64
User: karalev (5310)
PHP: 8.2.29
Disabled: NONE
Upload Files
File: //opt/alt/python27/lib64/python2.7/site-packages/numpy/ctypeslib.pyo
�
�9Zc@`s�dZddlmZmZmZddddddd	gZdd
lZdd
lZddlm	Z	m
Z
mZm
Z
mZddlmZmZydd
lZWnek
r�d
ZnXed
krd
�ZeZeZeZeZddlmZeZnEdd
ljj Z!e!j"�Z[!ej#Zd�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*j0e*j1fdfe*j2e*j3e*j4e*j5e*j6fdfe*j7e*j8fdfgZ9xEe9D]=\Z:Z;x.e:D]&Z<e,e<de;e*j=e<�f�qGWq4We>e*j/d �Z?d!�Z@d"�ZAd
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_func.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

i(tdivisiontabsolute_importtprint_functiontload_libraryt	ndpointerttesttctypes_load_librarytc_intpt	as_ctypestas_arrayN(tintegertndarraytdtypet	deprecatetarray(t	_flagdicttflagsobjcO`std��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((sB/opt/alt/python27/lib64/python2.7/site-packages/numpy/ctypeslib.pyt_dummyCs
(tintpcC`s[tjdkr+ddl}|jd�ntjj|�d}|s�ddlm}|�}||g}|dt	�}||ks�|j
d||�q�n	|g}tjj|�}tjj|�s�tjj
|�}n|}x^|D]V}	tjj||	�}
tjj|
�r�ytj|
SWqGtk
rC�qGXq�q�Wtd��dS(	sj
        It is possible to load a library using 
        >>> lib = ctypes.cdll[<full_path_name>]

        But there are cross-platform considerations, such as library file extensions,
        plus the fact Windows will just load the first library it finds with that name.  
        Numpy supplies the load_library function as a convenience.

        Parameters
        ----------
        libname : str
            Name of the library, which can have 'lib' as a prefix,
            but without an extension.
        loader_path : str
            Where the library can be found.

        Returns
        -------
        ctypes.cdll[libpath] : library object
           A ctypes library object 

        Raises
        ------
        OSError
            If there is no library with the expected extension, or the 
            library is defective and cannot be loaded.
        s1.0.1iNsAAll features of ctypes interface may not work with ctypes < 1.0.1i(tget_shared_lib_extensiont
is_python_extsno file with expected extension(tctypest__version__twarningstwarntostpathtsplitexttnumpy.distutils.misc_utilRtTruetinserttabspathtisdirtdirnametjointexiststcdlltOSError(tlibnametloader_pathRtextRtso_exttlibname_exttso_ext2tlibdirtlntlibpath((sB/opt/alt/python27/lib64/python2.7/site-packages/numpy/ctypeslib.pyR[s0	
	

cC`s)d}x|D]}|t|7}q
W|S(Ni(R(tflaglisttnumtval((sB/opt/alt/python27/lib64/python2.7/site-packages/numpy/ctypeslib.pyt_num_fromflags�s
tC_CONTIGUOUStF_CONTIGUOUStALIGNEDt	WRITEABLEtOWNDATAtUPDATEIFCOPYcC`s?g}x2tD]*}t|}||@r
|j|�q
q
W|S(N(t
_flagnamesRtappend(R3trestkeytvalue((sB/opt/alt/python27/lib64/python2.7/site-packages/numpy/ctypeslib.pyt_flags_fromnum�s


t_ndptrcB`s/eZd�Zed��Zed��ZRS(cC`s
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((sB/opt/alt/python27/lib64/python2.7/site-packages/numpy/ctypeslib.pyt_check_retval_�scC`sUi|jjd6|d6dd6|jd6dd6|jjddd	6|jtfd
6S(Ntdescrt__reftstridestshapeitversioniittypestrtdata(t_dtype_REtNonet_shape_R@tFalse(RC((sB/opt/alt/python27/lib64/python2.7/site-packages/numpy/ctypeslib.pyt__array_interface__�s
cC`st|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	TypeErrorRLRMRt_ndim_tndimRNRHtstrt_flags_tflagsR3RAR(tclstobj((sB/opt/alt/python27/lib64/python2.7/site-packages/numpy/ctypeslib.pyt
from_param�s (t__name__t
__module__RDtpropertyRPtclassmethodRZ(((sB/opt/alt/python27/lib64/python2.7/site-packages/numpy/ctypeslib.pyRB�s	c	C`sq|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_%sRLRNRSRVN(RMt_dtypeRQRUtsplittintR
RARR3tstriptupperRRR5t_pointer_type_cachetKeyErrortnamestidttupleR%ttypeRB(	RRTRHRWR3Rbtnametstrshapetklass((sB/opt/alt/python27/lib64/python2.7/site-packages/numpy/ctypeslib.pyR�s^4	)
			#




c`s^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.
        Nc`sMid�fgd6|d6dd6d
d6dd6�d6tj|�tfd	6S(NtRERFRGRHiRIRJRK((RMtctt	addressofRO(RC(RJ(sB/opt/alt/python27/lib64/python2.7/site-packages/numpy/ctypeslib.pyRPUs(RPtAttributeErrorRcRUt
_typecodesR](tsimple_typeRRP((RJsB/opt/alt/python27/lib64/python2.7/site-packages/numpy/ctypeslib.pytprep_simpleJs


titutfs%c%dic`s�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.
        NRERJc`sDi�d6|d6dd6�d6dd6�d6tj|�tfd6S(	NRERFRGRHiRIRJRK(RMRrRsRO(RC(RERHRJ(sB/opt/alt/python27/lib64/python2.7/site-packages/numpy/ctypeslib.pyRP�s
(	RPRtRmt_ARRAY_TYPER=t_length_t_type_RlR](t
array_typetobtaiRP((RERHRJsB/opt/alt/python27/lib64/python2.7/site-packages/numpy/ctypeslib.pyt
prep_arrayqs 




cC`sy|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.
        NiRIRJRKRH(	RPRttcontentsRcRmRURrRsRO(tpointer_objRHR�Rtinter((sB/opt/alt/python27/lib64/python2.7/site-packages/numpy/ctypeslib.pytprep_pointer�s
	


cC`sdt|�}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(RmRPRtthasattrR�R�RRO(RYRHttp((sB/opt/alt/python27/lib64/python2.7/site-packages/numpy/ctypeslib.pyR	�s
cC`s�|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.RGsstrided arrays not supportedRIis,only __array_interface__ version 3 supportedRKsreadonly arrays unsupportedRJRHNi����(RPRRRutfrom_addresst__keep(RYR�taddrtreadonlyR�tdimtresult((sB/opt/alt/python27/lib64/python2.7/site-packages/numpy/ctypeslib.pyR�s	
	(Bt__doc__t
__future__RRRt__all__tsysRtnumpyR
RRRcR
Rtnumpy.core.multiarrayRRRRRMRRRRR	RRtobjectt_ndptr_basetnumpy.core._internaltcoret	_internaltnict_getintp_ctypetc_void_pR5R<RARBRhRRrRuRwtc_bytetc_shorttc_inttc_longt
c_longlongtc_ubytetc_ushorttc_uinttc_ulongtc_ulonglongtc_floattc_doubletsimple_typesttypestcodeR�tsizeofRmR{R�R�(((sB/opt/alt/python27/lib64/python2.7/site-packages/numpy/ctypeslib.pyt<module>3s^(

				B					)f	''
(