σ šΔοYc@@scdZddlmZdefd„ƒYZeddƒe_dd„Zdd„Zd„Zd S( s Context management API of mxnet.i(tabsolute_importtContextcB@s›eZdZdZidd6dd6dd6Zidd6dd6dd6Zdd„Zed „ƒZ d „Z d „Z d „Z d „Z d„Zd„ZRS(s&Constructs a context. MXNet can run operations on CPU and different GPUs. A context describes the device type and ID on which computation should be carried on. One can use mx.cpu and mx.gpu for short. See also ---------- `How to run MXNet on multiple CPU/GPUs ` for more details. Parameters ---------- device_type : {'cpu', 'gpu'} or Context. String representing the device type. device_id : int (default=0) The device id of the device, needed for GPU. Note ---- Context can also be used as a way to change the default context. Examples -------- >>> # array on cpu >>> cpu_array = mx.nd.ones((2, 3)) >>> # switch default context to GPU(2) >>> with mx.Context(mx.gpu(2)): ... gpu_array = mx.nd.ones((2, 3)) >>> gpu_array.context gpu(2) One can also explicitly specify the context when creating an array. >>> gpu_array = mx.nd.ones((2, 3), mx.gpu(1)) >>> gpu_array.context gpu(1) tcpuitgpuit cpu_pinnediicC@sPt|tƒr*|j|_|j|_ntj||_||_d|_dS(N(t isinstanceRt device_typeidt device_idt devstr2typetNonet_old_ctx(tselft device_typeR((s-build/bdist.linux-armv7l/egg/mxnet/context.pyt__init__Cs   cC@stj|jS(sReturns the device type of current context. Examples ------- >>> mx.context.current_context().device_type 'cpu' >>> mx.current_context().device_type 'cpu' Returns ------- device_type : str (Rt devtype2strR(R ((s-build/bdist.linux-armv7l/egg/mxnet/context.pyR LscC@st|j|jfƒS(s3Compute hash value of context for dictionary lookup(thashRR(R ((s-build/bdist.linux-armv7l/egg/mxnet/context.pyt__hash__]scC@s1t|tƒo0|j|jko0|j|jkS(soCompares two contexts. Two contexts are equal if they have the same device type and device id. (RRRR(R tother((s-build/bdist.linux-armv7l/egg/mxnet/context.pyt__eq__ascC@sd|j|jfS(Ns%s(%d)(R R(R ((s-build/bdist.linux-armv7l/egg/mxnet/context.pyt__str__iscC@s |jƒS(N(R(R ((s-build/bdist.linux-armv7l/egg/mxnet/context.pyt__repr__lscC@stj|_|t_|S(N(Rt default_ctxR (R ((s-build/bdist.linux-armv7l/egg/mxnet/context.pyt __enter__os  cC@s|jt_dS(N(R RR(R tptypetvaluettrace((s-build/bdist.linux-armv7l/egg/mxnet/context.pyt__exit__tsN(t__name__t __module__t__doc__R RRRR tpropertyR RRRRRR(((s-build/bdist.linux-armv7l/egg/mxnet/context.pyRs(      RcC@s td|ƒS(sΙReturns a CPU context. This function is a short cut for ``Context('cpu', device_id)``. For most operations, when no context is specified, the default context is `cpu()`. Examples ---------- >>> with mx.Context('cpu', 1): ... cpu_array = mx.nd.ones((2, 3)) >>> cpu_array.context cpu(1) >>> with mx.cpu(1): ... cpu_array = mx.nd.ones((2, 3)) >>> cpu_array.context cpu(1) Parameters ---------- device_id : int, optional The device id of the device. `device_id` is not needed for CPU. This is included to make interface compatible with GPU. Returns ------- context : Context The corresponding CPU context. R(R(R((s-build/bdist.linux-armv7l/egg/mxnet/context.pyR{scC@s td|ƒS(sYReturns a GPU context. This function is a short cut for Context('gpu', device_id). The K GPUs on a node are typically numbered as 0,...,K-1. Examples ---------- >>> with mx.Context('gpu', 1): ... gpu_array = mx.nd.ones((2, 3)) >>> gpu_array.context gpu(1) >>> with mx.gpu(1): ... gpu_array = mx.nd.ones((2, 3)) >>> gpu_array.context gpu(1) Parameters ---------- device_id : int, optional The device id of the device, needed for GPU. Returns ------- context : Context The corresponding GPU context. R(R(R((s-build/bdist.linux-armv7l/egg/mxnet/context.pyRšscC@stjS(s6Returns the current context. By default, `mx.cpu()` is used for all the computations and it can be overridden by using `with mx.Context(x)` statement where x can be cpu(device_id) or gpu(device_id). Examples ------- >>> mx.current_context() cpu(0) >>> with mx.Context('gpu', 1): # Context changed in `with` block. ... mx.current_context() # Computation done here will be on gpu(1). ... gpu(1) >>> mx.current_context() # Back to default context. cpu(0) Returns ------- default_ctx : Context (RR(((s-build/bdist.linux-armv7l/egg/mxnet/context.pytcurrent_contextΈsN( Rt __future__RtobjectRRRRR(((s-build/bdist.linux-armv7l/egg/mxnet/context.pyts b