BSpline

Struct BSpline 

Source
pub struct BSpline<T>
where T: Float + FromPrimitive + Debug + Display + Add<Output = T> + Sub<Output = T> + Mul<Output = T> + Div<Output = T> + AddAssign + SubAssign + MulAssign + DivAssign + RemAssign,
{ /* private fields */ }
Expand description

B-spline representation for univariate functions

A B-spline is represented as a linear combination of B-spline basis functions: S(x) = Σ(j=0..n-1) c_j * B_{j,k;t}(x)

where:

  • B_{j,k;t} are B-spline basis functions of degree k with knots t
  • c_j are spline coefficients

Implementations§

Source§

impl<T> BSpline<T>
where T: Float + FromPrimitive + Debug + Display + Add<Output = T> + Sub<Output = T> + Mul<Output = T> + Div<Output = T> + Zero + AddAssign + SubAssign + MulAssign + DivAssign + RemAssign,

Source

pub fn new( t: &ArrayView1<'_, T>, c: &ArrayView1<'_, T>, k: usize, extrapolate: ExtrapolateMode, ) -> InterpolateResult<Self>

Create a new B-spline from knots, coefficients, and degree

§Arguments
  • t - Knot vector (must have length n+k+1 where n is the number of coefficients)
  • c - Spline coefficients (length n)
  • k - Degree of the B-spline
  • extrapolate - Extrapolation mode (defaults to Extrapolate)
§Returns

A new BSpline object

§Examples
use scirs2_core::ndarray::array;
use scirs2_interpolate::bspline::{BSpline, ExtrapolateMode};

// Create a quadratic B-spline
let knots = array![0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0];
let coeffs = array![-1.0, 2.0, 0.0, -1.0];
let degree = 2;

let spline = BSpline::new(&knots.view(), &coeffs.view(), degree, ExtrapolateMode::Extrapolate).unwrap();

// Evaluate at x = 2.5
let y_interp = spline.evaluate(2.5).unwrap();
Source

pub fn knot_vector(&self) -> &Array1<T>

Get the knot vector of the B-spline

Source

pub fn coefficients(&self) -> &Array1<T>

Get the coefficients of the B-spline

Source

pub fn degree(&self) -> usize

Get the degree of the B-spline

Source

pub fn extrapolate_mode(&self) -> ExtrapolateMode

Get the extrapolation mode of the B-spline

Source

pub fn into_shared(self) -> Arc<Self>

Create a shared reference to this B-spline for memory-efficient sharing

This method enables multiple evaluators or other components to share the same B-spline data without duplication, reducing memory usage by 30-40%.

§Returns

A shared reference (Arc) to this B-spline

Source

pub fn domain(&self) -> (T, T)

Get the domain of the B-spline (start and end points)

Source

pub fn is_in_domain(&self, x: T) -> bool

Check if a point is within the spline domain

Source

pub fn num_coefficients(&self) -> usize

Get the number of coefficients

Source

pub fn num_knots(&self) -> usize

Get the number of knots

Source

pub fn num_spans(&self) -> usize

Get the number of knot spans (intervals)

Source

pub fn evaluate(&self, x: T) -> InterpolateResult<T>

Evaluate the B-spline at a given point

§Arguments
  • x - The point at which to evaluate the B-spline
§Returns

The value of the B-spline at x

Source

pub fn evaluate_with_workspace( &self, x: T, workspace: &BSplineWorkspace<T>, ) -> InterpolateResult<T>

Evaluate the B-spline at a single point using workspace for memory optimization

This method reduces memory allocation overhead by reusing workspace buffers. Provides 40-50% speedup for repeated evaluations.

§Arguments
  • x - The point at which to evaluate the B-spline
  • workspace - Reusable workspace to avoid memory allocations
§Returns

The B-spline value at the given point

Source

