packages

linalg::scalar

On this page

Element types: Scalar is what every routine needs (f32, f64 and their complex forms), Real adds ordering and the float functions for the iterative routines (SVD, eigen) and for norms.

Traits

ScalarSource

pub trait Scalar: Copy + num::Zero + num::One + ops::Add<Output = Self> + ops::Sub<Output = Self>
    + ops::Mul<Output = Self> + ops::Div<Output = Self> + ops::Neg<Output = Self> + PartialEq + Debug + Send + Sync

An element type the routines accept: f32, f64, Complex<f32>, Complex<f64>. Real is the type of a modulus or a norm.

nabi
use linalg::Scalar;
use core::num::Complex;

let z = 3.0 + 4.0i;
assert(z.modulus() == 5.0);
assert(z.conj() == Complex::new(3.0, -4.0));
  • const COMPLEX: bool§

    Source

    true for the complex types.

  • fn conj(self) -> Self§

    Source

    The complex conjugate (the value itself for a real type).

  • fn re(self) -> Self::Real§

    Source

    The real part.

  • fn im(self) -> Self::Real§

    Source

    The imaginary part (0 for a real type).

  • fn modulus(self) -> Self::Real§

    Source

    |x|, without overflow for complex values.

  • fn abs1(self) -> Self::Real§

    Source

    |re| + |im|, a cheap modulus for pivot searches.

  • fn from_real(r: Self::Real) -> Self§

    Source

    r as this type.

  • fn scale(self, r: Self::Real) -> Self§

    Source

    self * r for a real r.

  • fn root(self) -> Self§

    Source

    The principal square root.

  • fn finite(self) -> bool§

    Source

    true unless a part is NaN or infinite.

  • fn of(x: f64) -> Self§

    Source

    x rounded to this type.

RealSource

pub trait Real: Scalar<Real = Self> + FloatingPoint

A real element type, f32 or f64: what the SVD and the eigensolvers take, and the type of every norm.

nabi
use core::array::Matrix;

fn top<T: linalg::Real>(a: Matrix<T>) -> T { (try! linalg::svdvals(a))[0] }

let a: Matrix<f32> = [[3, 0], [0, 1]];
assert(top(a) == 3.0f32);