pub struct TensorMut<'a> {
pub data: DevicePtrMut,
pub dtype: DataType,
pub shape: &'a [usize],
pub strides: &'a [i64],
pub byte_offset: usize,
pub device: DeviceId,
/* private fields */
}Expand description
Mutable, non-owning view of a tensor on any device.
Fields§
§data: DevicePtrMut§dtype: DataType§shape: &'a [usize]§strides: &'a [i64]Strides in elements (may be negative, matching DLPack).
byte_offset: usizeOffset in bytes of the element origin from data (DLPack semantics).
device: DeviceIdImplementations§
Source§impl<'a> TensorMut<'a>
impl<'a> TensorMut<'a>
Sourcepub fn new(
data: DevicePtrMut,
dtype: DataType,
shape: &'a [usize],
strides: &'a [i64],
device: DeviceId,
) -> Self
pub fn new( data: DevicePtrMut, dtype: DataType, shape: &'a [usize], strides: &'a [i64], device: DeviceId, ) -> Self
Construct a zero-offset mutable view. data must remain valid and
exclusively borrowed for 'a.
Sourcepub fn with_byte_offset(self, byte_offset: usize) -> Self
pub fn with_byte_offset(self, byte_offset: usize) -> Self
Set the DLPack-style byte offset of the element origin.
Sourcepub fn validate(&self) -> Result<()>
pub fn validate(&self) -> Result<()>
Check the view’s invariants (rank, dtype, offset alignment).
Sourcepub fn is_contiguous(&self) -> bool
pub fn is_contiguous(&self) -> bool
Whether the view is contiguous row-major.
Sourcepub fn byte_size(&self) -> usize
pub fn byte_size(&self) -> usize
Logical element byte size (dense; ignores stride gaps). Uses
storage_bytes so sub-byte (int4/uint4) types are counted correctly.
Sourcepub fn data_ptr_mut<T>(&mut self) -> *mut T
pub fn data_ptr_mut<T>(&mut self) -> *mut T
Typed mutable pointer to the element origin, applying byte_offset.
Computed with wrapping arithmetic (no deref) — safe to call.
Auto Trait Implementations§
impl<'a> !Send for TensorMut<'a>
impl<'a> !Sync for TensorMut<'a>
impl<'a> !UnwindSafe for TensorMut<'a>
impl<'a> Freeze for TensorMut<'a>
impl<'a> RefUnwindSafe for TensorMut<'a>
impl<'a> Unpin for TensorMut<'a>
impl<'a> UnsafeUnpin for TensorMut<'a>
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
Mutably borrows from an owned value. Read more