pub struct Parameter { /* private fields */ }Expand description
A learnable parameter of a neural network module.
Parameters wrap Variables and provide additional functionality:
- Automatic requires_grad=true by default
- Registration with parent modules
- Easy access to data and gradients
Implementations§
Source§impl Parameter
impl Parameter
Sourcepub fn new(data: Tensor<f32>, requires_grad: bool) -> Self
pub fn new(data: Tensor<f32>, requires_grad: bool) -> Self
Creates a new parameter from a tensor.
§Arguments
data- The tensor datarequires_grad- Whether to track gradients (default true)
Sourcepub fn named(
name: impl Into<String>,
data: Tensor<f32>,
requires_grad: bool,
) -> Self
pub fn named( name: impl Into<String>, data: Tensor<f32>, requires_grad: bool, ) -> Self
Creates a new parameter with a name.
Sourcepub fn from_variable(var: Variable) -> Self
pub fn from_variable(var: Variable) -> Self
Creates a parameter from an existing Variable.
Sourcepub fn requires_grad(&self) -> bool
pub fn requires_grad(&self) -> bool
Returns whether this parameter requires gradients.
Sourcepub fn update_data(&self, new_data: Tensor<f32>)
pub fn update_data(&self, new_data: Tensor<f32>)
Updates the parameter data in-place.
Used by optimizers to update weights.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Parameter
impl !RefUnwindSafe for Parameter
impl Send for Parameter
impl Sync for Parameter
impl Unpin for Parameter
impl !UnwindSafe for Parameter
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§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