ó łµČ[c@@sŸdZddlmZddlZddlZddlZddlZddlZddlZddl Z ddl m Z dgZ y eeWnek r®eZeZnXeee je jfZeeee jfZefZejddkrd„Zn d „Zd „Zd „Zd efd „ƒYZeƒZ de!fd„ƒYZ"de"fd„ƒYZ#de"fd„ƒYZ$dej%fd„ƒYZ&defd„ƒYZ'de(fd„ƒYZ)d„Z*d„Z+d„Z,e j-Z-e,ƒZ.ej/Z0ej1Z2ej3e2ƒZ4e j5Z6ej7Z8ej7Z9ej7Z:ej7Z;ej7Z<ej7Z=ej7Z>ej7Z?ej7Z@ej7ZAej7ZBej7ZCej7ZDej7ZEej7ZFd„ZGejddkrŌd„ZHd„ZInd „ZHd!„ZId"„ZJd#„ZKd$„ZLd%„ZMd&„ZNeOd'„ZPd(„ZQejReQƒeOd)„ZSd*„ZTd+d,d-d.gZUd/„ZVd0„ZWd1„ZXejYejZj[_\ej7ejZj]_\dS(2s-ctypes library of mxnet and helper functions.i(tabsolute_importNi(tlibinfot MXNetErroricC@s |jdƒS(Nsutf-8(tdecode(tx((sJ/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/base.pyt6scC@s|S(N((R((sJ/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/base.pyR8scC@sZtjƒ}|dkr7tjjtjjdƒdƒStjjtjjdƒdƒSdS(s^ :return: default data directory depending on the platform and environment variables tWindowstAPPDATAtmxnett~s.mxnetN(tplatformtsystemtostpathtjointenvirontgett expanduser(R ((sJ/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/base.pytdata_dir_default;s  cC@stjdtƒƒS(se :return: data directory in the filesystem for storage, for example when downloading models t MXNET_HOME(R tgetenvR(((sJ/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/base.pytdata_dirGst _NullTypecB@seZdZd„ZRS(sPlaceholder for argumentscC@sdS(Nt_Null((tself((sJ/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/base.pyt__repr__Qs(t__name__t __module__t__doc__R(((sJ/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/base.pyROscB@seZdZRS(s2Error that will be throwed by all mxnet functions.(RRR(((sJ/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/base.pyRXstNotImplementedForSymbolcB@s eZdZd„Zd„ZRS(s!Error: Not implemented for symbolcG@sTtt|ƒjƒ|j|_||_g|D]}tt|ƒƒ^q/|_dS(N( tsuperRt__init__Rtfunctiontaliaststrttypetargs(RR R!R$ta((sJ/usr/local/lib/python2.7/site-packages/mxnet-1.3.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.(tformatR R!R$R(Rtmsg((sJ/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/base.pyt__str__es  " (RRRRR((((sJ/usr/local/lib/python2.7/site-packages/mxnet-1.3.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( RR)RRR R!R"R#R$(RR R!R$R%((sJ/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/base.pyRqs  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.(R&R R!R$R(RR'((sJ/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/base.pyR(ws  " (RRRRR((((sJ/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/base.pyR)os tMXCallbackListcB@sSeZdZdejfdejejejƒƒfdejejƒfgZRS(sBStructure that holds Callback information. Passed to CustomOpProp.t num_callbackst callbackstcontexts( RRRtctypestc_inttPOINTERt CFUNCTYPEtc_void_pt_fields_(((sJ/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/base.pyR*s t_MXClassPropertyDescriptorcB@s2eZdd„Zdd„Zd„Zd„ZRS(cC@s||_||_dS(N(tfgettfset(RR5R6((sJ/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/base.pyRŒs cC@s1|dkrt|ƒ}n|jj||ƒƒS(N(tNoneR#R5t__get__(Rtobjtclas((sJ/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/base.pyR8s cC@sb|jstd|jƒ‚ntj|ƒr=|}d}n t|ƒ}|jj||ƒ|ƒS(Ns*cannot use the setter: %s to set attribute(R6RRtinspecttisclassR7R#R8(RR9tvaluettype_((sJ/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/base.pyt__set__•s   cC@s1t|ttfƒs$t|ƒ}n||_|S(N(t isinstancet classmethodt staticmethodR6(Rtfunc((sJ/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/base.pytsetterŸs N(RRR7RR8R?RD(((sJ/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/base.pyR4‹s   t_MXClassPropertyMetaClasscB@seZd„ZRS(cC@sP|jj|ƒ}|r7t|tƒr7|j||ƒStt|ƒj||ƒS(N(t__dict__RR@R4R?RREt __setattr__(tclstkeyR=R9((sJ/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/base.pyRG§s(RRRG(((sJ/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/base.pyRE¦sc@s5dtf‡‡fd†ƒY}tj|ddiƒS(s%Create a base class with a metaclass.t metaclassc@s2eZ‡‡fd†Ze‡‡fd†ƒZRS(c@sˆ|ˆ|ƒS(N((RHtnamet this_basestd(tbasestmeta(sJ/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/base.pyt__new__øsc@sˆj|ˆƒS(N(t __prepare__(RHRKRL(RNRO(sJ/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/base.pyRQ»s(RRRPRARQ((RNRO(sJ/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/base.pyRJ¶sttemporary_class((R#RP(RORNRJ((RNROsJ/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/base.pytwith_metaclass±scC@s.t|ttfƒs$t|ƒ}nt|ƒS(N(R@RARBR4(RC((sJ/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/base.pyt classpropertyĀscC@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.3.1-py2.7.egg/mxnet/base.pyt _load_libÉs 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_LIBRY(tret((sJ/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/base.pyt check_callšs icC@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.RX(tstring((sJ/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/base.pytc_strscC@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.RXtlen(tstringstarr((sJ/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/base.pyt c_str_arrays 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.RXtencode(Rb((sJ/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/base.pyRc'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.RXRdRh(ReRfts((sJ/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/base.pyRg<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 (Rd(tctypetvaluestout((sJ/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/base.pytc_arrayNscC@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 (Rdt from_buffer(Rjtbuf((sJ/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/base.pyt c_array_bufkscC@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.R2Rdthandle(tobjsRfto((sJ/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/base.pytc_handle_arrayˆs 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( R@R.R0tc_chart TypeErrort bytearrayRntmemmovet RuntimeError(tcptrtlengthtrestrptr((sJ/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/base.pyt ctypes2bufferšs 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( R@R.R0tmx_floatRyt from_addresst addressoftcontentstnpt frombuffertfloat32treshape(RztshapetsizeRitdbuffer((sJ/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/base.pytctypes2numpy_shared²s 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 (tsettziptaddRdtappendR( t arg_namest arg_typest arg_descst remove_dupt param_keyst param_strRIt type_infotdescR`tdoc_str((sJ/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/base.pytbuild_param_docĶs  "  cC@sttjƒƒdS(sNotify MXNet about a shutdown.N(RaR_tMXNotifyShutdown(((sJ/usr/local/lib/python2.7/site-packages/mxnet-1.3.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(RR7R;t getsourcefiletgetsourcelinestIOError(R9tfnametline((sJ/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/base.pyt _add_filelines  N( R@R"tsystmodulesR;t getmemberst isbuiltint isfunctiontismethodt__func__R<tadd_fileline_to_docstringtFalse(tmodulet incursiveR¢t_R9((sJ/usr/local/lib/python2.7/site-packages/mxnet-1.3.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(R@tlistttuple(R9((sJ/usr/local/lib/python2.7/site-packages/mxnet-1.3.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.3.1-py2.7.egg/mxnet/base.pyt_get_op_name_prefix6s 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œ                                                 '   $  C U