ó —Àv]c@s¨dZddlZddlZddlZddlZddlmZmZd„Zd„Z d„Z d„Z d „Z d e fd „ƒYZed „Zd „ZdS(sgeneral utility functionsiÿÿÿÿNi(t_LIBt check_callcCsGtjddkr0ddlm}||ƒntj|dtƒdS(snCreate directories recursively if they don't exist. os.makedirs(exist_ok=True) is not available in Python2iiiÿÿÿÿ(tmkpathtexist_okN(tsyst version_infotdistutils.dir_utilRtostmakedirstTrue(tdR((s+/tmp/pip-install-Qvdv_2/mxnet/mxnet/util.pyRs cCs/tjƒ}ttjtj|ƒƒƒ|jS(N(tctypestc_intRRt MXGetGPUCounttbyreftvalue(tsize((s+/tmp/pip-install-Qvdv_2/mxnet/mxnet/util.pyt get_gpu_count%s cCsYtjdƒ}tjdƒ}ttj|tj|ƒtj|ƒƒƒ|j|jfS(Ni(R tc_uint64RRtMXGetGPUMemoryInformation64RR(t gpu_dev_idtfree_memt total_mem((s+/tmp/pip-install-Qvdv_2/mxnet/mxnet/util.pytget_gpu_memory+s+cCsAtjƒ}ttjtj|ƒtj|ƒƒƒt|jƒS(s  Turns on/off NumPy shape semantics, in which `()` represents the shape of scalar tensors, and tuples with `0` elements, for example, `(0,)`, `(1, 0, 2)`, represent the shapes of zero-size tensors. This is turned off by default for keeping backward compatibility. Please note that this is designed as an infrastructure for the incoming MXNet-NumPy operators. Legacy operators registered in the modules `mx.nd` and `mx.sym` are not guaranteed to behave like their counterparts in NumPy within this semantics. Parameters ---------- active : bool Indicates whether to turn on/off NumPy shape semantics. Returns ------- A bool value indicating the previous state of NumPy shape semantics. Example ------- >>> import mxnet as mx >>> prev_state = mx.set_np_shape(True) >>> print(prev_state) False >>> print(mx.is_np_shape()) True (R R RRtMXSetIsNumpyShapeRtboolR(tactivetprev((s+/tmp/pip-install-Qvdv_2/mxnet/mxnet/util.pyt set_np_shape2s (cCs/tjƒ}ttjtj|ƒƒƒ|jS(s8 Checks whether the NumPy shape semantics is currently turned on. In NumPy shape semantics, `()` represents the shape of scalar tensors, and tuples with `0` elements, for example, `(0,)`, `(1, 0, 2)`, represent the shapes of zero-size tensors. This is turned off by default for keeping backward compatibility. In the NumPy shape semantics, `-1` indicates an unknown size. For example, `(-1, 2, 2)` means that the size of the first dimension is unknown. Its size may be inferred during shape inference. Please note that this is designed as an infrastructure for the incoming MXNet-NumPy operators. Legacy operators registered in the modules `mx.nd` and `mx.sym` are not guaranteed to behave like their counterparts in NumPy within this semantics. Returns ------- A bool value indicating whether the NumPy shape semantics is currently on. Example ------- >>> import mxnet as mx >>> prev_state = mx.set_np_shape(True) >>> print(prev_state) False >>> print(mx.is_np_shape()) True (R tc_boolRRtMXIsNumpyShapeRR(tcurr((s+/tmp/pip-install-Qvdv_2/mxnet/mxnet/util.pyt is_np_shapeTs t_NumpyShapeScopecBs)eZdZd„Zd„Zd„ZRS(sšScope for managing NumPy shape semantics. In NumPy shape semantics, `()` represents the shape of scalar tensors, and tuples with `0` elements, for example, `(0,)`, `(1, 0, 2)`, represent the shapes of zero-size tensors. Do not use this class directly. Use `np_shape(active)` instead. Example:: with _NumpyShapeScope(True): y = model(x) backward([y]) cCs||_d|_dS(N(t_enter_is_np_shapetNonet_prev_is_np_shape(tselfR ((s+/tmp/pip-install-Qvdv_2/mxnet/mxnet/util.pyt__init__†s cCs(|jdk r$t|jƒ|_ndS(N(R"R#RR$(R%((s+/tmp/pip-install-Qvdv_2/mxnet/mxnet/util.pyt __enter__ŠscCs5|jdk r1|j|jkr1t|jƒndS(N(R"R#R$R(R%tptypeRttrace((s+/tmp/pip-install-Qvdv_2/mxnet/mxnet/util.pyt__exit__Žs!(t__name__t __module__t__doc__R&R'R*(((s+/tmp/pip-install-Qvdv_2/mxnet/mxnet/util.pyR!ws  cCs t|ƒS(sŽ Returns an activated/deactivated NumPy shape scope to be used in 'with' statement and captures code that needs the NumPy shape semantics, i.e. support of scalar and zero-size tensors. Please note that this is designed as an infrastructure for the incoming MXNet-NumPy operators. Legacy operators registered in the modules `mx.nd` and `mx.sym` are not guaranteed to behave like their counterparts in NumPy even within this scope. Parameters ---------- active : bool Indicates whether to activate NumPy-shape semantics. Returns ------- _NumpyShapeScope A scope object for wrapping the code w/ or w/o NumPy-shape semantics. Example:: with mx.np_shape(active=True): # A scalar tensor's shape is `()`, whose `ndim` is `0`. scalar = mx.nd.ones(shape=()) assert scalar.shape == () # If NumPy shape semantics is enabled, 0 in a shape means that # dimension contains zero elements. data = mx.sym.var("data", shape=(0, 2, 3)) ret = mx.sym.sin(data) arg_shapes, out_shapes, _ = ret.infer_shape() assert arg_shapes[0] == (0, 2, 3) assert out_shapes[0] == (0, 2, 3) # -1 means unknown shape dimension size in the new NumPy shape definition data = mx.sym.var("data", shape=(-1, 2, 3)) ret = mx.sym.sin(data) arg_shapes, out_shapes, _ = ret.infer_shape_partial() assert arg_shapes[0] == (-1, 2, 3) assert out_shapes[0] == (-1, 2, 3) # When a shape is completely unknown when NumPy shape semantics is on, it is # represented as `None` in Python. data = mx.sym.var("data") ret = mx.sym.sin(data) arg_shapes, out_shapes, _ = ret.infer_shape_partial() assert arg_shapes[0] is None assert out_shapes[0] is None with mx.np_shape(active=False): # 0 means unknown shape dimension size in the legacy shape definition. data = mx.sym.var("data", shape=(0, 2, 3)) ret = mx.sym.sin(data) arg_shapes, out_shapes, _ = ret.infer_shape_partial() assert arg_shapes[0] == (0, 2, 3) assert out_shapes[0] == (0, 2, 3) # When a shape is completely unknown in the legacy mode (default), its ndim is # equal to 0 and it is represented as `()` in Python. data = mx.sym.var("data") ret = mx.sym.sin(data) arg_shapes, out_shapes, _ = ret.infer_shape_partial() assert arg_shapes[0] == () assert out_shapes[0] == () (R!(R((s+/tmp/pip-install-Qvdv_2/mxnet/mxnet/util.pytnp_shape“sBcs"tjˆƒ‡fd†ƒ}|S(scWraps a function with an activated NumPy-shape scope. This ensures that the execution of the function is guaranteed with the support of scalar and zero-size tensors as in NumPy. Please note that this is designed as an infrastructure for the incoming MXNet-NumPy operators. Legacy operators registered in the modules `mx.nd` and `mx.sym` are not guaranteed to behave like their counterparts in NumPy even within this scope. Parameters ---------- func : a user-provided callable function to be scoped by the NumPy-shape semantics. Returns ------- Function A function for wrapping the user functions in the NumPy-shape semantics. Examples -------- >>> import mxnet as mx >>> @mx.use_np_shape ... def scalar_one(): ... return mx.nd.ones(()) ... >>> print(scalar_one()) cs'tdtƒˆ||ŽSWdQXdS(NR(R.R (targstkwargs(tfunc(s+/tmp/pip-install-Qvdv_2/mxnet/mxnet/util.pyt_with_np_shapeös(t functoolstwraps(R1R2((R1s+/tmp/pip-install-Qvdv_2/mxnet/mxnet/util.pyt use_np_shapeØs(R-R RRR3tbaseRRRRRRR tobjectR!R R.R5(((s+/tmp/pip-install-Qvdv_2/mxnet/mxnet/util.pyts       " # E