cpu¶
-
cpu(device_id=0)¶ 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().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.
Examples
>>> with mx.cpu(): ... cpu_array = mx.nd.ones((2, 3)) >>> cpu_array.context cpu(0) >>> cpu_array = mx.nd.ones((2, 3), ctx=mx.cpu()) >>> cpu_array.context cpu(0)