ParallelOptimizer

Struct ParallelOptimizer 

Source
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(&params_list, &grads_list).unwrap();

Implementations§

Source§

impl<O, A, D> ParallelOptimizer<O, A, D>
where O: Optimizer<A, D> + Clone + Send + Sync, A: Float + ScalarOperand + Debug + Send + Sync, D: Dimension,

Source

pub fn new(base_optimizer: O) -> Self

Creates a new parallel optimizer wrapper

§Arguments
  • base_optimizer - The base optimizer to parallelize
Source

pub fn step_parallel_groups( &mut self, params_list: &[Array<A, D>], grads_list: &[Array<A, D>], ) -> Result<Vec<Array<A, D>>>
where Array<A, D>: Clone + Send + Sync,

Process multiple parameter groups in parallel

This method distributes parameter groups across available CPU cores for parallel processing.

§Arguments
  • params_list - List of parameter arrays
  • grads_list - List of gradient arrays
§Returns

Updated parameter arrays processed in parallel

Source

pub fn inner(&self) -> &O

Get the underlying optimizer

Source

pub fn inner_mut(&mut self) -> &mut O

Get mutable reference to underlying optimizer

Source

pub fn get_learning_rate(&self) -> A

Get the current learning rate from the base optimizer

Source

pub fn set_learning_rate(&mut self, learning_rate: A)

Set the learning rate on the base optimizer

Trait Implementations§

Source§

impl<O, A, D> Debug for ParallelOptimizer<O, A, D>
where O: Optimizer<A, D> + Clone + Send + Sync + Debug, A: Float + ScalarOperand + Debug + Send + Sync + Debug, D: Dimension + Debug,

Source§

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

Formats the value using the given formatter. Read more

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>
where O: Unpin, A: Unpin, D: Unpin,

§

impl<O, A, D> UnwindSafe for ParallelOptimizer<O, A, D>
where O: UnwindSafe, A: UnwindSafe, D: UnwindSafe,

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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 T
where 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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

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

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

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

Source§

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 T
where U: TryFrom<T>,

Source§

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 T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V