pub struct Variable { /* private fields */ }Expand description
Variable that participates in automatic differentiation
Implementations§
Source§impl Variable
impl Variable
Sourcepub fn new_with_name(tensor: Tensor, requires_grad: bool, name: String) -> Self
pub fn new_with_name(tensor: Tensor, requires_grad: bool, name: String) -> Self
Create a new variable with a name
Sourcepub fn from_graph(graph: GraphRef, node_id: NodeId, requires_grad: bool) -> Self
pub fn from_graph(graph: GraphRef, node_id: NodeId, requires_grad: bool) -> Self
Create a new variable from an existing graph
Sourcepub fn requires_grad(&self) -> bool
pub fn requires_grad(&self) -> bool
Check if this variable requires gradients
Sourcepub fn backward_with_grad(&self, grad: Tensor) -> Result<()>
pub fn backward_with_grad(&self, grad: Tensor) -> Result<()>
Compute backward pass with custom gradient
Sourcepub fn requires_grad_(&self) -> Result<Variable>
pub fn requires_grad_(&self) -> Result<Variable>
Create a copy of this variable that requires gradients
Sourcepub fn leaky_relu(&self, alpha: f32) -> Result<Variable>
pub fn leaky_relu(&self, alpha: f32) -> Result<Variable>
Leaky ReLU activation
Sourcepub fn add_scalar(&self, scalar: f32) -> Result<Variable>
pub fn add_scalar(&self, scalar: f32) -> Result<Variable>
Add a scalar
Sourcepub fn sub_scalar(&self, scalar: f32) -> Result<Variable>
pub fn sub_scalar(&self, scalar: f32) -> Result<Variable>
Subtract a scalar
Sourcepub fn mul_scalar(&self, scalar: f32) -> Result<Variable>
pub fn mul_scalar(&self, scalar: f32) -> Result<Variable>
Multiply by a scalar
Sourcepub fn div_scalar(&self, scalar: f32) -> Result<Variable>
pub fn div_scalar(&self, scalar: f32) -> Result<Variable>
Divide by a scalar
Sourcepub fn set_requires_grad(&mut self, requires_grad: bool)
pub fn set_requires_grad(&mut self, requires_grad: bool)
Set whether this variable requires gradients
Sourcepub fn from_tensor(tensor: Tensor) -> Self
pub fn from_tensor(tensor: Tensor) -> Self
Create a variable from a tensor (with requires_grad = false by default)
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Variable
impl RefUnwindSafe for Variable
impl Send for Variable
impl Sync for Variable
impl Unpin for Variable
impl UnsafeUnpin for Variable
impl UnwindSafe for Variable
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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