Skip to main content

Svd

Struct Svd 

Source
pub struct Svd<T: Scalar> { /* private fields */ }
Expand description

The singular value decomposition A = U·Σ·V* of an m × n matrix, k = min(m, n): U of m × k and V of n × k with orthonormal columns, Σ the diagonal of the singular values, real, not negative, in descending order. From Matrix::svd.

§Examples

use a::math::matrix::Matrix;

let a: Matrix<f64> = Matrix::from_rows(&[[3.0, 0.0], [4.0, 5.0]]);
let svd = a.svd();
let s = svd.singular_values();
assert!((s[0] - 45f64.sqrt()).abs() < 1e-14 && (s[1] - 5f64.sqrt()).abs() < 1e-14);
let sigma = Matrix::from_diagonal(s);
let back = &(&svd.u() * &sigma) * &svd.v().transpose();
assert!((&back - &a).as_slice().iter().all(|x| x.abs() < 1e-14));

Implementations§

Source§

impl<T: Scalar> Svd<T>

Source

pub fn u(&self) -> Matrix<T>

U, m × min(m, n), the left singular vectors as orthonormal columns.

Source

pub fn singular_values(&self) -> &[T::Real]

The singular values, real, not negative, in descending order.

Source

pub fn v(&self) -> Matrix<T>

V, n × min(m, n), the right singular vectors as orthonormal columns.

Trait Implementations§

Source§

impl<T: Clone + Scalar> Clone for Svd<T>
where T::Real: Clone,

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<T: Debug + Scalar> Debug for Svd<T>
where T::Real: Debug,

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Svd<T>
where Matrix<T>: Freeze, Vec<<T as Scalar>::Real>: Freeze,

§

impl<T> RefUnwindSafe for Svd<T>

§

impl<T> Send for Svd<T>
where Matrix<T>: Send, Vec<<T as Scalar>::Real>: Send,

§

impl<T> Sync for Svd<T>
where Matrix<T>: Sync, Vec<<T as Scalar>::Real>: Sync,

§

impl<T> Unpin for Svd<T>
where Matrix<T>: Unpin, Vec<<T as Scalar>::Real>: Unpin,

§

impl<T> UnsafeUnpin for Svd<T>

§

impl<T> UnwindSafe for Svd<T>
where Matrix<T>: UnwindSafe, Vec<<T as Scalar>::Real>: UnwindSafe,

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