pub struct TensorView { /* private fields */ }Expand description
A non-owning view of a tensor: a pointer to a DLTensor.
This mirrors tvm::ffi::TensorView in C++. A function argument of this
type accepts both a borrowed DLTensor* (type index kTVMFFIDLTensorPtr,
how C and 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. The caller must ensure that the
DLTensor it points to, and the memory that the DLTensor points to
(data, shape and strides), outlive every use of the view. For an argument
of an exported function, that is the duration of the call. For the same
reason, as in C++, a view cannot be moved into an owned Any;
use Tensor instead.
Implementations§
Source§impl TensorView
impl TensorView
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.
pub fn device(&self) -> DLDevice
pub fn dtype(&self) -> DLDataType
pub fn ndim(&self) -> usize
pub fn shape(&self) -> &[i64]
pub fn numel(&self) -> usize
Sourcepub fn strides(&self) -> &[i64]
pub fn strides(&self) -> &[i64]
The strides, in elements.
§Panics
If the DLTensor has null strides and at least one dimension, which
DLPack forbids since v1.2, as C++ TensorView::strides checks.
Sourcepub fn is_contiguous(&self) -> bool
pub fn is_contiguous(&self) -> bool
Whether the elements are laid out in row-major order without gaps, as
C++ tvm::ffi::IsContiguous decides: a DLTensor with null strides
or no elements is contiguous, and a dimension of extent 1 may have any
stride.
Trait Implementations§
Source§impl AnyCompatible for TensorView
impl AnyCompatible for TensorView
Source§unsafe fn copy_to_any_view(src: &Self, data: &mut TVMFFIAny)
unsafe fn copy_to_any_view(src: &Self, data: &mut TVMFFIAny)
Source§unsafe fn move_to_any(_src: Self, _data: &mut TVMFFIAny)
unsafe fn move_to_any(_src: Self, _data: &mut TVMFFIAny)
unsafe fn check_any_strict(data: &TVMFFIAny) -> bool
Source§unsafe fn copy_from_any_view_after_check(data: &TVMFFIAny) -> Self
unsafe fn copy_from_any_view_after_check(data: &TVMFFIAny) -> Self
Source§unsafe fn move_from_any_after_check(_data: &mut TVMFFIAny) -> Self
unsafe fn move_from_any_after_check(_data: &mut TVMFFIAny) -> Self
Source§unsafe fn try_cast_from_any_view(data: &TVMFFIAny) -> Result<Self, ()>
unsafe fn try_cast_from_any_view(data: &TVMFFIAny) -> Result<Self, ()>
Source§unsafe fn is_undefined(field: *const Self) -> bool
unsafe fn is_undefined(field: *const Self) -> bool
field, which holds a value of this type or all-zero bytes,
holds all-zero bytes that are no value of this type, as a null object
reference, a string of type index None or a zero device type: a field
that a creator left undefined for reflection to set, as C++ UnsafeInit
leaves a reference undefined (null). Unlike a C++ undefined reference,
it is no value; a nullable reference is Option<T>, whose None is a
defined value. Read moreSource§fn get_mismatch_type_info(data: &TVMFFIAny) -> String
fn get_mismatch_type_info(data: &TVMFFIAny) -> String
Source§fn type_schema() -> String
fn type_schema() -> String
TypeTraits<T>::TypeSchema writes, which the type schemas of functions
and fields embed. Read moreSource§impl Clone for TensorView
impl Clone for TensorView
Source§fn clone(&self) -> TensorView
fn clone(&self) -> TensorView
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more