Skip to content

Commit

Permalink
reorganize getters/setters, prep for release
Browse files Browse the repository at this point in the history
  • Loading branch information
kylecarow committed Nov 27, 2024
1 parent 1bf3519 commit be8bdb1
Show file tree
Hide file tree
Showing 9 changed files with 528 additions and 369 deletions.
10 changes: 6 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@
name = "ninterp"
version = "0.1.0"
edition = "2021"
description = "Numerical interpolation in N-dimensions over a regular, sorted, nonrepeating grid"
repository = "https://github.com/NREL/ninterp"
license = "BSD-3-Clause"
keywords = ["interpolation", "multidimensional", "multilinear", "numerical", "approximation"]
categories = ["mathematics"]

[dependencies]
itertools = "0.13.0"
log = { version = "0.4.22", optional = true }
ndarray = "0.16.1"
serde = { version = "1.0.210", optional = true }
serde = { version = "1.0.210", optional = true, features = ["derive"] }
thiserror = "1.0.64"

[dev-dependencies]
Expand All @@ -19,6 +23,4 @@ name = "benchmark"
harness = false

[features]
default = ["logging"]
logging = ["dep:log"]
serde = ["dep:serde", "ndarray/serde"]
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# ninterp

NREL SWR-25-25
The `ninterp` crate provides [multivariate interpolation](https://en.wikipedia.org/wiki/Multivariate_interpolation#Regular_grid) over a regular, sorted, nonrepeating grid of any dimensionality. A variety of interpolation strategies are implemented, however more are likely to be added. Extrapolation beyond the range of the supplied coordinates is supported for 1-D linear interpolators, using the slope of the nearby points.

There are hard-coded interpolators for lower dimensionalities (up to N = 3) for better runtime performance.

All interpolation is handled through instances of the Interpolator enum, with the selected tuple variant containing relevant data. Interpolation is executed by calling Interpolator::interpolate.

## Feature Flags
- `serde`: support for serde

## Getting Started

See the Interpolator enum documentation for examples and notes on usage.
2 changes: 1 addition & 1 deletion benches/benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
use criterion::{criterion_group, criterion_main, Criterion};

use ninterp::*;
use ndarray::prelude::*;
use ninterp::*;
use rand::{self, rngs::StdRng, Rng, SeedableRng};

#[allow(non_snake_case)]
Expand Down
20 changes: 11 additions & 9 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! Custom error types
use thiserror::Error;

#[derive(Error, Debug)]
Expand All @@ -6,7 +8,7 @@ pub enum Error {
ValidationError(#[from] ValidationError),
#[error(transparent)]
InterpolationError(#[from] InterpolationError),
#[error("No such field exists for interpolator variant")]
#[error("no such field exists for interpolator variant")]
NoSuchField,
#[error("{0}")]
Other(String),
Expand All @@ -15,27 +17,27 @@ pub enum Error {
/// Error types that occur from a `validate()` call, before calling interpolate()
#[derive(Error, Debug)]
pub enum ValidationError {
#[error("Selected `Strategy` variant ({0}) is unimplemented for interpolator variant")]
#[error("selected `Strategy` variant ({0}) is unimplemented for interpolator variant")]
StrategySelection(String),
#[error("Selected `Extrapolate` variant ({0}) is unimplemented for interpolator variant")]
#[error("selected `Extrapolate` variant ({0}) is unimplemented for interpolator variant")]
ExtrapolationSelection(String),
#[error("Supplied grid coordinates cannot be empty: dim {0}")]
#[error("supplied grid coordinates cannot be empty: dim {0}")]
EmptyGrid(String),
#[error("Supplied coordinates must be sorted and non-repeating: dim {0}")]
#[error("supplied coordinates must be sorted and non-repeating: dim {0}")]
Monotonicity(String),
#[error("Supplied grid and values are not compatible shapes: dim {0}")]
#[error("supplied grid and values are not compatible shapes: dim {0}")]
IncompatibleShapes(String),
#[error("{0}")]
Other(String),
}

#[derive(Error, Debug)]
pub enum InterpolationError {
#[error("Attempted to interpolate at point beyond grid data: {0}")]
#[error("sttempted to interpolate at point beyond grid data: {0}")]
ExtrapolationError(String),
#[error("Surrounding values cannot be NaN: {0}")]
#[error("surrounding values cannot be NaN: {0}")]
NaNError(String),
#[error("Supplied point is invalid for interpolator: {0}")]
#[error("supplied point is invalid for interpolator: {0}")]
InvalidPoint(String),
#[error("{0}")]
Other(String),
Expand Down
Loading

0 comments on commit be8bdb1

Please sign in to comment.