Trait peroxide::traits::fp::FPVector

source ·
pub trait FPVector {
    type Scalar;

    // Required methods
    fn fmap<F>(&self, f: F) -> Self
       where F: Fn(Self::Scalar) -> Self::Scalar;
    fn reduce<F, T>(&self, init: T, f: F) -> Self::Scalar
       where F: Fn(Self::Scalar, Self::Scalar) -> Self::Scalar,
             T: Into<Self::Scalar> + Copy;
    fn zip_with<F>(&self, f: F, other: &Self) -> Self
       where F: Fn(Self::Scalar, Self::Scalar) -> Self::Scalar;
    fn filter<F>(&self, f: F) -> Self
       where F: Fn(Self::Scalar) -> bool;
    fn take(&self, n: usize) -> Self;
    fn skip(&self, n: usize) -> Self;
    fn sum(&self) -> Self::Scalar;
    fn prod(&self) -> Self::Scalar;
}
Expand description

Functional Programming tools for Vector

Required Associated Types§

Required Methods§

source

fn fmap<F>(&self, f: F) -> Self
where F: Fn(Self::Scalar) -> Self::Scalar,

source

fn reduce<F, T>(&self, init: T, f: F) -> Self::Scalar
where F: Fn(Self::Scalar, Self::Scalar) -> Self::Scalar, T: Into<Self::Scalar> + Copy,

source

fn zip_with<F>(&self, f: F, other: &Self) -> Self
where F: Fn(Self::Scalar, Self::Scalar) -> Self::Scalar,

source

fn filter<F>(&self, f: F) -> Self
where F: Fn(Self::Scalar) -> bool,

source

fn take(&self, n: usize) -> Self

source

fn skip(&self, n: usize) -> Self

source

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

source

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

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl FPVector for Vec<AD>

source§

type Scalar = AD

source§

fn fmap<F>(&self, f: F) -> Self
where F: Fn(Self::Scalar) -> Self::Scalar,

source§

fn reduce<F, T>(&self, init: T, f: F) -> Self::Scalar
where F: Fn(Self::Scalar, Self::Scalar) -> Self::Scalar, T: Into<Self::Scalar>,

source§

fn zip_with<F>(&self, f: F, other: &Self) -> Self
where F: Fn(Self::Scalar, Self::Scalar) -> Self::Scalar,

source§

fn filter<F>(&self, f: F) -> Self
where F: Fn(Self::Scalar) -> bool,

source§

fn take(&self, n: usize) -> Self

source§

fn skip(&self, n: usize) -> Self

source§

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

source§

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

source§

impl FPVector for Vec<f64>

source§

fn fmap<F>(&self, f: F) -> Vec<f64>
where F: Fn(f64) -> f64,

fmap for Vec<f64>

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

fn main() {
    let a = c!(1,2,3,4,5);
    assert_eq!(a.fmap(|x| x*2f64), seq!(2,10,2));
}
source§

fn reduce<F, T>(&self, init: T, f: F) -> f64
where F: Fn(f64, f64) -> f64, T: Into<f64> + Copy,

reduce for Vec<f64>

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

fn main() {
    let a = seq!(1,100,1);
    assert_eq!(a.reduce(0, |x,y| x + y), 5050f64);
}
source§

fn filter<F>(&self, f: F) -> Vec<f64>
where F: Fn(f64) -> bool,

Filter for Vec<f64>

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

fn main() {
    let a = c!(1,2,3,4,5);
    let b = a.filter(|x| x > 3.);
    assert_eq!(b, c!(4,5));
}
source§

fn take(&self, n: usize) -> Vec<f64>

Take for Vec<f64>

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

fn main() {
    let a = c!(1,2,3,4,5);
    let b = a.take(3);
    assert_eq!(b, c!(1,2,3));
}
source§

fn skip(&self, n: usize) -> Vec<f64>

Skip for Vec<f64>

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

fn main() {
    let a = c!(1,2,3,4,5);
    let b = a.skip(3);
    assert_eq!(b, c!(4,5));
}
source§

type Scalar = f64

source§

fn zip_with<F>(&self, f: F, other: &Vec<f64>) -> Vec<f64>
where F: Fn(f64, f64) -> f64,

source§

fn sum(&self) -> f64

source§

fn prod(&self) -> f64

source§

impl FPVector for Vec<Complex<f64>>

source§

type Scalar = Complex<f64>

source§

fn fmap<F>(&self, f: F) -> Self
where F: Fn(Self::Scalar) -> Self::Scalar,

source§

fn zip_with<F>(&self, f: F, other: &Self) -> Self
where F: Fn(Self::Scalar, Self::Scalar) -> Self::Scalar,

source§

fn reduce<F, T>(&self, init: T, f: F) -> Self::Scalar
where F: Fn(Self::Scalar, Self::Scalar) -> Self::Scalar, T: Into<Self::Scalar>,

source§

fn filter<F>(&self, f: F) -> Self
where F: Fn(Self::Scalar) -> bool,

source§

fn take(&self, n: usize) -> Self

source§

fn skip(&self, n: usize) -> Self

source§

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

source§

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

Implementors§