pub struct ParallelOptimizer<O, A, D>where
O: Optimizer<A, D> + Clone + Send + Sync,
A: Float + ScalarOperand + Debug + Send + Sync,
D: Dimension,{ /* private fields */ }Expand description
Parallel optimizer wrapper for processing multiple parameter groups
This wrapper enables parallel processing of multiple parameter groups, providing significant speedup on multi-core systems.
§Examples
use scirs2_core::ndarray::Array1;
use optirs_core::optimizers::{SGD, Optimizer};
use optirs_core::parallel_optimizer::ParallelOptimizer;
// Create base optimizer
let optimizer = SGD::new(0.01);
// Wrap in parallel optimizer
let mut parallel_opt = ParallelOptimizer::new(optimizer);
// Process multiple parameter groups in parallel
let params_list = vec![
Array1::zeros(1000),
Array1::zeros(2000),
Array1::zeros(1500),
];
let grads_list = vec![
Array1::from_elem(1000, 0.1),
Array1::from_elem(2000, 0.1),
Array1::from_elem(1500, 0.1),
];
let updated = parallel_opt.step_parallel_groups(¶ms_list, &grads_list).unwrap();Implementations§
Source§impl<O, A, D> ParallelOptimizer<O, A, D>
impl<O, A, D> ParallelOptimizer<O, A, D>
Sourcepub fn new(base_optimizer: O) -> Self
pub fn new(base_optimizer: O) -> Self
Creates a new parallel optimizer wrapper
§Arguments
base_optimizer- The base optimizer to parallelize
Sourcepub fn step_parallel_groups(
&mut self,
params_list: &[Array<A, D>],
grads_list: &[Array<A, D>],
) -> Result<Vec<Array<A, D>>>
pub fn step_parallel_groups( &mut self, params_list: &[Array<A, D>], grads_list: &[Array<A, D>], ) -> Result<Vec<Array<A, D>>>
Sourcepub fn get_learning_rate(&self) -> A
pub fn get_learning_rate(&self) -> A
Get the current learning rate from the base optimizer
Sourcepub fn set_learning_rate(&mut self, learning_rate: A)
pub fn set_learning_rate(&mut self, learning_rate: A)
Set the learning rate on the base optimizer
Trait Implementations§
Auto Trait Implementations§
impl<O, A, D> Freeze for ParallelOptimizer<O, A, D>where
O: Freeze,
impl<O, A, D> RefUnwindSafe for ParallelOptimizer<O, A, D>
impl<O, A, D> Send for ParallelOptimizer<O, A, D>
impl<O, A, D> Sync for ParallelOptimizer<O, A, D>
impl<O, A, D> Unpin for ParallelOptimizer<O, A, D>
impl<O, A, D> UnwindSafe for ParallelOptimizer<O, A, D>
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> 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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.