def empty(shape, dtype="float32", ctx=context(1, 0)): """Create an empty array given shape and device Parameters ---------- shape : tuple of int The shape of the array dtype : type or str The data type of the array. ctx : TVMContext The context of the array Returns ------- arr : tvm.nd.NDArray The array tvm supported. """ shape = c_array(tvm_shape_index_t, shape) ndim = ctypes.c_int(len(shape)) handle = TVMArrayHandle() dtype = DataType(dtype) check_call( _LIB.TVMArrayAlloc(shape, ndim, ctypes.c_int(dtype.type_code), ctypes.c_int(dtype.bits), ctypes.c_int(dtype.lanes), ctx.device_type, ctx.device_id, ctypes.byref(handle))) return _make_array(handle, False, False)
def numpyasarray(np_data): """Return a TVMArray representation of a numpy array.""" data = np_data assert data.flags["C_CONTIGUOUS"] arr = TVMArray() shape = c_array(tvm_shape_index_t, data.shape) arr.data = data.ctypes.data_as(ctypes.c_void_p) arr.shape = shape arr.strides = None arr.dtype = DataType(np.dtype(data.dtype).name) arr.ndim = data.ndim # CPU device arr.device = device(1, 0) return arr, shape