v]c@@sdZddlmZddlZddlZddlZddlZddlZddlZddl Z ddl m Z dgZ y eeWnek reZeZnXeee je jfZeeee jfZefZejddkrdZn d Zd Zd Zd efd YZeZ de!fdYZ"de"fdYZ#de"fdYZ$dej%fdYZ&defdYZ'de(fdYZ)dZ*dZ+dZ,e j-Z-e,Z.ej/Z0ej1Z2ej3Z4ej5e4Z6e j7Z8ej9Z:ej9Z;ej9Z<ej9Z=ej9Z>ej9Z?ej9Z@ej9ZAej9ZBej9ZCej9ZDej9ZEej9ZFej9ZGej9ZHdZIejddkrdZJdZKnd ZJd!ZKd"ZLd#ZMd$ZNd%ZOd&ZPeQd'ZRd(ZSejTeSeQd)ZUd*ZVd+d,d-d.d/gZWd0ZXd1ZYd2ZZej[ej\j]_^ej9ej\j__^dS(3s-ctypes library of mxnet and helper functions.i(tabsolute_importNi(tlibinfot MXNetErroricC@s |jdS(Nsutf-8(tdecode(tx((s+/tmp/pip-install-Qvdv_2/mxnet/mxnet/base.pyt6tcC@s|S(N((R((s+/tmp/pip-install-Qvdv_2/mxnet/mxnet/base.pyR8RcC@sZtj}|dkr7tjjtjjddStjjtjjddSdS(s^ :return: default data directory depending on the platform and environment variables tWindowstAPPDATAtmxnett~s.mxnetN(tplatformtsystemtostpathtjointenvirontgett expanduser(R ((s+/tmp/pip-install-Qvdv_2/mxnet/mxnet/base.pytdata_dir_default;s  cC@stjdtS(se :return: data directory in the filesystem for storage, for example when downloading models t MXNET_HOME(R tgetenvR(((s+/tmp/pip-install-Qvdv_2/mxnet/mxnet/base.pytdata_dirGst _NullTypecB@seZdZdZRS(sPlaceholder for argumentscC@sdS(Nt_Null((tself((s+/tmp/pip-install-Qvdv_2/mxnet/mxnet/base.pyt__repr__Qs(t__name__t __module__t__doc__R(((s+/tmp/pip-install-Qvdv_2/mxnet/mxnet/base.pyROscB@seZdZRS(s2Error that will be throwed by all mxnet functions.(RRR(((s+/tmp/pip-install-Qvdv_2/mxnet/mxnet/base.pyRXstNotImplementedForSymbolcB@s eZdZdZdZRS(s!Error: Not implemented for symbolcG@sTtt|j|j|_||_g|D]}tt|^q/|_dS(N( tsuperRt__init__Rtfunctiontaliaststrttypetargs(RR!R"R%ta((s+/tmp/pip-install-Qvdv_2/mxnet/mxnet/base.pyR _s  cC@smdj|j}|jr4|dj|j7}n|jr_|djdj|j7}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((s+/tmp/pip-install-Qvdv_2/mxnet/mxnet/base.pyt__str__es  " (RRRR R)(((s+/tmp/pip-install-Qvdv_2/mxnet/mxnet/base.pyR]s tNotSupportedForSparseNDArraycB@s eZdZdZdZRS(s&Error: Not supported for SparseNDArraycG@sTtt|j|j|_||_g|D]}tt|^q/|_dS(N( RR*R RR!R"R#R$R%(RR!R"R%R&((s+/tmp/pip-install-Qvdv_2/mxnet/mxnet/base.pyR qs  cC@smdj|j}|jr4|dj|j7}n|jr_|djdj|j7}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(((s+/tmp/pip-install-Qvdv_2/mxnet/mxnet/base.pyR)ws  " (RRRR R)(((s+/tmp/pip-install-Qvdv_2/mxnet/mxnet/base.pyR*os tMXCallbackListcB@sSeZdZdejfdejejejfdejejfgZRS(sBStructure that holds Callback information. Passed to CustomOpProp.t num_callbackst callbackstcontexts( RRRtctypestc_inttPOINTERt CFUNCTYPEtc_void_pt_fields_(((s+/tmp/pip-install-Qvdv_2/mxnet/mxnet/base.pyR+s t_MXClassPropertyDescriptorcB@s2eZddZddZdZdZRS(cC@s||_||_dS(N(tfgettfset(RR6R7((s+/tmp/pip-install-Qvdv_2/mxnet/mxnet/base.pyR s cC@s1|dkrt|}n|jj||S(N(tNoneR$R6t__get__(Rtobjtclas((s+/tmp/pip-install-Qvdv_2/mxnet/mxnet/base.pyR9s cC@sb|jstd|jntj|r=|}d}n t|}|jj|||S(Ns*cannot use the setter: %s to set attribute(R7RRtinspecttisclassR8R$R9(RR:tvaluettype_((s+/tmp/pip-install-Qvdv_2/mxnet/mxnet/base.pyt__set__s   cC@s1t|ttfs$t|}n||_|S(N(t isinstancet classmethodt staticmethodR7(Rtfunc((s+/tmp/pip-install-Qvdv_2/mxnet/mxnet/base.pytsetters N(RRR8R R9R@RE(((s+/tmp/pip-install-Qvdv_2/mxnet/mxnet/base.pyR5s   t_MXClassPropertyMetaClasscB@seZdZRS(cC@sP|jj|}|r7t|tr7|j||Stt|j||S(N(t__dict__RRAR5R@RRFt __setattr__(tclstkeyR>R:((s+/tmp/pip-install-Qvdv_2/mxnet/mxnet/base.pyRHs(RRRH(((s+/tmp/pip-install-Qvdv_2/mxnet/mxnet/base.pyRFsc@s5dtffdY}tj|ddiS(s%Create a base class with a metaclass.t metaclassc@s2eZfdZefdZRS(c@s||S(N((RItnamet this_basestd(tbasestmeta(s+/tmp/pip-install-Qvdv_2/mxnet/mxnet/base.pyt__new__sc@sj|S(N(t __prepare__(RIRLRM(RORP(s+/tmp/pip-install-Qvdv_2/mxnet/mxnet/base.pyRRs(RRRQRBRR((RORP(s+/tmp/pip-install-Qvdv_2/mxnet/mxnet/base.pyRKsttemporary_class((R$RQ(RPRORK((RORPs+/tmp/pip-install-Qvdv_2/mxnet/mxnet/base.pytwith_metaclassscC@s.t|ttfs$t|}nt|S(N(RARBRCR5(RD((s+/tmp/pip-install-Qvdv_2/mxnet/mxnet/base.pyt classpropertyscC@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+/tmp/pip-install-Qvdv_2/mxnet/mxnet/base.pyt _load_libs cC@s+|dkr'tttjndS(sCheck 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_LIBRZ(tret((s+/tmp/pip-install-Qvdv_2/mxnet/mxnet/base.pyt check_calls icC@s tj|S(sCreate 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/RY(tstring((s+/tmp/pip-install-Qvdv_2/mxnet/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/RYtlen(tstringstarr((s+/tmp/pip-install-Qvdv_2/mxnet/mxnet/base.pyt c_str_arrays cC@stj|jdS(sCreate 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/RYtencode(Rc((s+/tmp/pip-install-Qvdv_2/mxnet/mxnet/base.pyRd(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/RYReRi(RfRgts((s+/tmp/pip-install-Qvdv_2/mxnet/mxnet/base.pyRh=s #cC@s|t|}||(|S(sCreate 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 (Re(tctypetvaluestout((s+/tmp/pip-install-Qvdv_2/mxnet/mxnet/base.pytc_arrayOscC@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 (Ret from_buffer(Rktbuf((s+/tmp/pip-install-Qvdv_2/mxnet/mxnet/base.pyt c_array_buflscC@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/R3Rethandle(tobjsRgto((s+/tmp/pip-install-Qvdv_2/mxnet/mxnet/base.pytc_handle_arrays cC@stt|tjtjs*tdnt|}tj|j|}tj|||sptdn|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( RAR/R1tc_chart TypeErrort bytearrayRotmemmovet RuntimeError(tcptrtlengthtrestrptr((s+/tmp/pip-install-Qvdv_2/mxnet/mxnet/base.pyt ctypes2buffers cC@st|tjts'tdnd}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( RAR/R1tmx_floatRzt from_addresst addressoftcontentst_npt frombuffertfloat32treshape(R{tshapetsizeRjtdbuffer((s+/tmp/pip-install-Qvdv_2/mxnet/mxnet/base.pytctypes2numpy_shareds c C@st}g}xt|||D]\}}}||krI|rIq"n|dkr[q"n|j|d||f} t|dkr| d|7} n|j| q"Wddd} | dj|} | S( sBuild 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 (tsettziptaddRetappendR( t arg_namest arg_typest arg_descst remove_dupt param_keyst param_strRJt type_infotdescRatdoc_str((s+/tmp/pip-install-Qvdv_2/mxnet/mxnet/base.pytbuild_param_docs  "  cC@sttjdS(sNotify MXNet about a shutdown.N(RbR`tMXNotifyShutdown(((s+/tmp/pip-install-Qvdv_2/mxnet/mxnet/base.pyt_notify_shutdownscC@sd}t|tr(tj|}nxtj|D]\}}tj|rYq8ntj|ru||ntj|r||j ntj |r8|r8t |t q8q8WdS(sAppend 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:Nis From:%s:%d(RR8R<t getsourcefiletgetsourcelinestIOError(R:tfnametline((s+/tmp/pip-install-Qvdv_2/mxnet/mxnet/base.pyt _add_filelines  N( RAR#tsystmodulesR<t getmemberst isbuiltint isfunctiontismethodt__func__R=tadd_fileline_to_docstringtFalse(tmodulet incursiveRt_R:((s+/tmp/pip-install-Qvdv_2/mxnet/mxnet/base.pyRs  cC@s$t|ttfr|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(RAtlistttuple(R:((s+/tmp/pip-install-Qvdv_2/mxnet/mxnet/base.pyt_as_list!s t _contrib_t_linalg_t_sparse_t_image_t_random_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. R(t_OP_NAME_PREFIX_LISTt startswith(top_nametprefix((s+/tmp/pip-install-Qvdv_2/mxnet/mxnet/base.pyt_get_op_name_prefix7s cC@stjtj}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| | RR_RRRtOpHandlet NNGetOpHandleRdRRetendswithRRtsetattrRt__all__(troot_namespacet module_namet make_op_functplistRtop_namestit module_optmodule_internaltcontrib_module_name_oldtcontrib_module_oldtsubmodule_dicttop_name_prefixRLthdltmodule_name_localt func_namet cur_moduleR!((s+/tmp/pip-install-Qvdv_2/mxnet/mxnet/base.pyt_init_op_moduleCsV   )  %       % cC@sld}d}tjtj}tj}ttjtj|tj|g}x.t|j D]}|j t ||qqW|d||f} g} |d||f} g} i} x8t D]0}|d|||dd!fgf| |RR_RRRRdRReRtTrueRR RRltclose(RRtop_code_gen_funcRRRRRRtmodule_op_filet module_op_alltmodule_internal_filetmodule_internal_allRRRLRRtcur_module_filetcur_module_alltcodeRt submodule_ft submodule_all((s+/tmp/pip-install-Qvdv_2/mxnet/mxnet/base.pyt_generate_op_module_signaturesT     "  %       (`Rt __future__RtatexitR/R RR<R tnumpyRRRRt basestringtlongt NameErrorR#tinttint32tint64t integer_typestfloattgenerict numeric_typest string_typest version_infoR_RRtobjectRRt ExceptionRRR*t StructureR+R5R$RFRTRUR^t __version__R`R0tmx_intRtmx_uinttc_floatRR1t mx_float_pRt mx_real_tR3t NDArrayHandletFunctionHandleRtCachedOpHandlet SymbolHandletExecutorHandletDataIterCreatorHandletDataIterHandlet KVStoreHandletRecordIOHandlet RtcHandletCudaModuleHandletCudaKernelHandlet ProfileHandlet DLPackHandleRbRdRhRnRqRuRRRRRtregisterRRRRRRt py_objectt pythonapit PyCapsule_NewR[tPyCapsule_GetPointer(((s+/tmp/pip-install-Qvdv_2/mxnet/mxnet/base.pyts                                                  '   $  G U