Struct tch::nn::Path

source ·
pub struct Path<'a> { /* private fields */ }
Expand description

A variable store with an associated path for variables naming.

Implementations§

source§

impl<'a> Path<'a>

source

pub fn components(&self) -> impl Iterator<Item = &str>

Get the components of the path.

source

pub fn sub<T: ToString>(&self, s: T) -> Path<'a>

Gets a sub-path of the given path.

source

pub fn set_group(&self, group: usize) -> Path<'a>

source

pub fn device(&self) -> Device

Gets the device where the var-store variables are stored.

source

pub fn path(&self, name: &str) -> String

source

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.

source

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

source

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

source

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

source

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

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

pub fn get(&self, name: &str) -> Option<Tensor>

Gets the tensor corresponding to a given name if present.

source

pub fn entry<'b>(&'b self, name: &'b str) -> Entry<'b>

Gets the entry corresponding to a given name for in-place manipulation.

Trait Implementations§

source§

impl<'a> Clone for Path<'a>

source§

fn clone(&self) -> Path<'a>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'a> Debug for Path<'a>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'a, T> Div<T> for &Path<'a>where T: ToString,

§

type Output = Path<'a>

The resulting type after applying the / operator.
source§

fn div(self, rhs: T) -> Self::Output

Performs the / operation. Read more
source§

impl<'a, T> Div<T> for &mut Path<'a>where T: ToString,

§

type Output = Path<'a>

The resulting type after applying the / operator.
source§

fn div(self, rhs: T) -> Self::Output

Performs the / operation. Read more
source§

impl<'a, T> Div<T> for Path<'a>where T: ToString,

§

type Output = Path<'a>

The resulting type after applying the / operator.
source§

fn div(self, rhs: T) -> Self::Output

Performs the / operation. Read more

Auto Trait Implementations§

§

impl<'a> RefUnwindSafe for Path<'a>

§

impl<'a> Send for Path<'a>

§

impl<'a> Sync for Path<'a>

§

impl<'a> Unpin for Path<'a>

§

impl<'a> UnwindSafe for Path<'a>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

source§

fn vzip(self) -> V