fix: minor refactoring
This commit is contained in:
+11
-11
@@ -6,13 +6,13 @@ use crate::math::num::FloatExt;
|
||||
use std::fmt::Debug;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct EVD<T: FloatExt + Debug, M: BaseMatrix<T>> {
|
||||
pub struct EVD<T: FloatExt, M: BaseMatrix<T>> {
|
||||
pub d: Vec<T>,
|
||||
pub e: Vec<T>,
|
||||
pub V: M
|
||||
}
|
||||
|
||||
impl<T: FloatExt + Debug, M: BaseMatrix<T>> EVD<T, M> {
|
||||
impl<T: FloatExt, M: BaseMatrix<T>> EVD<T, M> {
|
||||
pub fn new(V: M, d: Vec<T>, e: Vec<T>) -> EVD<T, M> {
|
||||
EVD {
|
||||
d: d,
|
||||
@@ -22,7 +22,7 @@ impl<T: FloatExt + Debug, M: BaseMatrix<T>> EVD<T, M> {
|
||||
}
|
||||
}
|
||||
|
||||
pub trait EVDDecomposableMatrix<T: FloatExt + Debug>: BaseMatrix<T> {
|
||||
pub trait EVDDecomposableMatrix<T: FloatExt>: BaseMatrix<T> {
|
||||
|
||||
fn evd(&self, symmetric: bool) -> EVD<T, Self>{
|
||||
self.clone().evd_mut(symmetric)
|
||||
@@ -68,7 +68,7 @@ pub trait EVDDecomposableMatrix<T: FloatExt + Debug>: BaseMatrix<T> {
|
||||
}
|
||||
}
|
||||
|
||||
fn tred2<T: FloatExt + Debug, M: BaseMatrix<T>>(V: &mut M, d: &mut Vec<T>, e: &mut Vec<T>) {
|
||||
fn tred2<T: FloatExt, M: BaseMatrix<T>>(V: &mut M, d: &mut Vec<T>, e: &mut Vec<T>) {
|
||||
|
||||
let (n, _) = V.shape();
|
||||
for i in 0..n {
|
||||
@@ -172,7 +172,7 @@ fn tred2<T: FloatExt + Debug, M: BaseMatrix<T>>(V: &mut M, d: &mut Vec<T>, e: &m
|
||||
e[0] = T::zero();
|
||||
}
|
||||
|
||||
fn tql2<T: FloatExt + Debug, M: BaseMatrix<T>>(V: &mut M, d: &mut Vec<T>, e: &mut Vec<T>) {
|
||||
fn tql2<T: FloatExt, M: BaseMatrix<T>>(V: &mut M, d: &mut Vec<T>, e: &mut Vec<T>) {
|
||||
let (n, _) = V.shape();
|
||||
for i in 1..n {
|
||||
e[i - 1] = e[i];
|
||||
@@ -288,7 +288,7 @@ fn tql2<T: FloatExt + Debug, M: BaseMatrix<T>>(V: &mut M, d: &mut Vec<T>, e: &mu
|
||||
}
|
||||
}
|
||||
|
||||
fn balance<T: FloatExt + Debug, M: BaseMatrix<T>>(A: &mut M) -> Vec<T> {
|
||||
fn balance<T: FloatExt, M: BaseMatrix<T>>(A: &mut M) -> Vec<T> {
|
||||
let radix = T::two();
|
||||
let sqrdx = radix * radix;
|
||||
|
||||
@@ -341,7 +341,7 @@ fn balance<T: FloatExt + Debug, M: BaseMatrix<T>>(A: &mut M) -> Vec<T> {
|
||||
return scale;
|
||||
}
|
||||
|
||||
fn elmhes<T: FloatExt + Debug, M: BaseMatrix<T>>(A: &mut M) -> Vec<usize> {
|
||||
fn elmhes<T: FloatExt, M: BaseMatrix<T>>(A: &mut M) -> Vec<usize> {
|
||||
let (n, _) = A.shape();
|
||||
let mut perm = vec![0; n];
|
||||
|
||||
@@ -387,7 +387,7 @@ fn elmhes<T: FloatExt + Debug, M: BaseMatrix<T>>(A: &mut M) -> Vec<usize> {
|
||||
return perm;
|
||||
}
|
||||
|
||||
fn eltran<T: FloatExt + Debug, M: BaseMatrix<T>>(A: &M, V: &mut M, perm: &Vec<usize>) {
|
||||
fn eltran<T: FloatExt, M: BaseMatrix<T>>(A: &M, V: &mut M, perm: &Vec<usize>) {
|
||||
let (n, _) = A.shape();
|
||||
for mp in (1..n - 1).rev() {
|
||||
for k in mp + 1..n {
|
||||
@@ -404,7 +404,7 @@ fn eltran<T: FloatExt + Debug, M: BaseMatrix<T>>(A: &M, V: &mut M, perm: &Vec<us
|
||||
}
|
||||
}
|
||||
|
||||
fn hqr2<T: FloatExt + Debug, M: BaseMatrix<T>>(A: &mut M, V: &mut M, d: &mut Vec<T>, e: &mut Vec<T>) {
|
||||
fn hqr2<T: FloatExt, M: BaseMatrix<T>>(A: &mut M, V: &mut M, d: &mut Vec<T>, e: &mut Vec<T>) {
|
||||
let (n, _) = A.shape();
|
||||
let mut z = T::zero();
|
||||
let mut s = T::zero();
|
||||
@@ -742,7 +742,7 @@ fn hqr2<T: FloatExt + Debug, M: BaseMatrix<T>>(A: &mut M, V: &mut M, d: &mut Vec
|
||||
}
|
||||
}
|
||||
|
||||
fn balbak<T: FloatExt + Debug, M: BaseMatrix<T>>(V: &mut M, scale: &Vec<T>) {
|
||||
fn balbak<T: FloatExt, M: BaseMatrix<T>>(V: &mut M, scale: &Vec<T>) {
|
||||
let (n, _) = V.shape();
|
||||
for i in 0..n {
|
||||
for j in 0..n {
|
||||
@@ -751,7 +751,7 @@ fn balbak<T: FloatExt + Debug, M: BaseMatrix<T>>(V: &mut M, scale: &Vec<T>) {
|
||||
}
|
||||
}
|
||||
|
||||
fn sort<T: FloatExt + Debug, M: BaseMatrix<T>>(d: &mut Vec<T>, e: &mut Vec<T>, V: &mut M) {
|
||||
fn sort<T: FloatExt, M: BaseMatrix<T>>(d: &mut Vec<T>, e: &mut Vec<T>, V: &mut M) {
|
||||
let n = d.len();
|
||||
let mut temp = vec![T::zero(); n];
|
||||
for j in 1..n {
|
||||
|
||||
@@ -16,7 +16,7 @@ use crate::linalg::qr::QRDecomposableMatrix;
|
||||
use crate::math::num::FloatExt;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct DenseMatrix<T: FloatExt + Debug> {
|
||||
pub struct DenseMatrix<T: FloatExt> {
|
||||
|
||||
ncols: usize,
|
||||
nrows: usize,
|
||||
@@ -24,7 +24,7 @@ pub struct DenseMatrix<T: FloatExt + Debug> {
|
||||
|
||||
}
|
||||
|
||||
impl<T: FloatExt + Debug> fmt::Display for DenseMatrix<T> {
|
||||
impl<T: FloatExt> fmt::Display for DenseMatrix<T> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
let mut rows: Vec<Vec<f64>> = Vec::new();
|
||||
for r in 0..self.nrows {
|
||||
@@ -34,7 +34,7 @@ impl<T: FloatExt + Debug> fmt::Display for DenseMatrix<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: FloatExt + Debug> DenseMatrix<T> {
|
||||
impl<T: FloatExt> DenseMatrix<T> {
|
||||
|
||||
fn new(nrows: usize, ncols: usize, values: Vec<T>) -> Self {
|
||||
DenseMatrix {
|
||||
@@ -182,15 +182,15 @@ impl<T: FloatExt + fmt::Debug + Serialize> Serialize for DenseMatrix<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: FloatExt + Debug> SVDDecomposableMatrix<T> for DenseMatrix<T> {}
|
||||
impl<T: FloatExt> SVDDecomposableMatrix<T> for DenseMatrix<T> {}
|
||||
|
||||
impl<T: FloatExt + Debug> EVDDecomposableMatrix<T> for DenseMatrix<T> {}
|
||||
impl<T: FloatExt> EVDDecomposableMatrix<T> for DenseMatrix<T> {}
|
||||
|
||||
impl<T: FloatExt + Debug> QRDecomposableMatrix<T> for DenseMatrix<T> {}
|
||||
impl<T: FloatExt> QRDecomposableMatrix<T> for DenseMatrix<T> {}
|
||||
|
||||
impl<T: FloatExt + Debug> Matrix<T> for DenseMatrix<T> {}
|
||||
impl<T: FloatExt> Matrix<T> for DenseMatrix<T> {}
|
||||
|
||||
impl<T: FloatExt + Debug> PartialEq for DenseMatrix<T> {
|
||||
impl<T: FloatExt> PartialEq for DenseMatrix<T> {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
if self.ncols != other.ncols || self.nrows != other.nrows {
|
||||
return false
|
||||
@@ -213,13 +213,13 @@ impl<T: FloatExt + Debug> PartialEq for DenseMatrix<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: FloatExt + Debug> Into<Vec<T>> for DenseMatrix<T> {
|
||||
impl<T: FloatExt> Into<Vec<T>> for DenseMatrix<T> {
|
||||
fn into(self) -> Vec<T> {
|
||||
self.values
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: FloatExt + Debug> BaseMatrix<T> for DenseMatrix<T> {
|
||||
impl<T: FloatExt> BaseMatrix<T> for DenseMatrix<T> {
|
||||
|
||||
type RowVector = Vec<T>;
|
||||
|
||||
|
||||
+3
-3
@@ -6,13 +6,13 @@ use crate::math::num::FloatExt;
|
||||
use crate::linalg::BaseMatrix;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct QR<T: FloatExt + Debug, M: BaseMatrix<T>> {
|
||||
pub struct QR<T: FloatExt, M: BaseMatrix<T>> {
|
||||
QR: M,
|
||||
tau: Vec<T>,
|
||||
singular: bool
|
||||
}
|
||||
|
||||
impl<T: FloatExt + Debug, M: BaseMatrix<T>> QR<T, M> {
|
||||
impl<T: FloatExt, M: BaseMatrix<T>> QR<T, M> {
|
||||
pub fn new(QR: M, tau: Vec<T>) -> QR<T, M> {
|
||||
|
||||
let mut singular = false;
|
||||
@@ -112,7 +112,7 @@ impl<T: FloatExt + Debug, M: BaseMatrix<T>> QR<T, M> {
|
||||
}
|
||||
}
|
||||
|
||||
pub trait QRDecomposableMatrix<T: FloatExt + Debug>: BaseMatrix<T> {
|
||||
pub trait QRDecomposableMatrix<T: FloatExt>: BaseMatrix<T> {
|
||||
|
||||
fn qr(&self) -> QR<T, Self> {
|
||||
self.clone().qr_mut()
|
||||
|
||||
+3
-3
@@ -5,7 +5,7 @@ use crate::math::num::FloatExt;
|
||||
use std::fmt::Debug;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct SVD<T: FloatExt + Debug, M: SVDDecomposableMatrix<T>> {
|
||||
pub struct SVD<T: FloatExt, M: SVDDecomposableMatrix<T>> {
|
||||
pub U: M,
|
||||
pub V: M,
|
||||
pub s: Vec<T>,
|
||||
@@ -15,7 +15,7 @@ pub struct SVD<T: FloatExt + Debug, M: SVDDecomposableMatrix<T>> {
|
||||
tol: T
|
||||
}
|
||||
|
||||
pub trait SVDDecomposableMatrix<T: FloatExt + Debug>: BaseMatrix<T> {
|
||||
pub trait SVDDecomposableMatrix<T: FloatExt>: BaseMatrix<T> {
|
||||
|
||||
fn svd_solve_mut(self, b: Self) -> Self {
|
||||
self.svd_mut().solve(b)
|
||||
@@ -373,7 +373,7 @@ pub trait SVDDecomposableMatrix<T: FloatExt + Debug>: BaseMatrix<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: FloatExt + Debug, M: SVDDecomposableMatrix<T>> SVD<T, M> {
|
||||
impl<T: FloatExt, M: SVDDecomposableMatrix<T>> SVD<T, M> {
|
||||
pub fn new(U: M, V: M, s: Vec<T>) -> SVD<T, M> {
|
||||
let m = U.shape().0;
|
||||
let n = V.shape().0;
|
||||
|
||||
Reference in New Issue
Block a user