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
fn rank(&self) -> Vec<usize>
fn sign(&self) -> f64
fn arg_max(&self) -> usize
fn swap_with_perm(&mut self, p: &Vec<(usize, usize)>)
Implementations on Foreign Types
sourceimpl Algorithm for Vec<f64>
impl Algorithm for Vec<f64>
sourcefn rank(&self) -> Vec<usize>
fn rank(&self) -> Vec<usize>
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]);
}
sourcefn sign(&self) -> f64
fn sign(&self) -> f64
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));
}
sourcefn arg_max(&self) -> usize
fn arg_max(&self) -> usize
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);
}