Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -286,10 +286,10 @@ See examples in `new` method documentation:
- [`InterpND::new`](https://docs.rs/ninterp/latest/ninterp/interpolator/struct.InterpND.html#method.new)

Also see the [`examples`](https://github.com/NatLabRockies/ninterp/tree/main/examples) directory for advanced examples:
- Swapping strategies at runtime: [`dynamic_strategy.rs`](https://github.com/NatLabRockies/ninterp/blob/main/examples/dynamic_strategy.rs)
- Swapping strategies at runtime: [`swap_strategy.rs`](https://github.com/NatLabRockies/ninterp/blob/main/examples/swap_strategy.rs)
- Strategy enums (`strategy::enums::Strategy1DEnum`/etc.): `serde`-compatible, custom strategies not supported
- `Box<dyn Strategy1D>`/etc. (dynamic dispatch): custom strategies supported, not `serde`-compatible, runtime cost
- Swapping interpolators at runtime: [`dynamic_interpolator.rs`](https://github.com/NatLabRockies/ninterp/blob/main/examples/dynamic_interpolator.rs)
- Swapping interpolators at runtime: [`swap_interpolator.rs`](https://github.com/NatLabRockies/ninterp/blob/main/examples/swap_interpolator.rs)
- `InterpolatorEnum`: `serde`-compatible, custom strategies not supported
- `Box<dyn Interpolator>` (dynamic dispatch): custom strategies supported, not `serde`-compatible, runtime cost
- Defining custom strategies: [`custom_strategy.rs`](https://github.com/NatLabRockies/ninterp/blob/main/examples/custom_strategy.rs)
Expand Down
5 changes: 5 additions & 0 deletions examples/custom_strategy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ where
// e.g. `Array2<f32>`, `ArrayView2<f32>`, `CowArray<<'a, f32>, Ix2>`, etc.
// For a more generic bound, consider introducing a bound for D::Elem
// e.g. D::Elem: num_traits::Num + PartialOrd
//
// Note: when reading grid coordinates in `interpolate`, index `data.grid[i]` directly
// via ArrayView indexing (e.g. `data.grid[i][idx]`), not `.as_slice()`, which panics
// on non-contiguous storage. `Interp*Viewed` can produce that from a strided slice.
// For a bracket-search helper, see `ninterp::strategy::utils::locate_lower_index`.
D: Data<Elem = f32> + RawDataClone + Clone,
{
// We can optionally define an initialization step, useful for strategies that need precalculation.
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/interpolator/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ use strategy::enums::*;
/// interp = InterpolatorEnum::new_0d(0.5);
/// assert_eq!(interp.interpolate(&[]).unwrap(), 0.5);
/// ```
/// See also: `examples/dynamic_interpolator.rs`
/// See also: `examples/swap_interpolator.rs`
#[allow(missing_docs)]
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
Expand Down
2 changes: 1 addition & 1 deletion src/strategy/enums/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
//! assert_eq!(interp.interpolate(&[3.75]).unwrap(), 0.8);
//! assert_eq!(interp.interpolate(&[4.00]).unwrap(), 1.0);
//! ```
//! See also: `examples/dynamic_strategy.rs`
//! See also: `examples/swap_strategy.rs`
// NOTE: `enum_dispatch` does essentially what this module does, but with less boilerplate.
// However, it does not currently support using a generic trait on a non-generic enum.
Expand Down
20 changes: 20 additions & 0 deletions src/strategy/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ where
}

/// Execute interpolation (after handling [`Extrapolate`](`crate::interpolator::Extrapolate`) setting).
///
/// # Note for custom strategies
/// Index `data.grid[i]` directly via `ArrayView` indexing; avoid `.as_slice()`, which
/// panics on non-contiguous storage (possible with `Interp*Viewed`). See
/// [`crate::strategy::utils::locate_lower_index`] for a ready-made bracket search.
fn interpolate(
&self,
data: &InterpData1D<D>,
Expand Down Expand Up @@ -64,6 +69,11 @@ where
}

/// Execute interpolation (after handling [`Extrapolate`](`crate::interpolator::Extrapolate`) setting).
///
/// # Note for custom strategies
/// Index `data.grid[i]` directly via `ArrayView` indexing; avoid `.as_slice()`, which
/// panics on non-contiguous storage (possible with `Interp*Viewed`). See
/// [`crate::strategy::utils::locate_lower_index`] for a ready-made bracket search.
fn interpolate(
&self,
data: &InterpData2D<D>,
Expand Down Expand Up @@ -114,6 +124,11 @@ where
}

/// Execute interpolation (after handling [`Extrapolate`](`crate::interpolator::Extrapolate`) setting).
///
/// # Note for custom strategies
/// Index `data.grid[i]` directly via `ArrayView` indexing; avoid `.as_slice()`, which
/// panics on non-contiguous storage (possible with `Interp*Viewed`). See
/// [`crate::strategy::utils::locate_lower_index`] for a ready-made bracket search.
fn interpolate(
&self,
data: &InterpData3D<D>,
Expand Down Expand Up @@ -164,6 +179,11 @@ where
}

/// Execute interpolation (after handling [`Extrapolate`](`crate::interpolator::Extrapolate`) setting).
///
/// # Note for custom strategies
/// Index `data.grid[i]` directly via `ArrayView` indexing; avoid `.as_slice()`, which
/// panics on non-contiguous storage (possible with `Interp*Viewed`). See
/// [`crate::strategy::utils::locate_lower_index`] for a ready-made bracket search.
fn interpolate(
&self,
data: &InterpDataND<D>,
Expand Down
Loading