ó šÄïYc@@sdZddlmZddlZddlZddlZddlZddlZddlZ ddl m Z ej dde ƒdgZejdd krÊefZeee jfZeZd „Zn3efZeeee jfZeefZd „Zd efd „ƒYZeƒZdefd„ƒYZdefd„ƒYZdej fd„ƒYZ!d„Z"e j#Z#e"ƒZ$ej%Z&ej'Z(ej)e(ƒZ*e j+Z,ej-Z.ej-Z/ej-Z0ej-Z1ej-Z2ej-Z3ej-Z4ej-Z5ej-Z6ej-Z7ej-Z8d„Z9ejdd kr1d„Z:n d„Z:d„Z;d„Z<d„Z=e>d„Z?d„Z@ejAe@ƒe>d„ZBd„ZCdS(s-ctypes library of mxnet and helper functions.i(tabsolute_importNi(tlibinfotdefaulttcategoryt MXNetErroricC@s |jdƒS(Nsutf-8(tdecode(tx((s*build/bdist.linux-armv7l/egg/mxnet/base.pyt*scC@s|S(N((R((s*build/bdist.linux-armv7l/egg/mxnet/base.pyR/st _NullTypecB@seZdZd„ZRS(sPlaceholder for argumentscC@sdS(Nt_Null((tself((s*build/bdist.linux-armv7l/egg/mxnet/base.pyt__repr__3s(t__name__t __module__t__doc__R (((s*build/bdist.linux-armv7l/egg/mxnet/base.pyR1scB@seZdZRS(s2Error that will be throwed by all mxnet functions.(R R R(((s*build/bdist.linux-armv7l/egg/mxnet/base.pyR8stNotImplementedForSymbolcB@seZd„Zd„ZRS(cG@sTtt|ƒjƒ|j|_||_g|D]}tt|ƒƒ^q/|_dS(N( tsuperRt__init__R tfunctiontaliaststrttypetargs(R RRRta((s*build/bdist.linux-armv7l/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((s*build/bdist.linux-armv7l/egg/mxnet/base.pyt__str__Bs  " (R R RR(((s*build/bdist.linux-armv7l/egg/mxnet/base.pyR<s tMXCallbackListcB@sSeZdZdejfdejejejƒƒfdejejƒfgZRS(sBStructure that holds Callback information. Passed to CustomOpProp.t num_callbackst callbackstcontexts( R R Rtctypestc_inttPOINTERt CFUNCTYPEtc_void_pt_fields_(((s*build/bdist.linux-armv7l/egg/mxnet/base.pyRLs 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((s*build/bdist.linux-armv7l/egg/mxnet/base.pyt _load_libUs 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((s*build/bdist.linux-armv7l/egg/mxnet/base.pyt check_callus 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((s*build/bdist.linux-armv7l/egg/mxnet/base.pytc_str„scC@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 Hello, World sutf-8(R R)tencode(R3((s*build/bdist.linux-armv7l/egg/mxnet/base.pyR4™scC@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 (tlen(tctypetvalues((s*build/bdist.linux-armv7l/egg/mxnet/base.pytc_array¯scC@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 bytearrayt from_buffertmemmovet RuntimeError(tcptrtlengthtrestrptr((s*build/bdist.linux-armv7l/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 R"tmx_floatR@t from_addresst addressoftcontentstnpt frombuffertfloat32treshape(RAtshapetsizetstdbuffer((s*build/bdist.linux-armv7l/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 (tsettziptaddR6tappendR( t arg_namest arg_typest arg_descst remove_dupt param_keyst param_strtkeyt type_infotdescR1tdoc_str((s*build/bdist.linux-armv7l/egg/mxnet/base.pytbuild_param_docûs  "  cC@sttjƒƒdS(sNotify MXNet about a shutdown.N(R2R0tMXNotifyShutdown(((s*build/bdist.linux-armv7l/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((s*build/bdist.linux-armv7l/egg/mxnet/base.pyt _add_fileline1s  N( R:RtsystmodulesRgt getmemberst isbuiltint isfunctiontismethodt__func__tisclasstadd_fileline_to_docstringtFalse(tmodulet incursiveRnt_Rk((s*build/bdist.linux-armv7l/egg/mxnet/base.pyRw(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(Rk((s*build/bdist.linux-armv7l/egg/mxnet/base.pyt_as_listKs (DRt __future__RRoR tatexittwarningsRgtnumpyRKtRtfilterwarningstDeprecationWarningt__all__t version_infoRt string_typestfloattinttgenerict numeric_typest integer_typesR/t basestringtlongtobjectRR t ExceptionRRt StructureRR.t __version__R0tc_uinttmx_uinttc_floatRGR"t mx_float_pRMt mx_real_tR$t NDArrayHandletFunctionHandletOpHandletCachedOpHandlet SymbolHandletExecutorHandletDataIterCreatorHandletDataIterHandlet KVStoreHandletRecordIOHandlet RtcHandleR2R4R9RERStTrueRcRetregisterRwR~(((s*build/bdist.linux-armv7l/egg/mxnet/base.pytsl                                    '   #