8 releases (stable)

2.0.1 Oct 8, 2024
2.0.0 Sep 23, 2024
1.0.3 Dec 27, 2023
1.0.2 Oct 19, 2023
0.1.1 Jun 6, 2021

#169 in Algorithms

Download history 346/week @ 2024-07-26 220/week @ 2024-08-02 250/week @ 2024-08-09 349/week @ 2024-08-16 328/week @ 2024-08-23 404/week @ 2024-08-30 271/week @ 2024-09-06 272/week @ 2024-09-13 531/week @ 2024-09-20 458/week @ 2024-09-27 309/week @ 2024-10-04 279/week @ 2024-10-11 204/week @ 2024-10-18 441/week @ 2024-10-25 248/week @ 2024-11-01 244/week @ 2024-11-08

1,200 downloads per month
Used in 7 crates (4 directly)

MIT/Apache

22KB
278 lines

interp

Test status Code coverage Crate version Rust version Downloads

An implementation of 1-dimensional linear interpolation in Rust, similar to MATLAB's interp1 or NumPy's numpy.interp.

API documentation is available on docs.rs.

Usage

Add interp to your Cargo.toml file:

[dependencies]
interp = "2.0"

Example

use interp::{interp, interp_array, interp_slice, InterpMode};

let x = vec![0.0, 0.2, 0.5, 0.8, 1.0];
let y = vec![0.0, 1.0, 3.0, 3.5, 4.0];

// Interpolate at a single point
assert_eq!(interp(&x, &y, 0.35, &InterpMode::default()), 2.0);

// Interpolate a slice - alloces a new results Vec<T>
let xp = vec![0.1, 0.65, 0.9];
assert_eq!(interp_slice(&x, &y, &xp, &InterpMode::default()), vec![0.5, 3.25, 3.75]);

// Interpolate an array
let xp = [0.1, 0.65, 0.9];
assert_eq!(interp_array(&x, &y, &xp, &InterpMode::default()), [0.5, 3.25, 3.75]);

Full API documentation is available on docs.rs.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

You can install the pre-commit hook (which checks formatting, etc) by running:

pip install -U pre-commit
pre-commit install

Licence

Licensed under either of

at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~600KB
~11K SLoC