Skip to content

Commit

Permalink
Simplify multilinear methods (#8)
Browse files Browse the repository at this point in the history
* Remove initial guess for cell index from rectilinear method
* Collapse some loops
* Remove support for negative step sizes for regular grid in favor of reducing number of abs() calls
* Remove some saturating sub calls that are not needed now that degenerate grids are not supported
* Get indexing dimension product in the same way for rectilinear method as for regular grid method
* Use better initial value for folds
* Update docs
* Use optimizations for tests because it's faster overall
  • Loading branch information
jlogan03 authored Dec 18, 2023
1 parent ba4f0c9 commit 0fb81e8
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 263 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ resolver = "2"
opt-level = 3
codegen-units = 1
lto = true

[profile.dev]
opt-level = 3
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ Note that for a self-consistent multidimensional interpolation, there are 2^ndim
to each observation point, and as such, that is the theoretical floor for performance scaling. That said,
depending on the implementation, the constant term can vary by more than an order of magnitude.

| Method | RAM | Interp. Cost (Best Case) | Interp. Cost (Worst Case) | Extrap. Cost (Worst Case) |
|-------------------------------|-----------|--------------------------|-------------------------------------|------------------------------------------------|
| multilinear::regular | O(ndims) | O(2^ndims) | O(2^ndims) | O(2^ndims + ndims^2) |
| multilinear::rectilinear | O(ndims) | O(2^ndims) | O(2^ndims + ndims * log2(gridsize)) | O(2^ndims + ndims^2 + ndims * log2(gridsize)) |
| Method | RAM | Interp. Cost (Best Case) | Interp. Cost (Worst Case) | Extrap. Cost (Worst Case) |
|-------------------------------|-----------|--------------------------|-----------------------------------------|------------------------------------------------|
| multilinear::regular | O(ndims) | O(2^ndims * ndims) | O(2^ndims * ndims) | O(2^ndims + ndims^2) |
| multilinear::rectilinear | O(ndims) | O(2^ndims * ndims) | O(ndims * (2^ndims + log2(gridsize))) | O(ndims * (2^ndims + ndims + log2(gridsize))) |

# Example: Multilinear w/ Regular Grid
```rust
Expand Down
2 changes: 1 addition & 1 deletion interpn/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "interpn"
version = "0.2.0"
version = "0.3.0"
edition = "2021"
authors = ["James Logan <jlogan03@gmail.com>"]
license = "MIT OR Apache-2.0"
Expand Down
8 changes: 4 additions & 4 deletions interpn/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ Note that for a self-consistent multidimensional interpolation, there are 2^ndim
to each observation point, and as such, that is the theoretical floor for performance scaling. That said,
depending on the implementation, the constant term can vary by more than an order of magnitude.

| Method | RAM | Interp. Cost (Best Case) | Interp. Cost (Worst Case) | Extrap. Cost (Worst Case) |
|-------------------------------|-----------|--------------------------|-------------------------------------|------------------------------------------------|
| multilinear::regular | O(ndims) | O(2^ndims) | O(2^ndims) | O(2^ndims + ndims^2) |
| multilinear::rectilinear | O(ndims) | O(2^ndims) | O(2^ndims + ndims * log2(gridsize)) | O(2^ndims + ndims^2 + ndims * log2(gridsize)) |
| Method | RAM | Interp. Cost (Best Case) | Interp. Cost (Worst Case) | Extrap. Cost (Worst Case) |
|-------------------------------|-----------|--------------------------|-----------------------------------------|------------------------------------------------|
| multilinear::regular | O(ndims) | O(2^ndims * ndims) | O(2^ndims * ndims) | O(2^ndims + ndims^2) |
| multilinear::rectilinear | O(ndims) | O(2^ndims * ndims) | O(ndims * (2^ndims + log2(gridsize))) | O(ndims * (2^ndims + ndims + log2(gridsize))) |

# Example: Multilinear w/ Regular Grid
```rust
Expand Down
8 changes: 4 additions & 4 deletions interpn/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
//! to each observation point, and as such, that is the theoretical floor for performance scaling. That said,
//! depending on the implementation, the constant term can vary by more than an order of magnitude.
//!
//! | Method | RAM | Interp. Cost (Best Case) | Interp. Cost (Worst Case) | Extrap. Cost (Worst Case) |
//! |-------------------------------|-----------|--------------------------|-------------------------------------|------------------------------------------------|
//! | multilinear::regular | O(ndims) | O(2^ndims) | O(2^ndims) | O(2^ndims + ndims^2) |
//! | multilinear::rectilinear | O(ndims) | O(2^ndims) | O(2^ndims + ndims * log2(gridsize)) | O(2^ndims + ndims^2 + ndims * log2(gridsize)) |
//! | Method | RAM | Interp. Cost (Best Case) | Interp. Cost (Worst Case) | Extrap. Cost (Worst Case) |
//! |-------------------------------|-----------|--------------------------|-----------------------------------------|------------------------------------------------|
//! | multilinear::regular | O(ndims) | O(2^ndims * ndims) | O(2^ndims * ndims) | O(2^ndims + ndims^2) |
//! | multilinear::rectilinear | O(ndims) | O(2^ndims * ndims) | O(ndims * (2^ndims + log2(gridsize))) | O(ndims * (2^ndims + ndims + log2(gridsize))) |
//!
//! # Example: Multilinear w/ Regular Grid
//! ```rust
Expand Down
Loading

0 comments on commit 0fb81e8

Please sign in to comment.