pub struct CustomOpContext {
pub intermediates: HashMap<String, Scirs2Tensor>,
pub metadata: HashMap<String, String>,
pub requires_grad: bool,
}Expand description
Context for custom operation execution.
Provides storage for intermediate values needed during backward pass and metadata about the execution environment.
Fields§
§intermediates: HashMap<String, Scirs2Tensor>Storage for intermediate values (forward pass -> backward pass)
metadata: HashMap<String, String>Custom metadata
requires_grad: boolWhether gradient computation is enabled
Implementations§
Source§impl CustomOpContext
impl CustomOpContext
Sourcepub fn save_for_backward(
&mut self,
name: impl Into<String>,
tensor: Scirs2Tensor,
)
pub fn save_for_backward( &mut self, name: impl Into<String>, tensor: Scirs2Tensor, )
Store an intermediate tensor for backward pass.
Sourcepub fn get_saved(&self, name: &str) -> Option<&Scirs2Tensor>
pub fn get_saved(&self, name: &str) -> Option<&Scirs2Tensor>
Retrieve a saved intermediate tensor.
Sourcepub fn get_metadata(&self, key: &str) -> Option<&String>
pub fn get_metadata(&self, key: &str) -> Option<&String>
Get metadata.
Trait Implementations§
Source§impl Clone for CustomOpContext
impl Clone for CustomOpContext
Source§fn clone(&self) -> CustomOpContext
fn clone(&self) -> CustomOpContext
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for CustomOpContext
impl Debug for CustomOpContext
Source§impl Default for CustomOpContext
impl Default for CustomOpContext
Source§fn default() -> CustomOpContext
fn default() -> CustomOpContext
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for CustomOpContext
impl RefUnwindSafe for CustomOpContext
impl Send for CustomOpContext
impl Sync for CustomOpContext
impl Unpin for CustomOpContext
impl UnwindSafe for CustomOpContext
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