Struct tvm::runtime::NDArray [−][src]
pub struct NDArray(_);
Implementations
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 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 the total bytes taken up by the data.
This is equal to nd.len() * nd.dtype().itemsize()
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
.
pub fn fill_from_iter<T, I>(&mut self, iter: I) where
T: Num32,
I: ExactSizeIterator<Item = T>,
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
Performs the conversion.
Performs the conversion.
type Object = NDArrayContainer
fn downcast<U>(self) -> Result<U, Error> where
U: IsObjectRef,
<U as IsObjectRef>::Object: AsRef<Self::Object>,
Auto Trait Implementations
impl RefUnwindSafe for NDArray
impl UnwindSafe for NDArray
Blanket Implementations
Mutably borrows from an owned value. Read more
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