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

Predicting in a loop makes loads of allocations #130

Open
2 of 4 tasks
pYtoner opened this issue May 10, 2021 · 3 comments
Open
2 of 4 tasks

Predicting in a loop makes loads of allocations #130

pYtoner opened this issue May 10, 2021 · 3 comments
Labels
help wanted Extra attention is needed infrastructure General tasks effecting all implementations

Comments

@pYtoner
Copy link
Contributor

pYtoner commented May 10, 2021

We could add a version of Predict::predict which would write the output to a buffer instead of allocating the output.

Something like PredictInplace::predict_inplace. With a signature like fn predict_inplace(&self, x: &R, y: &mut T).

Implementation

  • implement buffer reuse with predict_inplace
  • add error handling for predict_inplace

Update algorithms

  • K-Means clustering
  • check other algorithms for feasibility
@YuhanLiin
Copy link
Collaborator

A back-compatible way of adding this would be to add something like

pub trait Predict<R: Records, T> {
    ...
    fn predict_into(&self, x: R, out: &mut T) {
         *out = self.predict(x);
    }
}

which would be overridden for a more efficient implementation. This isn't really useful if T is a Result, however.

@pYtoner
Copy link
Contributor Author

pYtoner commented Jul 27, 2021

Do we want to handle invalid target shapes like:

fn predict_inplace<'a>(&'a self, x: &'a R, y: &mut T) -> Result<(), InvalidTargetShape>

Or with a more generic error? Is it just a shape mismatch that we want to handle like this?

@YuhanLiin
Copy link
Collaborator

We should have a PredictError enum that has InvalidTargetShape as a variant. The error type will only contain error variants that makes sense to panic on. For now we only care about shape mismatches.

@YuhanLiin YuhanLiin added help wanted Extra attention is needed infrastructure General tasks effecting all implementations labels Nov 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed infrastructure General tasks effecting all implementations
Projects
None yet
Development

No branches or pull requests

2 participants