ó R;]c@@s9dZddlmZddlZddlZddlZddlZddlZddlZddl Z ddl m Z ej ddeƒdgZejdd kråefZeee jfZee je jfZd „Zn?efZeeee jfZeee je jfZd „Zd efd „ƒYZeƒZde fd„ƒYZ!de!fd„ƒYZ"de!fd„ƒYZ#dej$fd„ƒYZ%d„Z&e j'Z'e&ƒZ(ej)Z*ej+Z,ej-e,ƒZ.e j/Z0ej1Z2ej1Z3ej1Z4ej1Z5ej1Z6ej1Z7ej1Z8ej1Z9ej1Z:ej1Z;ej1Z<ej1Z=ej1Z>ej1Z?d„Z@ejdd kr’d„ZAd„ZBnd„ZAd„ZBd„ZCd„ZDd„ZEd„ZFd„ZGeHd „ZId!„ZJejKeJƒeHd"„ZLd#„ZMd$d%d&d'gZNd(„ZOd)„ZPd*„ZQdS(+s-ctypes library of mxnet and helper functions.i(tabsolute_importNi(tlibinfotdefaulttcategoryt MXNetErroricC@s |jdƒS(Nsutf-8(tdecode(tx((sJ/usr/local/lib/python2.7/site-packages/mxnet-1.2.1-py2.7.egg/mxnet/base.pyt+scC@s|S(N((R((sJ/usr/local/lib/python2.7/site-packages/mxnet-1.2.1-py2.7.egg/mxnet/base.pyR0st _NullTypecB@seZdZd„ZRS(sPlaceholder for argumentscC@sdS(Nt_Null((tself((sJ/usr/local/lib/python2.7/site-packages/mxnet-1.2.1-py2.7.egg/mxnet/base.pyt__repr__4s(t__name__t __module__t__doc__R (((sJ/usr/local/lib/python2.7/site-packages/mxnet-1.2.1-py2.7.egg/mxnet/base.pyR2scB@seZdZRS(s2Error that will be throwed by all mxnet functions.(R R R(((sJ/usr/local/lib/python2.7/site-packages/mxnet-1.2.1-py2.7.egg/mxnet/base.pyR9stNotImplementedForSymbolcB@s eZdZd„Zd„ZRS(s!Error: Not implemented for symbolcG@sTtt|ƒjƒ|j|_||_g|D]}tt|ƒƒ^q/|_dS(N( tsuperRt__init__R tfunctiontaliaststrttypetargs(R RRRta((sJ/usr/local/lib/python2.7/site-packages/mxnet-1.2.1-py2.7.egg/mxnet/base.pyR?s  cC@smdj|jƒ}|jr4|dj|jƒ7}n|jr_|djdj|jƒƒ7}n|d7}|S(Ns Function {}s (namely operator "{}")s with arguments ({})s, s= is not implemented for Symbol and only available in NDArray.(tformatRRRtjoin(R tmsg((sJ/usr/local/lib/python2.7/site-packages/mxnet-1.2.1-py2.7.egg/mxnet/base.pyt__str__Ds  " (R R RRR(((sJ/usr/local/lib/python2.7/site-packages/mxnet-1.2.1-py2.7.egg/mxnet/base.pyR=s tNotSupportedForSparseNDArraycB@s eZdZd„Zd„ZRS(s&Error: Not supported for SparseNDArraycG@sTtt|ƒjƒ|j|_||_g|D]}tt|ƒƒ^q/|_dS(N( RRRR RRRRR(R RRRR((sJ/usr/local/lib/python2.7/site-packages/mxnet-1.2.1-py2.7.egg/mxnet/base.pyROs  cC@smdj|jƒ}|jr4|dj|jƒ7}n|jr_|djdj|jƒƒ7}n|d7}|S(Ns Function {}s (namely operator "{}")s with arguments ({})s, sB is not supported for SparseNDArray and only available in NDArray.(RRRRR(R R((sJ/usr/local/lib/python2.7/site-packages/mxnet-1.2.1-py2.7.egg/mxnet/base.pyRTs  " (R R RRR(((sJ/usr/local/lib/python2.7/site-packages/mxnet-1.2.1-py2.7.egg/mxnet/base.pyRMs tMXCallbackListcB@sSeZdZdejfdejejejƒƒfdejejƒfgZRS(sBStructure that holds Callback information. Passed to CustomOpProp.t num_callbackst callbackstcontexts( R R Rtctypestc_inttPOINTERt CFUNCTYPEtc_void_pt_fields_(((sJ/usr/local/lib/python2.7/site-packages/mxnet-1.2.1-py2.7.egg/mxnet/base.pyR]s cC@s8tjƒ}tj|dtjƒ}tj|j_|S(s(Load library by searching possible path.i(Rt find_lib_pathR!tCDLLt RTLD_LOCALtc_char_ptMXGetLastErrortrestype(tlib_pathtlib((sJ/usr/local/lib/python2.7/site-packages/mxnet-1.2.1-py2.7.egg/mxnet/base.pyt _load_libfs cC@s+|dkr'tttjƒƒƒ‚ndS(séCheck the return value of C API call. This function will raise an exception when an error occurs. Wrap every API call with this function. Parameters ---------- ret : int return value from API calls. iN(Rtpy_strt_LIBR+(tret((sJ/usr/local/lib/python2.7/site-packages/mxnet-1.2.1-py2.7.egg/mxnet/base.pyt check_call‰s cC@s tj|ƒS(s‚Create ctypes char * from a Python string. Parameters ---------- string : string type Python string. Returns ------- str : c_char_p A char pointer that can be passed to C API. Examples -------- >>> x = mx.base.c_str("Hello, World") >>> print x.value Hello, World (R!R*(tstring((sJ/usr/local/lib/python2.7/site-packages/mxnet-1.2.1-py2.7.egg/mxnet/base.pytc_str™scC@s!tjt|ƒƒ}||(|S(s2Create ctypes const char ** from a list of Python strings. Parameters ---------- strings : list of string Python strings. Returns ------- (ctypes.c_char_p * len(strings)) A const char ** pointer that can be passed to C API. (R!R*tlen(tstringstarr((sJ/usr/local/lib/python2.7/site-packages/mxnet-1.2.1-py2.7.egg/mxnet/base.pyt c_str_array®s cC@stj|jdƒƒS(s†Create ctypes char * from a Python string. Parameters ---------- string : string type Python string. Returns ------- str : c_char_p A char pointer that can be passed to C API. Examples -------- >>> x = mx.base.c_str("Hello, World") >>> print(x.value) b"Hello, World" sutf-8(R!R*tencode(R4((sJ/usr/local/lib/python2.7/site-packages/mxnet-1.2.1-py2.7.egg/mxnet/base.pyR5ÀscC@s=tjt|ƒƒ}g|D]}|jdƒ^q|(|S(s2Create ctypes const char ** from a list of Python strings. Parameters ---------- strings : list of string Python strings. Returns ------- (ctypes.c_char_p * len(strings)) A const char ** pointer that can be passed to C API. sutf-8(R!R*R6R:(R7R8ts((sJ/usr/local/lib/python2.7/site-packages/mxnet-1.2.1-py2.7.egg/mxnet/base.pyR9Õs #cC@s|t|ƒƒ}||(|S(sµCreate ctypes array from a Python array. Parameters ---------- ctype : ctypes data type Data type of the array we want to convert to, such as mx_float. values : tuple or list Data content. Returns ------- out : ctypes array Created ctypes array. Examples -------- >>> x = mx.base.c_array(mx.base.mx_float, [1, 2, 3]) >>> print len(x) 3 >>> x[1] 2.0 (R6(tctypetvaluestout((sJ/usr/local/lib/python2.7/site-packages/mxnet-1.2.1-py2.7.egg/mxnet/base.pytc_arrayæscC@s|t|ƒj|ƒS(s-Create ctypes array from a Python buffer. For primitive types, using the buffer created with array.array is faster than a c_array call. Parameters ---------- ctype : ctypes data type Data type of the array we want to convert to, such as mx_float. buf : buffer type Data content. Returns ------- out : ctypes array Created ctypes array. Examples -------- >>> x = mx.base.c_array_buf(mx.base.mx_float, array.array('i', [1, 2, 3])) >>> print len(x) 3 >>> x[1] 2.0 (R6t from_buffer(R<tbuf((sJ/usr/local/lib/python2.7/site-packages/mxnet-1.2.1-py2.7.egg/mxnet/base.pyt c_array_bufscC@s7tjt|ƒƒ}g|D]}|j^q|(|S(sCreate ctypes const void ** from a list of MXNet objects with handles. Parameters ---------- objs : list of NDArray/Symbol. MXNet objects. Returns ------- (ctypes.c_void_p * len(objs)) A void ** pointer that can be passed to C API. (R!R%R6thandle(tobjsR8to((sJ/usr/local/lib/python2.7/site-packages/mxnet-1.2.1-py2.7.egg/mxnet/base.pytc_handle_arrays cC@stt|tjtjƒƒs*tdƒ‚nt|ƒ}tj|j|ƒ}tj|||ƒsptdƒ‚n|S(s$Convert ctypes pointer to buffer type. Parameters ---------- cptr : ctypes.POINTER(ctypes.c_char) Pointer to the raw memory region. length : int The length of the buffer. Returns ------- buffer : bytearray The raw byte memory buffer. sexpected char pointersmemmove failed( t isinstanceR!R#tc_chart TypeErrort bytearrayR@tmemmovet RuntimeError(tcptrtlengthtrestrptr((sJ/usr/local/lib/python2.7/site-packages/mxnet-1.2.1-py2.7.egg/mxnet/base.pyt ctypes2buffer0s cC@s†t|tjtƒƒs'tdƒ‚nd}x|D]}||9}q4Wt|jtj|jƒƒ}tj |dtj ƒj |ƒS(sdConvert a ctypes pointer to a numpy array. The resulting NumPy array shares the memory with the pointer. Parameters ---------- cptr : ctypes.POINTER(mx_float) pointer to the memory region shape : tuple Shape of target `NDArray`. Returns ------- out : numpy_array A numpy array : numpy array. sexpected float pointeritdtype( RGR!R#tmx_floatRLt from_addresst addressoftcontentstnpt frombuffertfloat32treshape(RMtshapetsizeR;tdbuffer((sJ/usr/local/lib/python2.7/site-packages/mxnet-1.2.1-py2.7.egg/mxnet/base.pytctypes2numpy_sharedGs c C@sÑtƒ}g}xšt|||ƒD]†\}}}||krI|rIq"n|dkr[q"n|j|ƒd||f} t|ƒdkr›| d|7} n|j| ƒq"Wddd} | dj|ƒ} | S( sŽBuild argument docs in python style. arg_names : list of str Argument names. arg_types : list of str Argument type information. arg_descs : list of str Argument description information. remove_dup : boolean, optional Whether remove duplication or not. Returns ------- docstr : str Python docstring of parameter sections. tnum_argss%s : %sis s Parameters s ---------- s%s s (tsettziptaddR6tappendR( t arg_namest arg_typest arg_descst remove_dupt param_keyst param_strtkeyt type_infotdescR2tdoc_str((sJ/usr/local/lib/python2.7/site-packages/mxnet-1.2.1-py2.7.egg/mxnet/base.pytbuild_param_docbs  "  cC@sttjƒƒdS(sNotify MXNet about a shutdown.N(R3R1tMXNotifyShutdown(((sJ/usr/local/lib/python2.7/site-packages/mxnet-1.2.1-py2.7.egg/mxnet/base.pyt_notify_shutdown‰scC@sÁd„}t|tƒr(tj|}nx’tj|ƒD]\}}tj|ƒrYq8ntj|ƒru||ƒntj|ƒr”||j ƒntj |ƒr8|r8t |t ƒq8q8WdS(s¿Append the definition position to each function contained in module. Examples -------- # Put the following codes at the end of a file add_fileline_to_docstring(__name__) cS@sŠ|jdksd|jkr"dStj|ƒ}|dkrAdSytj|ƒd}Wntk rldSX|jd||f7_dS(s"Add fileinto to a object. sFrom:Niÿÿÿÿs From:%s:%d(RtNonetinspectt getsourcefiletgetsourcelinestIOError(tobjtfnametline((sJ/usr/local/lib/python2.7/site-packages/mxnet-1.2.1-py2.7.egg/mxnet/base.pyt _add_fileline™s  N( RGRtsystmodulesRrt getmemberst isbuiltint isfunctiontismethodt__func__tisclasstadd_fileline_to_docstringtFalse(tmodulet incursiveRyt_Rv((sJ/usr/local/lib/python2.7/site-packages/mxnet-1.2.1-py2.7.egg/mxnet/base.pyR‚s  cC@s$t|ttfƒr|S|gSdS(sA utility function that converts the argument to a list if it is not already. Parameters ---------- obj : object Returns ------- If `obj` is a list or tuple, return it. Otherwise, return `[obj]` as a single-element list. N(RGtlistttuple(Rv((sJ/usr/local/lib/python2.7/site-packages/mxnet-1.2.1-py2.7.egg/mxnet/base.pyt_as_list´s t _contrib_t_linalg_t_sparse_t_image_cC@s(x!tD]}|j|ƒr|SqWdS(s™ Check whether the given op_name starts with any words in `_OP_NAME_PREFIX_LIST`. If found, return the prefix; else, return an empty string. t(t_OP_NAME_PREFIX_LISTt startswith(top_nametprefix((sJ/usr/local/lib/python2.7/site-packages/mxnet-1.2.1-py2.7.egg/mxnet/base.pyt_get_op_name_prefixÊs cC@sžtjtjƒƒ}tjƒ}ttjtj|ƒtj|ƒƒƒg}x.t|j ƒD]}|j t ||ƒƒq_Wt j d||f}t j d||f}d||f} t j | } i} x3tD]+} t j d||| dd!f| | s†                                           '   $  D