Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Residuals method on System trait #17

Open
pnevyk opened this issue Nov 13, 2023 · 0 comments
Open

Residuals method on System trait #17

pnevyk opened this issue Nov 13, 2023 · 0 comments

Comments

@pnevyk
Copy link
Collaborator

pnevyk commented Nov 13, 2023

After return-position-impl-trait-in-trait feature gets into the stable, I would like to change the System trait to have the following API (some details omitted):

trait System: Problem {
    fn residuals<'a>(&self, x: &'a Vector) -> impl Iterator<Item = Self::Field> + 'a;

    fn eval(&self, x: &Vector, fx: &mut Vector) {
        // default impl, fill fx using self.residuals(x)
    }

    fn norm(&self, x: &Vector) -> Self::Field {
        // default impl, sqrt of sum of self.residuals(x)
    }
}

The main advantage is that by having residuals iterator the main interface, default implementation of norm can use that instead of eval and thus avoiding the need of allocating a temporary vector for fx. I believe that creating an iterator of residuals will not be more struggle than evaluating the system directly to fx. The iterator approach is already successfully used in the testing module.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant