Skip to main content

IrlbaConfig

Struct IrlbaConfig 

Source
pub struct IrlbaConfig {
    pub rank: usize,
    pub work: Option<usize>,
    pub tol: f64,
    pub max_restarts: usize,
    pub seed: Option<u64>,
    pub mean_center: bool,
    pub require_convergence: bool,
}
Expand description

Configuration for svd_with.

Fields§

§rank: usize

Number of singular triplets wanted.

§work: Option<usize>

Basis size. Must exceed rank; defaults to rank + 7, clamped to min(rows, cols).

§This is the knob that matters on tall matrices

Each restart re-orthogonalises against the whole basis, so a step costs O(work · (rows + cols)) — on a matrix with a million rows that dominates the sparse products by a wide margin. A larger work makes each step dearer but converges in far fewer restarts, and the second effect wins comfortably.

Measured on 400k × 30k restricted to 2238 columns, 50 components (cargo run --release --example tune):

worktimematvecsaccuracy
rank + 7 (default)30.2 s15156.7e-17
rank + 3013.7 s7011.9e-14
rank + 5018.6 s6012.0e-14
rank + 10021.4 s5012.2e-14

So rank + 30 was 2.2× faster at the same accuracy. The cost is basis memory, which is linear in work: work · rows scalars for the left basis, or 600 MiB rather than 456 MiB at a million rows. The default stays conservative because memory is the reason to choose this crate; raise it when you have the headroom.

Run the tune example on your own shape rather than trusting these numbers — the optimum moves with the aspect ratio and the spectrum.

§tol: f64

Relative residual tolerance: triplet i is accepted once its residual falls below tol · σ_max.

§max_restarts: usize

Cap on restart cycles before giving up.

§seed: Option<u64>

Fixed seed for the starting vector; None draws from the OS.

§mean_center: bool

Subtract column means without materialising the centered matrix — i.e. PCA rather than plain SVD.

§require_convergence: bool

Refuse to return triplets that did not reach tol. Defaults to true.

Exhausting the restart budget means the answer is a best effort of unknown quality. Returning it as Ok puts the burden on every caller to remember to inspect the diagnostics, and a pipeline that forgets gets a silently degraded decomposition feeding whatever comes next. Failing loudly is the safer default; set this to false if a best effort is genuinely what you want, then check SvdRec::converged.

Implementations§

Source§

impl IrlbaConfig

Source

pub fn new(rank: usize) -> Self

Configuration for rank triplets, everything else defaulted.

Source

pub fn work(self, work: usize) -> Self

Set the basis size.

Source

pub fn tol(self, tol: f64) -> Self

Set the relative residual tolerance.

Source

pub fn max_restarts(self, n: usize) -> Self

Set the restart cap.

Source

pub fn seed(self, seed: u64) -> Self

Fix the seed, making the result reproducible.

Source

pub fn mean_center(self, yes: bool) -> Self

Enable implicit mean centering.

Source

pub fn allow_unconverged(self) -> Self

Accept a best-effort result instead of failing when the restart budget runs out.

Trait Implementations§

Source§

impl Clone for IrlbaConfig

Source§

fn clone(&self) -> IrlbaConfig

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 IrlbaConfig

Source§

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

Formats the value using the given formatter. Read more

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> 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> 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.