pub struct TensorBlockRefMut<'a> { /* private fields */ }Expand description
Mutable reference to a TensorBlock
Implementations§
Source§impl<'a> TensorBlockRefMut<'a>
impl<'a> TensorBlockRefMut<'a>
Sourcepub unsafe fn from_raw(ptr: *mut mts_block_t) -> TensorBlockRefMut<'a>
pub unsafe fn from_raw(ptr: *mut mts_block_t) -> TensorBlockRefMut<'a>
Create a new TensorBlockRefMut from the given raw mts_block_t
This is a VERY unsafe function, creating a lifetime out of thin air,
and allowing mutable access to the mts_block_t. Make sure the lifetime
is actually constrained by the lifetime of the owner of this
mts_block_t; and that the owner is mutably borrowed by this
TensorBlockRefMut.
Sourcepub fn as_mut_ptr(&mut self) -> *mut mts_block_t
pub fn as_mut_ptr(&mut self) -> *mut mts_block_t
Get the underlying (mutable) raw pointer
Sourcepub fn as_ref(&self) -> TensorBlockRef<'_>
pub fn as_ref(&self) -> TensorBlockRef<'_>
Get a non mutable reference to this block
Sourcepub fn data_mut(&mut self) -> TensorBlockDataMut<'_>
pub fn data_mut(&mut self) -> TensorBlockDataMut<'_>
Get all the data and metadata inside this TensorBlockRefMut as a
struct with separate fields, to allow borrowing them separately.
Sourcepub fn device(&self) -> Result<DLDevice, Error>
pub fn device(&self) -> Result<DLDevice, Error>
Get the device on which the values of this block are stored.
Sourcepub fn dtype(&self) -> Result<DLDataType, Error>
pub fn dtype(&self) -> Result<DLDataType, Error>
Get the data type of the values of this block.
Sourcepub fn values_mut(&mut self) -> ArrayRefMut<'_>
pub fn values_mut(&mut self) -> ArrayRefMut<'_>
Get a mutable reference to the values in this block
Sourcepub fn components(&self) -> Vec<Labels>
pub fn components(&self) -> Vec<Labels>
Get the components for this block
Sourcepub fn properties(&self) -> Labels
pub fn properties(&self) -> Labels
Get the properties for this block
Sourcepub fn gradient_mut(&mut self, parameter: &str) -> Option<TensorBlockRefMut<'_>>
pub fn gradient_mut(&mut self, parameter: &str) -> Option<TensorBlockRefMut<'_>>
Get a mutable reference to the data and metadata for the gradient with respect to the given parameter in this block, if it exists.
Sourcepub fn gradients_mut(&mut self) -> GradientsMutIter<'_> ⓘ
pub fn gradients_mut(&mut self) -> GradientsMutIter<'_> ⓘ
Get an iterator over parameter/TensorBlockRefMut pairs for all gradients
in this block
Sourcepub fn save(&self, path: impl AsRef<Path>) -> Result<(), Error>
pub fn save(&self, path: impl AsRef<Path>) -> Result<(), Error>
Save the given block to the file at path
This is a convenience function calling crate::io::save_block
Sourcepub fn save_buffer(&self, buffer: &mut Vec<u8>) -> Result<(), Error>
pub fn save_buffer(&self, buffer: &mut Vec<u8>) -> Result<(), Error>
Save the given block to an in-memory buffer
This is a convenience function calling crate::io::save_block_buffer