IterativeKernel

Trait IterativeKernel 

Source
pub trait IterativeKernel<S, I, O>: GpuKernel
where S: Send + Sync + 'static, I: Send + Sync + 'static, O: Send + Sync + 'static,
{ // Required methods fn initial_state(&self, input: &I) -> S; fn iterate<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, state: &'life1 mut S, input: &'life2 I, ) -> Pin<Box<dyn Future<Output = Result<IterationResult<O>, KernelError>> + Send + 'async_trait>> where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, Self: 'async_trait; fn converged(&self, state: &S, threshold: f64) -> bool; // Provided methods fn max_iterations(&self) -> usize { ... } fn default_threshold(&self) -> f64 { ... } fn run_to_convergence<'life0, 'async_trait>( &'life0 self, input: I, ) -> Pin<Box<dyn Future<Output = Result<O, KernelError>> + Send + 'async_trait>> where 'life0: 'async_trait, Self: Sync + 'async_trait { ... } fn run_to_convergence_with_threshold<'life0, 'async_trait>( &'life0 self, input: I, threshold: f64, ) -> Pin<Box<dyn Future<Output = Result<O, KernelError>> + Send + 'async_trait>> where 'life0: 'async_trait, Self: Sync + 'async_trait { ... } }
Expand description

Trait for iterative (multi-pass) kernels.

Provides support for algorithms that require multiple iterations to converge (e.g., PageRank, K-Means).

§Type Parameters

  • S: State type
  • I: Input type
  • O: Output type

Required Methods§

Source

fn initial_state(&self, input: &I) -> S

Create the initial state.

Source

fn iterate<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, state: &'life1 mut S, input: &'life2 I, ) -> Pin<Box<dyn Future<Output = Result<IterationResult<O>, KernelError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, Self: 'async_trait,

Perform one iteration.

§Arguments
  • state - The current state (mutable)
  • input - The input data
§Returns

The iteration result.

Source

fn converged(&self, state: &S, threshold: f64) -> bool

Check if the algorithm has converged.

§Arguments
  • state - The current state
  • threshold - The convergence threshold
§Returns

true if converged, false otherwise.

Provided Methods§

Source

fn max_iterations(&self) -> usize

Maximum number of iterations.

Source

fn default_threshold(&self) -> f64

Default convergence threshold.

Source

fn run_to_convergence<'life0, 'async_trait>( &'life0 self, input: I, ) -> Pin<Box<dyn Future<Output = Result<O, KernelError>> + Send + 'async_trait>>
where 'life0: 'async_trait, Self: Sync + 'async_trait,

Run the iterative algorithm to convergence.

Source

fn run_to_convergence_with_threshold<'life0, 'async_trait>( &'life0 self, input: I, threshold: f64, ) -> Pin<Box<dyn Future<Output = Result<O, KernelError>> + Send + 'async_trait>>
where 'life0: 'async_trait, Self: Sync + 'async_trait,

Run the iterative algorithm with a custom threshold.

Implementors§