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

Consider exposing stored x and y values #10

Open
ivan-aksamentov opened this issue Nov 18, 2024 · 2 comments
Open

Consider exposing stored x and y values #10

ivan-aksamentov opened this issue Nov 18, 2024 · 2 comments

Comments

@ivan-aksamentov
Copy link

When working on an iterative methods when data needs to be modified and interpolated, there's 2 choices:

  • keep a copy of the original data around and also create and interp object
  • keep only data and create interp object every time interpolation is needed

Both cases waste memoty and second also wastes CPU cycles.

It would be nice if we could have access to the original data, and mutable access would be amazing.

@jonasBoss
Copy link
Owner

you can use Interp1D::new_unchecked(x.view(), y.view(), ...) if you know that the data is valid. This is basically free and you don't need to copy stuff.

@jonasBoss
Copy link
Owner

fn main() {
    let x = array![1.0,2.0,3.0,4.0];
    let mut y = array![5.0,4.0,4.5,6.0];

    let interp = Interp1D::builder(y.view()).x(x.view()).build(); // this causes validation
    
    y[0] = 6.0;
    // changing y does not invalidate the data so we can use new_unchecked
    let interp = Interp1D::new_unchecked(x.view(), y.view(), Linear::new().extrapolate(true));
}

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

No branches or pull requests

2 participants