6 releases (stable)

1.0.3 Dec 27, 2023
1.0.2 Oct 19, 2023
1.0.1 Mar 11, 2023
1.0.0 Feb 20, 2023
0.1.1 Jun 6, 2021

#185 in Algorithms

Download history 57/week @ 2023-12-22 204/week @ 2023-12-29 155/week @ 2024-01-05 179/week @ 2024-01-12 129/week @ 2024-01-19 235/week @ 2024-01-26 411/week @ 2024-02-02 387/week @ 2024-02-09 127/week @ 2024-02-16 167/week @ 2024-02-23 296/week @ 2024-03-01 193/week @ 2024-03-08 347/week @ 2024-03-15 233/week @ 2024-03-22 306/week @ 2024-03-29 111/week @ 2024-04-05

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

MIT/Apache

17KB
177 lines

interp

Test status Code coverage Crate version Rust version Downloads

A Rust reimplementation of Matlab's interp1 function for linear interpolation.

API documentation is available on docs.rs.

Usage

Add interp to your Cargo.toml file:

[dependencies]
interp = "1.0"

Or, if you need the interp_array feature (only supported on Rust 1.55.0 or later)

[dependencies]
interp = { version = "1.0", features = ["interp_array"] }

Example

use interp::interp;

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), 2.0);

// Interpolate a vec
let xp = vec![0.1, 0.65, 0.9];
assert_eq!(interp_slice(&x, &y, &xp), vec![0.5, 3.25, 3.75]);

// Interpolate an array (requires the interp_array feature and Rust 1.55.0+)
let xp = [0.1, 0.65, 0.9];
assert_eq!(interp_array(&x, &y, &xp), [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

~585KB
~11K SLoC