pub struct VarMap { /* private fields */ }
Expand description
A VarMap
is a store that holds named variables. Variables can be retrieved from the stores
and new variables can be added by providing some initialization config in case they are
missing.
VarMap
structures can be serialized in the safetensors format.
Implementations§
source§impl VarMap
impl VarMap
sourcepub fn save<P: AsRef<Path>>(&self, path: P) -> Result<()>
pub fn save<P: AsRef<Path>>(&self, path: P) -> Result<()>
Save the map in the safetensors format.
sourcepub fn load<P: AsRef<Path>>(&mut self, path: P) -> Result<()>
pub fn load<P: AsRef<Path>>(&mut self, path: P) -> Result<()>
Load some values from a safetensors file and modify the existing variables to have these values.
Note that values for variables that are currently not in the map are not kept.
sourcepub fn set_one<K: AsRef<str>, V: AsRef<Tensor>>(
&mut self,
name: K,
value: V,
) -> Result<()>
pub fn set_one<K: AsRef<str>, V: AsRef<Tensor>>( &mut self, name: K, value: V, ) -> Result<()>
Set a named variable to some value.
sourcepub fn set<I: Iterator<Item = (K, V)>, K: AsRef<str>, V: AsRef<Tensor>>(
&mut self,
iter: I,
) -> Result<()>
pub fn set<I: Iterator<Item = (K, V)>, K: AsRef<str>, V: AsRef<Tensor>>( &mut self, iter: I, ) -> Result<()>
Set some named variables to some values.
If an error is returned, some of the variables might have already been set to their new values.
sourcepub fn get<S: Into<Shape>>(
&self,
shape: S,
path: &str,
init: Init,
dtype: DType,
device: &Device,
) -> Result<Tensor>
pub fn get<S: Into<Shape>>( &self, shape: S, path: &str, init: Init, dtype: DType, device: &Device, ) -> Result<Tensor>
Retrieve or add a new variable.
sourcepub fn get_unchecked(
&self,
_path: &str,
_dtype: DType,
_device: &Device,
) -> Result<Tensor>
pub fn get_unchecked( &self, _path: &str, _dtype: DType, _device: &Device, ) -> Result<Tensor>
Retrieve or add a new variable.
pub fn data(&self) -> &Mutex<HashMap<String, Var>>
Trait Implementations§
source§impl SimpleBackend for VarMap
impl SimpleBackend for VarMap
source§fn get(
&self,
s: Shape,
name: &str,
h: Init,
dtype: DType,
dev: &Device,
) -> Result<Tensor>
fn get( &self, s: Shape, name: &str, h: Init, dtype: DType, dev: &Device, ) -> Result<Tensor>
Retrieve a tensor based on a target name and shape.
source§fn get_unchecked(
&self,
name: &str,
dtype: DType,
dev: &Device,
) -> Result<Tensor>
fn get_unchecked( &self, name: &str, dtype: DType, dev: &Device, ) -> Result<Tensor>
Retrieve a tensor based on the name.
fn contains_tensor(&self, name: &str) -> bool
Auto Trait Implementations§
impl Freeze for VarMap
impl RefUnwindSafe for VarMap
impl Send for VarMap
impl Sync for VarMap
impl Unpin for VarMap
impl UnwindSafe for VarMap
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more