Removes DenseVector

This commit is contained in:
Volodymyr Orlov
2019-12-18 10:28:15 -08:00
parent 4411b57219
commit 2425419d10
9 changed files with 376 additions and 590 deletions
+14 -118
View File
@@ -3,10 +3,16 @@ use std::fmt::Debug;
pub mod naive;
pub trait Matrix: Into<Vec<f64>> + Clone + Debug{
pub trait Matrix: Clone + Debug {
fn from_array(nrows: usize, ncols: usize, values: &[f64]) -> Self;
fn from_vec(nrows: usize, ncols: usize, values: Vec<f64>) -> Self;
fn get(&self, row: usize, col: usize) -> f64;
fn set(&mut self, row: usize, col: usize, x: f64);
fn qr_solve_mut(&mut self, b: Self) -> Self;
fn svd_solve_mut(&mut self, b: Self) -> Self;
@@ -15,7 +21,7 @@ pub trait Matrix: Into<Vec<f64>> + Clone + Debug{
fn ones(nrows: usize, ncols: usize) -> Self;
fn from_vector<V:Vector>(v: &V, nrows: usize, ncols: usize) -> Self;
fn to_raw_vector(&self) -> Vec<f64>;
fn fill(nrows: usize, ncols: usize, value: f64) -> Self;
@@ -27,7 +33,9 @@ pub trait Matrix: Into<Vec<f64>> + Clone + Debug{
fn dot(&self, other: &Self) -> Self;
fn slice(&self, rows: Range<usize>, cols: Range<usize>) -> Self;
fn vector_dot(&self, other: &Self) -> f64;
fn slice(&self, rows: Range<usize>, cols: Range<usize>) -> Self;
fn approximate_eq(&self, other: &Self, error: f64) -> bool;
@@ -139,120 +147,8 @@ pub trait Matrix: Into<Vec<f64>> + Clone + Debug{
result
}
fn argmax(&self) -> Vec<usize>;
}
pub trait Vector: Into<Vec<f64>> + Clone + Debug {
fn from_array(values: &[f64]) -> Self;
fn from_vec(values: &Vec<f64>) -> Self;
fn get(&self, i: usize) -> f64;
fn set(&mut self, i: usize, value: f64);
fn zeros(size: usize) -> Self;
fn ones(size: usize) -> Self;
fn fill(size: usize, value: f64) -> Self;
fn shape(&self) -> (usize, usize);
fn norm2(&self) -> f64;
fn norm(&self, p:f64) -> f64;
fn negative_mut(&mut self) -> &Self;
fn negative(&self) -> Self;
fn add_mut(&mut self, other: &Self) -> &Self;
fn sub_mut(&mut self, other: &Self) -> &Self;
fn mul_mut(&mut self, other: &Self) -> &Self;
fn div_mut(&mut self, other: &Self) -> &Self;
fn add(&self, other: &Self) -> Self {
let mut r = self.clone();
r.add_mut(other);
r
}
fn sub(&self, other: &Self) -> Self {
let mut r = self.clone();
r.sub_mut(other);
r
}
fn mul(&self, other: &Self) -> Self {
let mut r = self.clone();
r.mul_mut(other);
r
}
fn div(&self, other: &Self) -> Self {
let mut r = self.clone();
r.div_mut(other);
r
}
fn add_scalar_mut(&mut self, scalar: f64) -> &Self;
fn sub_scalar_mut(&mut self, scalar: f64) -> &Self;
fn mul_scalar_mut(&mut self, scalar: f64) -> &Self;
fn div_scalar_mut(&mut self, scalar: f64) -> &Self;
fn add_scalar(&self, scalar: f64) -> Self{
let mut r = self.clone();
r.add_scalar_mut(scalar);
r
}
fn sub_scalar(&self, scalar: f64) -> Self{
let mut r = self.clone();
r.sub_scalar_mut(scalar);
r
}
fn mul_scalar(&self, scalar: f64) -> Self{
let mut r = self.clone();
r.mul_scalar_mut(scalar);
r
}
fn div_scalar(&self, scalar: f64) -> Self{
let mut r = self.clone();
r.div_scalar_mut(scalar);
r
}
fn dot(&self, other: &Self) -> f64;
fn copy_from(&mut self, other: &Self);
fn abs_mut(&mut self) -> &Self;
fn pow_mut(&mut self, p: f64) -> &Self;
fn sum(&self) -> f64;
fn abs(&self) -> Self{
let mut r = self.clone();
r.abs_mut();
r
}
fn max_diff(&self, other: &Self) -> f64;
fn argmax(&self) -> Vec<usize>;
fn softmax_mut(&mut self);
fn unique(&self) -> Vec<f64>;
fn unique(&self) -> Vec<f64>;
}
}