1 Star 0 Fork 0

yutiansut / Peroxide

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
fp.rs 1.76 KB
一键复制 编辑 原始数据 按行查看 历史
Axect 提交于 2020-07-17 15:40 . Cargo fmt
use crate::structure::matrix::Matrix;
use std::convert::Into;
/// Functional Programming tools for Vector
pub trait FPVector {
type Scalar;
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>;
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;
}
/// Functional Programming for Matrix
pub trait FPMatrix {
fn take_row(&self, n: usize) -> Matrix;
fn take_col(&self, n: usize) -> Matrix;
fn skip_row(&self, n: usize) -> Matrix;
fn skip_col(&self, n: usize) -> Matrix;
fn fmap<F>(&self, f: F) -> Matrix
where
F: Fn(f64) -> f64;
fn col_map<F>(&self, f: F) -> Matrix
where
F: Fn(Vec<f64>) -> Vec<f64>;
fn row_map<F>(&self, f: F) -> Matrix
where
F: Fn(Vec<f64>) -> Vec<f64>;
fn col_mut_map<F>(&mut self, f: F)
where
F: Fn(Vec<f64>) -> Vec<f64>;
fn row_mut_map<F>(&mut self, f: F)
where
F: Fn(Vec<f64>) -> Vec<f64>;
fn reduce<F, T>(&self, init: T, f: F) -> f64
where
F: Fn(f64, f64) -> f64,
T: Into<f64>;
fn zip_with<F>(&self, f: F, other: &Matrix) -> Matrix
where
F: Fn(f64, f64) -> f64;
fn col_reduce<F>(&self, f: F) -> Vec<f64>
where
F: Fn(Vec<f64>) -> f64;
fn row_reduce<F>(&self, f: F) -> Vec<f64>
where
F: Fn(Vec<f64>) -> f64;
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/yutiansut/Peroxide.git
git@gitee.com:yutiansut/Peroxide.git
yutiansut
Peroxide
Peroxide
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891