Create an empty array given shape and device Parameters ---------- shape : Union[tvm_ffi.Shape, Sequence[typing.SupportsInt]] The shape of the array. dtype : type or str The data type of the array. device : Device The device of the array. mem_scope
(shape, dtype="float32", device=None, mem_scope=None)
| 298 | |
| 299 | |
| 300 | def empty(shape, dtype="float32", device=None, mem_scope=None): |
| 301 | """Create an empty array given shape and device |
| 302 | |
| 303 | Parameters |
| 304 | ---------- |
| 305 | shape : Union[tvm_ffi.Shape, Sequence[typing.SupportsInt]] |
| 306 | The shape of the array. |
| 307 | |
| 308 | dtype : type or str |
| 309 | The data type of the array. |
| 310 | |
| 311 | device : Device |
| 312 | The device of the array. |
| 313 | |
| 314 | mem_scope : Optional[str] |
| 315 | The memory scope of the array. |
| 316 | |
| 317 | Returns |
| 318 | ------- |
| 319 | arr : tvm.runtime.Tensor |
| 320 | The array tvm supported. |
| 321 | """ |
| 322 | device = device or cpu() |
| 323 | if not isinstance(shape, tvm_ffi.Shape): |
| 324 | shape = tvm_ffi.Shape([int(dim) for dim in shape]) |
| 325 | dtype = tvm_ffi.dtype(dtype) |
| 326 | arr = _ffi_api.TVMTensorAllocWithScope(shape, dtype, device, mem_scope) |
| 327 | return arr |
| 328 | |
| 329 | |
| 330 | def tensor(arr, device=None, mem_scope=None): |