Struct tvm::runtime::NDArray[][src]

pub struct NDArray(_);

Implementations

Returns the shape of the NDArray.

Returns the shape of the NDArray as a &usize

On 64-bit platforms, this is zero-cost and uses the shape from the DLTensor. On other platforms, this copies into a buffer.

Returns the strides of the underlying NDArray.

Returns the strides of the NDArray as a &usize

On 64-bit platforms, this is zero-cost and uses the strides from the DLTensor. On other platforms, this copies into a buffer.

Returns true if the tensor is empty

Returns the total number of entries of the NDArray.

Returns the total bytes taken up by the data. This is equal to nd.len() * nd.dtype().itemsize()

Returns the device which the NDArray was defined.

Returns the type of the entries of the NDArray.

Returns the number of dimensions of the NDArray.

Shows whether the underlying ndarray is contiguous in memory or not.

Flattens the NDArray to a Vec of the same type in cpu.

Example
let mut shape = [4];
let mut data = vec![1i32, 2, 3, 4];
let dev = Device::cpu(0);
let mut ndarray = NDArray::empty(&mut shape, dev, DataType::from_str("int32").unwrap());
ndarray.copy_from_buffer(&mut data);
assert_eq!(ndarray.shape(), shape);
assert_eq!(ndarray.to_vec::<i32>().unwrap(), data);

Converts the NDArray to ByteArray.

Creates an NDArray from a mutable buffer of types i32, u32 or f32 in cpu.

Example
let shape = &mut [2];
let mut data = vec![1f32, 2.0];
let dev = Device::cpu(0);
let mut ndarray = NDArray::empty(shape, dev, DataType::from_str("int32").unwrap());
ndarray.copy_from_buffer(&mut data);

Note: if something goes wrong during the copy, it will panic from TVM side. See TVMArrayCopyFromBytes in include/tvm/runtime/c_runtime_api.h.

Copies the NDArray to another target NDArray.

Copies the NDArray to a target device.

Converts a Rust’s ndarray to TVM NDArray.

Allocates and creates an empty NDArray given the shape, device and dtype.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

The resulting type after dereferencing.

Dereferences the value.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more