pub trait Algorithm {
type Scalar;
// Required methods
fn rank(&self) -> Vec<usize>;
fn sign(&self) -> Self::Scalar;
fn arg_max(&self) -> usize;
fn arg_min(&self) -> usize;
fn max(&self) -> Self::Scalar;
fn min(&self) -> Self::Scalar;
fn swap_with_perm(&mut self, p: &Vec<(usize, usize)>);
}
Expand description
Some algorithms for Vector
Required Associated Types§
Required Methods§
fn rank(&self) -> Vec<usize>
fn sign(&self) -> Self::Scalar
fn arg_max(&self) -> usize
fn arg_min(&self) -> usize
fn max(&self) -> Self::Scalar
fn min(&self) -> Self::Scalar
fn swap_with_perm(&mut self, p: &Vec<(usize, usize)>)
Implementations on Foreign Types§
source§impl Algorithm for Vec<f64>
impl Algorithm for Vec<f64>
source§fn 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]);
}
source§fn 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));
}
source§fn 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);
}
source§fn arg_min(&self) -> usize
fn arg_min(&self) -> usize
arg min
§Examples
#[macro_use]
extern crate peroxide;
use peroxide::fuga::*;
fn main() {
let v = c!(1,3,2,4,3,7);
assert_eq!(v.arg_min(),0);
let v2 = c!(4,3,2,5,1,6);
assert_eq!(v2.arg_min(),4);
}