Skip to main content

SegmentHints

Struct SegmentHints 

Source
pub struct SegmentHints { /* private fields */ }
Expand description

SVEHints given by the segment boundaries of the domain

The boundaries are given on the full domain [xmin, xmax] × [ymin, ymax] of the kernel, whether it is centrosymmetric or not. A centrosymmetric kernel is discretized on [0, xmax] × [0, ymax] and the mirror images of its segments (SVEHints): the boundaries in (0, xmax] ((0, ymax]), with 0 added if it is not one of them.

The accuracy of the SVE depends on the segments: on each of them, the kernel must be resolved by polynomials of degree ngauss - 1 in each variable. sve_residual measures how well the result reproduces the kernel.

§Example

use sparse_ir_sve::{AbstractKernel, CustomNumeric, SVEKernel, ExpandableKernel, SegmentHints};
use std::fmt::Debug;

/// K(x, y) = exp(-(x - y)²) on [-1, 1] × [0, 2]
#[derive(Clone)]
struct Gaussian;

impl AbstractKernel for Gaussian {
    fn compute<T: CustomNumeric + Copy + Debug>(&self, x: T, y: T) -> T {
        (-(x - y) * (x - y)).exp()
    }
}

impl SVEKernel for Gaussian {
    type SVEHintsType<T>
        = SegmentHints
    where
        T: Copy + Debug + Send + Sync + CustomNumeric + 'static;

    fn xmax(&self) -> f64 {
        1.0
    }

    fn ymax(&self) -> f64 {
        2.0
    }

    fn ymin(&self) -> f64 {
        0.0
    }

    fn sve_hints<T>(&self, _epsilon: f64) -> SegmentHints
    where
        T: Copy + Debug + Send + Sync + CustomNumeric + 'static,
    {
        // Four segments on each axis, 16 Gauss points on each segment
        SegmentHints::uniform(self, 4, 4, 16).unwrap()
    }
}

// Not centrosymmetric: the SVE is taken over the full domain
impl ExpandableKernel for Gaussian {}

Implementations§

Source§

impl SegmentHints

Source

pub fn new<K: SVEKernel>( kernel: &K, segments_x: &[f64], segments_y: &[f64], ngauss: usize, ) -> Result<Self, Error>

Hints with the segment boundaries segments_x and segments_y of the full domain of kernel and ngauss Gauss points per segment

§Errors

Error::InvalidParameter if ngauss is 0, or the boundaries on an axis are not finite and strictly increasing from the lower to the upper bound of the domain of kernel on that axis (as SVEKernel::xmin and SVEKernel::xmax return them)

Source

pub fn uniform<K: SVEKernel>( kernel: &K, nseg_x: usize, nseg_y: usize, ngauss: usize, ) -> Result<Self, Error>

Hints with nseg_x and nseg_y segments of equal length on the full domain of kernel and ngauss Gauss points per segment

On a domain symmetric about 0, the boundaries are symmetric as well, so a centrosymmetric kernel with an even number of segments is discretized on half of them.

§Errors

Error::InvalidParameter if nseg_x, nseg_y or ngauss is 0, or the domain of kernel is not a finite, non-empty interval on an axis

Trait Implementations§

Source§

impl Clone for SegmentHints

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for SegmentHints

Source§

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

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

impl PartialEq for SegmentHints

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<T> SVEHints<T> for SegmentHints
where T: Copy + Debug + Send + Sync + CustomNumeric,

Source§

fn nsvals(&self) -> usize

The number of singular values the discretization can resolve, at most ngauss per segment on the axis with fewer segments; the SVE does not use it

Source§

fn segments_x(&self) -> Vec<T>

Segment boundaries on x: strictly increasing from xmin to xmax Read more
Source§

fn segments_y(&self) -> Vec<T>

Segment boundaries on y: strictly increasing from ymin to ymax Read more
Source§

fn ngauss(&self) -> usize

Get the number of Gauss points for quadrature
Source§

impl StructuralPartialEq for SegmentHints

Auto Trait Implementations§

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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,

§

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

§

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

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

fn is_in_subset(&self) -> bool

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

fn to_subset_unchecked(&self) -> SS

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

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.