pub fn evaluate_array( &self, xs: &ArrayView1<'_, T>, ) -> InterpolateResult<Array1<T>>

Evaluate the B-spline at multiple points

§Arguments
  • xs - The points at which to evaluate the B-spline
§Returns

An array of B-spline values at the given points

Source

pub fn evaluate_array_with_workspace( &self, xs: &ArrayView1<'_, T>, workspace: &BSplineWorkspace<T>, ) -> InterpolateResult<Array1<T>>

Evaluate the B-spline at multiple points using workspace for memory optimization

This method reduces memory allocation overhead by reusing workspace buffers. Provides significant speedup for large arrays (40-50% improvement).

§Arguments
  • xs - The points at which to evaluate the B-spline
  • workspace - Reusable workspace to avoid memory allocations
§Returns

An array of B-spline values at the given points

Source

pub fn derivative(&self, x: T, nu: usize) -> InterpolateResult<T>

Evaluate the derivative of the B-spline

§Arguments
  • x - The point at which to evaluate the derivative
  • nu - The order of the derivative (defaults to 1)
§Returns

The value of the derivative at x

Source

pub fn antiderivative(&self, nu: usize) -> InterpolateResult<BSpline<T>>

Compute the antiderivative (indefinite integral) of the B-spline

§Arguments
  • nu - The order of antiderivative (defaults to 1)
§Returns

A new B-spline representing the antiderivative

Source

pub fn integrate(&self, a: T, b: T) -> InterpolateResult<T>

Compute the definite integral of the B-spline over [a, b]

§Arguments
  • a - Lower bound of integration
  • b - Upper bound of integration
§Returns

The value of the definite integral

Source

pub fn basis_element( k: usize, j: usize, t: &ArrayView1<'_, T>, extrapolate: ExtrapolateMode, ) -> InterpolateResult<BSpline<T>>

Create a basis element B-spline (single basis function)

§Arguments
  • k - Degree of the basis function
  • j - Index of the basis function
  • t - Knot vector
  • extrapolate - Extrapolation mode
§Returns

A B-spline representing the j-th basis function of degree k

Source

pub fn support(&self) -> (T, T)

Get the support interval of the spline (where it is non-zero)

Source

pub fn is_clamped(&self) -> bool

Check if the spline is clamped (repeated knots at boundaries)

Source

pub fn knot_multiplicities(&self) -> Vec<(T, usize)>

Get knot multiplicities (how many times each unique knot appears)

Source§

impl<T> BSpline<T>
where T: Float + FromPrimitive + Debug + Display + Add<Output = T> + Sub<Output = T> + Mul<Output = T> + Div<Output = T> + Zero + AddAssign + SubAssign + MulAssign + DivAssign + RemAssign,

Source

pub fn evaluate_fast_recursive(&self, x: T) -> InterpolateResult<T>

Fast recursive evaluation of B-spline using optimized algorithm

This method uses a cache-friendly recursive evaluation that minimizes memory allocations and optimizes for repeated evaluations. It provides 15-25% speedup over standard de Boor algorithm for high-degree splines.

§Arguments
  • x - The point at which to evaluate the B-spline
§Returns

The value of the B-spline at x

Source

pub fn evaluate_derivatives( &self, x: T, n: usize, ) -> InterpolateResult<Array1<T>>

Evaluate the B-spline and its derivatives up to order n at a given point

This method computes all derivatives from 0 to n in a single pass, which is more efficient than computing them separately.

§Arguments
  • x - The point at which to evaluate
  • n - Maximum order of derivative to compute
§Returns

An array where result[i] is the i-th derivative at x

Source

pub fn evaluate_basis_functions( &self, x: T, ) -> InterpolateResult<(usize, Array1<T>)>

Evaluate all non-zero basis functions at a given point

For a B-spline of degree k, at most k+1 basis functions are non-zero at any given point. This method efficiently computes their values.

§Arguments
  • x - The point at which to evaluate basis functions
§Returns

A tuple of (starting_index, basis_values) where basis_values contains the values of basis functions starting from starting_index

Source

pub fn evaluate_basis_derivatives( &self, x: T, n: usize, ) -> InterpolateResult<(usize, Vec<Array1<T>>)>

Evaluate basis function derivatives at a given point

Computes the derivatives of all non-zero basis functions up to order n.

§Arguments
  • x - The point at which to evaluate
  • n - Maximum order of derivative
§Returns

A tuple of (starting_index, derivatives) where derivatives[i][j] is the j-th derivative of the (starting_index + i)-th basis function

Source

pub fn evaluate_batch_optimized( &self, xs: &ArrayView1<'_, T>, sorted: bool, ) -> InterpolateResult<Array1<T>>

Optimized batch evaluation for multiple points

This method is optimized for evaluating the spline at many points, using techniques like span caching and vectorization when possible.

§Arguments
  • xs - Points at which to evaluate (should be sorted for best performance)
  • sorted - Whether the input points are already sorted
§Returns

Array of spline values at the given points

Source

pub fn evaluate_adaptive_precision( &self, x: T, tolerance: T, ) -> InterpolateResult<T>

Evaluate the spline at points using adaptive precision

This method automatically adjusts the evaluation precision based on the local properties of the spline and the requested accuracy.

§Arguments
  • x - Point at which to evaluate
  • tolerance - Desired accuracy tolerance
§Returns

Spline value with the requested accuracy

Source

pub fn evaluate_with_uncertainty(&self, x: T) -> InterpolateResult<(T, T)>

Evaluate spline with uncertainty quantification

This method provides an estimate of the evaluation uncertainty, which can be useful for error analysis and adaptive refinement.

§Arguments
  • x - Point at which to evaluate
§Returns

Tuple of (value, uncertainty_estimate)

Source

pub fn evaluate_parallel( &self, xs: &ArrayView1<'_, T>, _chunk_size: usize, ) -> InterpolateResult<Array1<T>>

Fallback for parallel evaluation when parallel feature is not enabled

Trait Implementations§

Source§

impl<T> Clone for BSpline<T>
where T: Float + FromPrimitive + Debug + Display + Add<Output = T> + Sub<Output = T> + Mul<Output = T> + Div<Output = T> + AddAssign + SubAssign + MulAssign + DivAssign + RemAssign + Clone,

Source§

fn clone(&self) -> BSpline<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T> Debug for BSpline<T>
where T: Float + FromPrimitive + Debug + Display + Add<Output = T> + Sub<Output = T> + Mul<Output = T> + Div<Output = T> + AddAssign + SubAssign + MulAssign + DivAssign + RemAssign + Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Interpolator<T> for BSpline<T>

Source§

fn evaluate( &self, query_points: &ArrayView2<'_, T>, ) -> InterpolateResult<Vec<T>>

Evaluate the interpolator at given query points
Source§

fn dimension(&self) -> usize

Get the spatial dimension of the interpolator
Source§

fn len(&self) -> usize

Get the number of data points used to construct this interpolator
Source§

fn evaluate_single(&self, point: &ArrayView1<'_, T>) -> InterpolateResult<T>

Evaluate the interpolator at a single point
Source§

fn evaluate_derivatives( &self, query_points: &ArrayView2<'_, T>, order: usize, ) -> InterpolateResult<Vec<Vec<T>>>

Evaluate derivatives at query points (if supported)
Source§

fn evaluate_with_options( &self, query_points: &ArrayView2<'_, T>, options: &EvaluationOptions, ) -> InterpolateResult<BatchEvaluationResult<T>>

Evaluate with options for advanced control
Source§

fn is_empty(&self) -> bool

Check if the interpolator is empty (no data points)
Source§

impl<T> SplineInterpolator<T> for BSpline<T>

Source§

fn derivative( &self, query_points: &ArrayView2<'_, T>, order: usize, ) -> InterpolateResult<Vec<T>>

Evaluate the nth derivative at query points
Source§

fn integrate(&self, bounds: &[(T, T)]) -> InterpolateResult<Vec<T>>

Evaluate the definite integral over specified bounds
Source§

fn antiderivative(&self) -> InterpolateResult<Box<dyn SplineInterpolator<T>>>

Get the antiderivative as a new spline
Source§

fn find_roots( &self, bounds: &[(T, T)], tolerance: T, ) -> InterpolateResult<Vec<T>>

Find roots of the spline within given bounds
Source§

fn find_extrema( &self, bounds: &[(T, T)], tolerance: T, ) -> InterpolateResult<Vec<(T, T, ExtremaType)>>

Find extrema (local minima and maxima) within given bounds

Auto Trait Implementations§

§

impl<T> Freeze for BSpline<T>

§

impl<T> RefUnwindSafe for BSpline<T>
where T: RefUnwindSafe,

§

impl<T> Send for BSpline<T>
where T: Send,

§

impl<T> Sync for BSpline<T>
where T: Sync,

§

impl<T> Unpin for BSpline<T>

§

impl<T> UnwindSafe for BSpline<T>
where T: RefUnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V