#[repr(C)]pub struct Tensor { /* private fields */ }Expand description
ABI stable owned Shape for ffi
Implementations§
Source§impl Tensor
impl Tensor
Sourcepub fn data_ptr_mut(&mut self) -> *mut c_void
pub fn data_ptr_mut(&mut self) -> *mut c_void
Sourcepub fn is_contiguous(&self) -> bool
pub fn is_contiguous(&self) -> bool
pub fn data_as_slice<T: AsDLDataType>(&self) -> Result<&[T]>
Sourcepub fn data_as_slice_mut<T: AsDLDataType>(&self) -> Result<&mut [T]>
pub fn data_as_slice_mut<T: AsDLDataType>(&self) -> Result<&mut [T]>
Returns the tensor data as a mutable slice.
This method takes &self rather than &mut self by design: like
std::fs::File::write, the metadata of a Tensor (shape, dtype,
device) is governed by Rust’s ownership rules, but writing to the
underlying data buffer (CPU memory or a GPU pointer) is a side-effect
outside Rust’s aliasing model. Most C/CUDA kernel APIs accept a
non-mut Tensor and mutate its data content, so requiring &mut self
here would force artificial mutability annotations throughout the
deep-learning stack with no real safety benefit.
§Safety contract (caller responsibility)
If the Tensor has been cloned (via ObjectArc), the caller must
ensure no other clone is concurrently reading the data.
pub fn shape(&self) -> &[i64]
pub fn ndim(&self) -> usize
pub fn numel(&self) -> usize
pub fn strides(&self) -> &[i64]
pub fn dtype(&self) -> DLDataType
pub fn device(&self) -> DLDevice
Source§impl Tensor
impl Tensor
Sourcepub fn from_nd_alloc<TNDAlloc>(
alloc: TNDAlloc,
shape: &[i64],
dtype: DLDataType,
device: DLDevice,
) -> Selfwhere
TNDAlloc: NDAllocator,
pub fn from_nd_alloc<TNDAlloc>(
alloc: TNDAlloc,
shape: &[i64],
dtype: DLDataType,
device: DLDevice,
) -> Selfwhere
TNDAlloc: NDAllocator,
Sourcepub fn from_env_alloc(
shape: &[i64],
dtype: DLDataType,
device: DLDevice,
) -> Result<Self>
pub fn from_env_alloc( shape: &[i64], dtype: DLDataType, device: DLDevice, ) -> Result<Self>
Create a Tensor with the environment allocator of this thread, as C++
Tensor::FromEnvAlloc(TVMFFIEnvTensorAlloc, ...) does.
Kernel libraries allocate intermediate tensors this way, so that they
come from the caller’s allocator, such as the one a framework sets
with TVMFFIEnvSetDLPackManagedTensorAllocator.
§Arguments
shape- The shape of the Tensordtype- The data type of the Tensordevice- The device of the Tensor
§Returns
Result<Tensor>- The created Tensor, or the error the allocator raised, which is aRuntimeErrorwhen no allocator is set
Sourcepub fn from_slice<T: AsDLDataType>(slice: &[T], shape: &[i64]) -> Result<Self>
pub fn from_slice<T: AsDLDataType>(slice: &[T], shape: &[i64]) -> Result<Self>
Trait Implementations§
Source§impl AnyCompatible for Tensor
impl AnyCompatible for Tensor
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§unsafe fn copy_to_any_view(src: &Self, data: &mut TVMFFIAny)
unsafe fn copy_to_any_view(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_to_any(src: Self, data: &mut TVMFFIAny)
unsafe fn move_to_any(src: Self, data: &mut TVMFFIAny)
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§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<'a> ArgIntoRef for &'a Tensor
impl<'a> ArgIntoRef for &'a Tensor
Source§impl ArgIntoRef for Tensor
impl ArgIntoRef for Tensor
Source§impl From<&Tensor> for TensorView
impl From<&Tensor> for TensorView
Source§impl<'a> IntoArgHolder for &'a Tensor
impl<'a> IntoArgHolder for &'a Tensor
Source§impl IntoArgHolder for Tensor
impl IntoArgHolder for Tensor
Source§impl ObjectRefCore for Tensor
impl ObjectRefCore for Tensor
type ContainerType = <ObjectArc<TensorObj> as Deref>::Target
fn data(this: &Self) -> &ObjectArc<Self::ContainerType>
fn into_data(this: Self) -> ObjectArc<Self::ContainerType>
Source§unsafe fn from_data(data: ObjectArc<Self::ContainerType>) -> Self
unsafe fn from_data(data: ObjectArc<Self::ContainerType>) -> Self
Source§fn same_as<Other: ObjectRefCore>(&self, other: &Other) -> bool
fn same_as<Other: ObjectRefCore>(&self, other: &Other) -> bool
Source§fn downcast_ref<T: ObjectCore>(&self) -> Option<&T>
fn downcast_ref<T: ObjectCore>(&self) -> Option<&T>
Auto Trait Implementations§
impl Freeze for Tensor
impl RefUnwindSafe for Tensor
impl !Send for Tensor
impl !Sync for Tensor
impl Unpin for Tensor
impl UnwindSafe for Tensor
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> ObjectRefCast for Twhere
T: ObjectRefCore + AnyCompatible,
impl<T> ObjectRefCast for Twhere
T: ObjectRefCore + AnyCompatible,
Source§fn try_cast<B>(self) -> Result<B>where
B: ObjectRefCore + AnyCompatible,
fn try_cast<B>(self) -> Result<B>where
B: ObjectRefCore + AnyCompatible,
self and rewrap the underlying object as B without copying.