pub struct TensorView<'a> { /* private fields */ }Expand description
A non-owning view of a tensor: a pointer to a DLTensor.
A function argument of this type accepts both a borrowed DLTensor* (type
index kTVMFFIDLTensorPtr, how C callers pass tensors) and a Tensor
object (type index kTVMFFITensor), and is passed on as a DLTensor*.
Prefer it over Tensor for arguments of exported functions that only
read a tensor’s metadata and data.
The view does not keep anything alive: its lifetime 'a ties it to what
it borrows. For the same reason, a view cannot be moved into an owned
Any, which could outlive it; use Tensor instead.
Neither misuse compiles:
use tvm_ffi::{Tensor, TensorView};
let view = {
let tensor = Tensor::from_slice(&[1.0_f32], &[1]).unwrap();
TensorView::from(&tensor)
};
view.ndim();use tvm_ffi::{Any, Tensor, TensorView};
let tensor = Tensor::from_slice(&[1.0_f32], &[1]).unwrap();
let _ = Any::from(TensorView::from(&tensor));A view received as an argument of an exported function is valid only
during the call. The function may name any lifetime for it,
TensorView<'static> included, so the compiler does not stop it from
being kept past the call; doing so is undefined behavior.
Implementations§
Source§impl<'a> TensorView<'a>
impl<'a> TensorView<'a>
Sourcepub fn data_ptr(&self) -> *mut c_void
pub fn data_ptr(&self) -> *mut c_void
The data pointer, as in the DLTensor; byte_offset is not applied.
Sourcepub fn dtype(&self) -> DLDataType
pub fn dtype(&self) -> DLDataType
The element type.
Sourcepub fn strides(&self) -> &'a [i64]
pub fn strides(&self) -> &'a [i64]
The strides, in elements.
§Panics
If the DLTensor has null strides and at least one dimension, which
DLPack forbids since v1.2.
Sourcepub fn is_contiguous(&self) -> bool
pub fn is_contiguous(&self) -> bool
Whether the elements are laid out in row-major order without gaps: a
DLTensor with null strides or no elements is contiguous, and a
dimension of extent 1 may have any stride.
Trait Implementations§
Source§impl<'a> Clone for TensorView<'a>
impl<'a> Clone for TensorView<'a>
Source§fn clone(&self) -> TensorView<'a>
fn clone(&self) -> TensorView<'a>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more