pub struct Path<'a> { /* private fields */ }
Expand description
A variable store with an associated path for variables naming.
Implementations§
source§impl<'a> Path<'a>
impl<'a> Path<'a>
sourcepub fn components(&self) -> impl Iterator<Item = &str>
pub fn components(&self) -> impl Iterator<Item = &str>
Get the components of the path.
pub fn set_group(&self, group: usize) -> Path<'a>
pub fn path(&self, name: &str) -> String
sourcepub fn set_kind(&mut self, kind: Kind)
pub fn set_kind(&mut self, kind: Kind)
Casts all variables in a var store sub-path to the target kind .
Only the variable in the path sub-tree are cast to the target kind:
other var store variables are unaffected. For floating-point conversion, methods
half
, bfloat16
, float
and double
should be preferred as they ensure only
float-like variables will be converted to the target type.
sourcepub fn half(&mut self)
pub fn half(&mut self)
Casts all float-like variables in a var store sub-path to half-precision (Half kind).
Only the variable in the path sub-tree are cast to half-precision: other var store variables are unaffected
sourcepub fn bfloat16(&mut self)
pub fn bfloat16(&mut self)
Casts all float-like variables in a var store sub-path to bfloat16-precision (BFloat16 kind).
Only the variable in the path sub-tree are cast to bfloat16-precision: other var store variables are unaffected
sourcepub fn float(&mut self)
pub fn float(&mut self)
Casts all float-like variables in a var store sub-path to single-precision (Float kind).
Only the variable in the path sub-tree are cast to single-precision: other var store variables are unaffected
sourcepub fn double(&mut self)
pub fn double(&mut self)
Casts all float-like variables in a var store sub-path to double-precision (Double kind).
Only the variable in the path sub-tree are cast to double-precision: other var store variables are unaffected
sourcepub fn f_zeros_no_train(
&self,
name: &str,
dims: &[i64]
) -> Result<Tensor, TchError>
pub fn f_zeros_no_train( &self, name: &str, dims: &[i64] ) -> Result<Tensor, TchError>
Creates a new variable initialized with zeros.
The new variable is named according to the name parameter and has the specified shape. The variable will not be trainable so gradients will not be tracked. The variable uses a float tensor initialized with zeros.
sourcepub fn f_ones_no_train(
&self,
name: &str,
dims: &[i64]
) -> Result<Tensor, TchError>
pub fn f_ones_no_train( &self, name: &str, dims: &[i64] ) -> Result<Tensor, TchError>
Creates a new variable initialized with ones.
The new variable is named according to the name parameter and has the specified shape. The variable will not be trainable so gradients will not be tracked. The variable uses a float tensor initialized with ones.
sourcepub fn f_var(
&self,
name: &str,
dims: &[i64],
init: Init
) -> Result<Tensor, TchError>
pub fn f_var( &self, name: &str, dims: &[i64], init: Init ) -> Result<Tensor, TchError>
Creates a new variable.
The new variable is named according to the name parameter and has the specified shape. The variable is trainable, its gradient will be tracked. The variable uses a float tensor initialized as per the related argument.
sourcepub fn f_zeros(&self, name: &str, dims: &[i64]) -> Result<Tensor, TchError>
pub fn f_zeros(&self, name: &str, dims: &[i64]) -> Result<Tensor, TchError>
Creates a new variable initialized with zeros.
The new variable is named according to the name parameter and has the specified shape. The variable is trainable, its gradient will be tracked. The variable uses a float tensor initialized with zeros.
sourcepub fn f_ones(&self, name: &str, dims: &[i64]) -> Result<Tensor, TchError>
pub fn f_ones(&self, name: &str, dims: &[i64]) -> Result<Tensor, TchError>
Creates a new variable initialized with ones.
The new variable is named according to the name parameter and has the specified shape. The variable is trainable, its gradient will be tracked. The variable uses a float tensor initialized with ones.
sourcepub fn f_randn_standard(
&self,
name: &str,
dims: &[i64]
) -> Result<Tensor, TchError>
pub fn f_randn_standard( &self, name: &str, dims: &[i64] ) -> Result<Tensor, TchError>
Creates a new variable initialized randomly with normal distribution.
The new variable is named according to the name parameter and has the specified shape. The variable is trainable, its gradient will be tracked. The variable uses a float tensor initialized randomly using a standard normal distribution.
sourcepub fn f_randn(
&self,
name: &str,
dims: &[i64],
mean: f64,
stdev: f64
) -> Result<Tensor, TchError>
pub fn f_randn( &self, name: &str, dims: &[i64], mean: f64, stdev: f64 ) -> Result<Tensor, TchError>
Creates a new variable initialized randomly with normal distribution.
The new variable is named according to the name parameter and has the specified shape. The variable is trainable, its gradient will be tracked. The variable uses a float tensor initialized randomly using a normal distribution with the specified mean and standard deviation.
sourcepub fn f_uniform(
&self,
name: &str,
dims: &[i64],
lo: f64,
up: f64
) -> Result<Tensor, TchError>
pub fn f_uniform( &self, name: &str, dims: &[i64], lo: f64, up: f64 ) -> Result<Tensor, TchError>
Creates a new variable initialized randomly with uniform distribution.
The new variable is named according to the name parameter and has the specified shape. The variable is trainable, its gradient will be tracked. The variable uses a float tensor initialized randomly using a uniform distribution between the specified bounds.
sourcepub fn f_kaiming_uniform(
&self,
name: &str,
dims: &[i64]
) -> Result<Tensor, TchError>
pub fn f_kaiming_uniform( &self, name: &str, dims: &[i64] ) -> Result<Tensor, TchError>
Creates a new variable initialized randomly with kaiming uniform.
The new variable is named according to the name parameter and has the specified shape. The variable is trainable, its gradient will be tracked. The variable uses a float tensor initialized randomly using a uniform distribution which bounds follow Kaiming initialization.
sourcepub fn f_kaiming_normal(
&self,
name: &str,
dims: &[i64]
) -> Result<Tensor, TchError>
pub fn f_kaiming_normal( &self, name: &str, dims: &[i64] ) -> Result<Tensor, TchError>
Creates a new variable initialized randomly with kaiming normal.
The new variable is named according to the name parameter and has the specified shape. The variable is trainable, its gradient will be tracked. The variable uses a float tensor initialized randomly using a normal distribution which stdev follow Kaiming initialization.
sourcepub fn f_orthogonal(
&self,
name: &str,
dims: &[i64],
gain: f64
) -> Result<Tensor, TchError>
pub fn f_orthogonal( &self, name: &str, dims: &[i64], gain: f64 ) -> Result<Tensor, TchError>
Creates a new variable initialized randomly with an orthogonal matrix
The new variable is named according to the name parameter and has the specified shape. The variable is trainable, its gradient will be tracked. The variable uses a float tensor initialized randomly with an orthogonal matrix as described in Exact solutions to the nonlinear dynamics of learning in deep linear neural networks - Saxe, A. et. al. (2013). The input tensor must have at least 2 dimensions, and for tensors with more than 2 dimensions the trailing dimensions are flattened.
sourcepub fn f_var_copy(&self, name: &str, t: &Tensor) -> Result<Tensor, TchError>
pub fn f_var_copy(&self, name: &str, t: &Tensor) -> Result<Tensor, TchError>
Creates a new variable initialized by copying an existing tensor.
The new variable is named according to the name parameter and has the specified shape. The variable is trainable, its gradient will be tracked. The variable uses a float tensor initialized by copying some given tensor.
sourcepub fn zeros_no_train(&self, name: &str, dims: &[i64]) -> Tensor
pub fn zeros_no_train(&self, name: &str, dims: &[i64]) -> Tensor
Creates a new variable initialized with zeros.
The new variable is named according to the name parameter and has the specified shape. The variable will not be trainable so gradients will not be tracked. The variable uses a float tensor initialized with zeros.
sourcepub fn ones_no_train(&self, name: &str, dims: &[i64]) -> Tensor
pub fn ones_no_train(&self, name: &str, dims: &[i64]) -> Tensor
Creates a new variable initialized with ones.
The new variable is named according to the name parameter and has the specified shape. The variable will not be trainable so gradients will not be tracked. The variable uses a float tensor initialized with ones.
sourcepub fn var(&self, name: &str, dims: &[i64], init: Init) -> Tensor
pub fn var(&self, name: &str, dims: &[i64], init: Init) -> Tensor
Creates a new variable.
The new variable is named according to the name parameter and has the specified shape. The variable is trainable, its gradient will be tracked. The variable uses a float tensor initialized as per the related argument.
sourcepub fn zeros(&self, name: &str, dims: &[i64]) -> Tensor
pub fn zeros(&self, name: &str, dims: &[i64]) -> Tensor
Creates a new variable initialized with zeros.
The new variable is named according to the name parameter and has the specified shape. The variable is trainable, its gradient will be tracked. The variable uses a float tensor initialized with zeros.
sourcepub fn ones(&self, name: &str, dims: &[i64]) -> Tensor
pub fn ones(&self, name: &str, dims: &[i64]) -> Tensor
Creates a new variable initialized with ones.
The new variable is named according to the name parameter and has the specified shape. The variable is trainable, its gradient will be tracked. The variable uses a float tensor initialized with ones.
sourcepub fn randn_standard(&self, name: &str, dims: &[i64]) -> Tensor
pub fn randn_standard(&self, name: &str, dims: &[i64]) -> Tensor
Creates a new variable initialized randomly with normal distribution.
The new variable is named according to the name parameter and has the specified shape. The variable is trainable, its gradient will be tracked. The variable uses a float tensor initialized randomly using a standard normal distribution.
sourcepub fn randn(&self, name: &str, dims: &[i64], mean: f64, stdev: f64) -> Tensor
pub fn randn(&self, name: &str, dims: &[i64], mean: f64, stdev: f64) -> Tensor
Creates a new variable initialized randomly with normal distribution.
The new variable is named according to the name parameter and has the specified shape. The variable is trainable, its gradient will be tracked. The variable uses a float tensor initialized randomly using a normal distribution with the specified mean and standard deviation.
sourcepub fn uniform(&self, name: &str, dims: &[i64], lo: f64, up: f64) -> Tensor
pub fn uniform(&self, name: &str, dims: &[i64], lo: f64, up: f64) -> Tensor
Creates a new variable initialized randomly with uniform distribution.
The new variable is named according to the name parameter and has the specified shape. The variable is trainable, its gradient will be tracked. The variable uses a float tensor initialized randomly using a uniform distribution between the specified bounds.
sourcepub fn kaiming_uniform(&self, name: &str, dims: &[i64]) -> Tensor
pub fn kaiming_uniform(&self, name: &str, dims: &[i64]) -> Tensor
Creates a new variable initialized randomly with kaiming uniform.
The new variable is named according to the name parameter and has the specified shape. The variable is trainable, its gradient will be tracked. The variable uses a float tensor initialized randomly using a uniform distribution which bounds follow Kaiming initialization.
sourcepub fn kaiming_normal(&self, name: &str, dims: &[i64]) -> Tensor
pub fn kaiming_normal(&self, name: &str, dims: &[i64]) -> Tensor
Creates a new variable initialized randomly with kaiming normal.
The new variable is named according to the name parameter and has the specified shape. The variable is trainable, its gradient will be tracked. The variable uses a float tensor initialized randomly using a normal distribution which stdev follow Kaiming initialization.
sourcepub fn orthogonal(&self, name: &str, dims: &[i64], gain: f64) -> Tensor
pub fn orthogonal(&self, name: &str, dims: &[i64], gain: f64) -> Tensor
Creates a new variable initialized randomly with an orthogonal matrix
The new variable is named according to the name parameter and has the specified shape. The variable is trainable, its gradient will be tracked. The variable uses a float tensor initialized randomly with an orthogonal matrix as described in Exact solutions to the nonlinear dynamics of learning in deep linear neural networks - Saxe, A. et. al. (2013). The input tensor must have at least 2 dimensions, and for tensors with more than 2 dimensions the trailing dimensions are flattened.
sourcepub fn var_copy(&self, name: &str, t: &Tensor) -> Tensor
pub fn var_copy(&self, name: &str, t: &Tensor) -> Tensor
Creates a new variable initialized by copying an existing tensor.
The new variable is named according to the name parameter and has the specified shape. The variable is trainable, its gradient will be tracked. The variable uses a float tensor initialized by copying some given tensor.