pub struct TensorBlockRef<'a> { /* private fields */ }Expand description
Reference to a TensorBlock
Implementations§
Source§impl<'a> TensorBlockRef<'a>
impl<'a> TensorBlockRef<'a>
Sourcepub unsafe fn from_raw(ptr: *const mts_block_t) -> TensorBlockRef<'a>
pub unsafe fn from_raw(ptr: *const mts_block_t) -> TensorBlockRef<'a>
Create a new TensorBlockRef from the given raw mts_block_t
This is a VERY unsafe function, creating a lifetime out of thin air.
Make sure the lifetime is actually constrained by the lifetime of the
owner of this mts_block_t.
Source§impl<'a> TensorBlockRef<'a>
impl<'a> TensorBlockRef<'a>
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 data(&'a self) -> TensorBlockData<'a>
pub fn data(&'a self) -> TensorBlockData<'a>
Get all the data and metadata inside this TensorBlockRef as a
struct with separate fields, to allow borrowing them separately.
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_list(&self) -> Vec<&'a str>
pub fn gradient_list(&self) -> Vec<&'a str>
Get the full list of gradients in this block
Sourcepub fn gradient(&self, parameter: &str) -> Option<TensorBlockRef<'a>>
pub fn gradient(&self, parameter: &str) -> Option<TensorBlockRef<'a>>
Get the data and metadata for the gradient with respect to the given parameter in this block, if it exists.
Sourcepub fn try_clone(&self) -> Result<TensorBlock, Error>
pub fn try_clone(&self) -> Result<TensorBlock, Error>
Clone this block, cloning all the data and metadata contained inside.
This can fail if the external data held inside an mts_array_t can not
be cloned.
Sourcepub fn gradients(&self) -> GradientsIter<'_> ⓘ
pub fn gradients(&self) -> GradientsIter<'_> ⓘ
Get an iterator over parameter/TensorBlockRef 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
Trait Implementations§
Source§impl<'a> Clone for TensorBlockRef<'a>
impl<'a> Clone for TensorBlockRef<'a>
Source§fn clone(&self) -> TensorBlockRef<'a>
fn clone(&self) -> TensorBlockRef<'a>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more