pub trait Algorithm {
    fn rank(&self) -> Vec<usize>;
    fn sign(&self) -> f64;
    fn arg_max(&self) -> usize;
    fn swap_with_perm(&mut self, p: &Vec<(usize, usize)>);
}
Expand description

Some algorithms for Vector

Required Methods

Implementations on Foreign Types

Assign rank

Examples
#[macro_use]
extern crate peroxide;
use peroxide::fuga::*;

fn main() {
    let v = c!(7, 5, 9, 2, 8);
    assert_eq!(v.rank(), vec![2,3,0,4,1]);
}

Sign of Permutation

Examples
#[macro_use]
extern crate peroxide;
use peroxide::fuga::*;

fn main() {
    let a = c!(1,0,2);
    let b = c!(1,2,0);
    let c = c!(0,1,2);

    assert_eq!((a.sign(), b.sign(), c.sign()), (-1f64, 1f64, 1f64));
}

arg max

Examples
#[macro_use]
extern crate peroxide;
use peroxide::fuga::*;

fn main() {
    let v = c!(1,3,2,4,3,7);
    assert_eq!(v.arg_max(),5);

    let v2 = c!(1,3,2,5,6,6);
    assert_eq!(v2.arg_max(),4);
}

Implementors