Expand description
§sparse-ir-sve
The singular value expansion (SVE) of integral kernels K(x, y), computed in extended precision with an ACA-accelerated truncated SVD, and the numerics it is built on: Gauss–Legendre quadrature, piecewise Legendre polynomials, dense column-major containers, the error type, the FPU guard, and the parallel execution on the rayon pool.
A kernel implements AbstractKernel (its values) and SVEKernel (its
domain and the discretization hints of its SVE), and either
ReducedKernel (a centrosymmetric kernel, through its even and odd
reduced kernels) or ExpandableKernel (any other kernel, no methods);
compute_sve then returns its singular values and singular functions
(SVEResult).
In f64, compute_sve decomposes the discretized kernel by a dense
column-pivoted QR; in double-double (Df64), where that is costly, by
adaptive cross approximation (ACA), which reads only a few rows and
columns of it. The one exception is the full-domain SVE of a
centrosymmetric kernel (SVEOptions::full_domain), which keeps the
dense QR in Df64 too: its single block holds nearly degenerate pairs of
singular values. unstable::sve::compute_sve_dense takes the dense
path in both, to check the result on a new kernel.
The crate is mathematics only: it defines no concrete kernel. The
sparse-ir crates define the kernels of the IR basis and build the basis
on top of it.
§Example
The SVE of K(x, y) = exp(xy) on [-1, 1] × [-1, 1]. The kernel is
centrosymmetric, K(-x, -y) = K(x, y), so the SVE is computed in even and
odd blocks: the even and odd reduced kernels K(x, y) ± K(x, -y) are
2 cosh(xy) and 2 sinh(xy). SegmentHints discretizes it on segments of
equal length.
use sparse_ir_sve::{
AbstractKernel, CustomNumeric, ReducedKernel, SVEKernel, SegmentHints, SymmetryType,
TworkType, compute_sve, sve_residual,
};
use std::fmt::Debug;
#[derive(Debug, Clone, Copy)]
struct ExpKernel;
impl AbstractKernel for ExpKernel {
fn compute<T: CustomNumeric + Copy + Debug>(&self, x: T, y: T) -> T {
(x * y).exp()
}
}
impl ReducedKernel for ExpKernel {
fn compute_reduced<T: CustomNumeric + Copy + Debug>(
&self,
x: T,
y: T,
symmetry: SymmetryType,
) -> T {
let two = T::from_f64_unchecked(2.0);
match symmetry {
SymmetryType::Even => two * (x * y).cosh(),
SymmetryType::Odd => two * (x * y).sinh(),
}
}
}
impl SVEKernel for ExpKernel {
type SVEHintsType<T>
= SegmentHints
where
T: Copy + Debug + Send + Sync + CustomNumeric + 'static;
fn xmax(&self) -> f64 {
1.0
}
fn ymax(&self) -> f64 {
1.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()
}
}
let sve = compute_sve(ExpKernel, Some(1e-10), None, None, TworkType::Auto)?;
let s = sve.s();
assert!(s.windows(2).all(|w| w[0] >= w[1]));
// K(x, y) = Σ_l s_l u_l(x) v_l(y), to the requested accuracy
let (x, y) = (0.3, -0.7);
let k: f64 = (0..s.len())
.map(|l| s[l] * sve.u()[l].evaluate(x) * sve.v()[l].evaluate(y))
.sum();
assert!((k - f64::exp(x * y)).abs() < 1e-8);
// The segments resolve the kernel: the residual is far below 1e-10
assert!(sve_residual(&ExpKernel, &sve) < 1e-12);Re-exports§
pub use error::Error;pub use error::ErrorKind;pub use error::Result;pub use gauss::Rule;pub use gauss::legendre;pub use hints::SegmentHints;pub use kernel::AbstractKernel;pub use kernel::ExpandableKernel;pub use kernel::ReducedKernel;pub use kernel::SVEHints;pub use kernel::SVEKernel;pub use kernel::SymmetryType;pub use matrix::Mat;pub use matrix::Mat3;pub use numeric::CustomNumeric;pub use poly::PiecewiseLegendrePoly;pub use poly::PiecewiseLegendrePolyVector;pub use sve::SVEOptions;pub use sve::SVEResult;pub use sve::TworkType;pub use sve::compute_sve;pub use sve::compute_sve_with;pub use sve::sve_residual;
Modules§
- error
- Error type of the public API
- gauss
- Gauss quadrature rules for numerical integration
- hints
- SVE hints given by the segments of the domain
- kernel
- Kernels K(x, y) and the traits the singular value expansion needs
- matrix
- Small column-major dense containers for internal numerics.
- numeric
- Custom numeric traits for high-precision computation
- poly
- Piecewise Legendre polynomials
- sve
- Singular Value Expansion (SVE) module
- unstable
- Items the other
sparse-ircrates build on, outside the semver guarantees of this crate
Type Aliases§
- Df64
- Compensated f64 (emulated quad precision) type.