tvm.runtime.ndarray

Runtime NDArray API

class tvm.nd.NDArray

Lightweight NDArray class of TVM runtime.

Strictly this is only an Array Container (a buffer object) No arthimetic operations are defined. All operations are performed by TVM functions.

The goal is not to re-build yet another array library. Instead, this is a minimal data structure to demonstrate how can we use TVM in existing project which might have their own array containers.

property dtype

Type of this array

property ctx

context of this array

property context

context of this array

same_as(other)

Check object identity equality

Parameters

other (object) – The other object to compare to

Returns

same – Whether other is same as self.

Return type

bool

copyfrom(source_array)

Peform an synchronize copy from the array.

Parameters

source_array (array_like) – The data source we should like to copy from.

Returns

arr – Reference to self.

Return type

NDArray

asnumpy()

Convert this array to numpy array

Returns

np_arr – The corresponding numpy array.

Return type

numpy.ndarray

copyto(target)

Copy array to target

Parameters

target (NDArray) – The target array to be copied, must have same shape as this array.

shape

Shape of this array

to_dlpack()

Produce an array from a DLPack Tensor without copying memory

Returns

dlpack

Return type

DLPack tensor view of the array data

tvm.nd.array(arr, ctx=cpu(0))

Create an array from source arr.

Parameters
  • arr (numpy.ndarray) – The array to be copied from

  • ctx (TVMContext, optional) – The device context to create the array

Returns

ret – The created array

Return type

NDArray

tvm.nd.empty(shape, dtype='float32', ctx=cpu(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 – The array tvm supported.

Return type

tvm.nd.NDArray