Trait argmin::core::Operator

source ·
pub trait Operator {
    type Param;
    type Output;

    // Required method
    fn apply(&self, param: &Self::Param) -> Result<Self::Output, Error>;

    // Provided methods
    fn bulk_apply<P>(&self, params: &[P]) -> Result<Vec<Self::Output>, Error>
       where P: Borrow<Self::Param> + SyncAlias,
             Self::Output: SendAlias,
             Self: SyncAlias { ... }
    fn parallelize(&self) -> bool { ... }
}
Expand description

Defines the application of an operator to a parameter vector.

§Example

use argmin::core::{Operator, Error};
use argmin_math::ArgminDot;

struct Model {
    matrix: Vec<Vec<f64>>,
}

impl Operator for Model {
    type Param = Vec<f64>;
    type Output = Vec<f64>;

    /// Multiply matrix `self.matrix` with vector `param`
    fn apply(&self, param: &Self::Param) -> Result<Self::Output, Error> {
        Ok(self.matrix.dot(param))
    }
}

Required Associated Types§

source

type Param

Type of the parameter vector

source

type Output

Type of the return value of the operator

Required Methods§

source

fn apply(&self, param: &Self::Param) -> Result<Self::Output, Error>

Applies the operator to parameters

Provided Methods§

source

fn bulk_apply<P>(&self, params: &[P]) -> Result<Vec<Self::Output>, Error>
where P: Borrow<Self::Param> + SyncAlias, Self::Output: SendAlias, Self: SyncAlias,

Compute apply in bulk. If the rayon feature is enabled, multiple calls to apply will be run in parallel using rayon, otherwise they will execute sequentially. If the rayon feature is enabled, parallelization can still be turned off by overwriting parallelize to return false. This can be useful in cases where it is preferable to parallelize only certain parts. Note that even if parallelize is set to false, the parameter vectors and the problem are still required to be Send and Sync. Those bounds are linked to the rayon feature. This method can be overwritten.

source

fn parallelize(&self) -> bool

Indicates whether to parallelize calls to apply when using bulk_apply. By default returns true, but can be set manually to false if needed. This allows users to turn off parallelization for certain traits implemented on their problem. Note that parallelization requires the rayon feature to be enabled, otherwise calls to apply will be executed sequentially independent of how parallelize is set.

Object Safety§

This trait is not object safe.

Implementors§