Trait peroxide::traits::general::Algorithm

source ·
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§

source

fn rank(&self) -> Vec<usize>

source

fn sign(&self) -> Self::Scalar

source

fn arg_max(&self) -> usize

source

fn arg_min(&self) -> usize

source

fn max(&self) -> Self::Scalar

source

fn min(&self) -> Self::Scalar

source

fn swap_with_perm(&mut self, p: &Vec<(usize, usize)>)

Implementations on Foreign Types§

source§

impl Algorithm for Vec<f64>

source§

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

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

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

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);
}
source§

type Scalar = f64

source§

fn max(&self) -> f64

source§

fn min(&self) -> f64

source§

fn swap_with_perm(&mut self, p: &Vec<(usize, usize)>)

source§

impl Algorithm for Vec<Complex<f64>>

source§

type Scalar = Complex<f64>

source§

fn rank(&self) -> Vec<usize>

source§

fn sign(&self) -> Complex<f64>

source§

fn arg_max(&self) -> usize

source§

fn arg_min(&self) -> usize

source§

fn max(&self) -> Complex<f64>

source§

fn min(&self) -> Complex<f64>

source§

fn swap_with_perm(&mut self, p: &Vec<(usize, usize)>)

Implementors§