Create an tensor from source arr. Parameters ---------- arr : numpy.ndarray The array to be copied from device : Device, optional The device to create the array mem_scope : Optional[str] The memory scope of the array Returns ------- ret : T
(arr, device=None, mem_scope=None)
| 328 | |
| 329 | |
| 330 | def tensor(arr, device=None, mem_scope=None): |
| 331 | """Create an tensor from source arr. |
| 332 | |
| 333 | Parameters |
| 334 | ---------- |
| 335 | arr : numpy.ndarray |
| 336 | The array to be copied from |
| 337 | |
| 338 | device : Device, optional |
| 339 | The device to create the array |
| 340 | |
| 341 | mem_scope : Optional[str] |
| 342 | The memory scope of the array |
| 343 | |
| 344 | Returns |
| 345 | ------- |
| 346 | ret : Tensor |
| 347 | The created array |
| 348 | """ |
| 349 | device = device or cpu() |
| 350 | |
| 351 | if not isinstance(arr, np.ndarray | Tensor): |
| 352 | arr = np.asarray(arr) |
| 353 | return empty(arr.shape, arr.dtype, device, mem_scope).copyfrom(arr) |
| 354 | |
| 355 | |
| 356 | def cpu(dev_id=0): |
no test coverage detected
searching dependent graphs…