Skip to content

Commit

Permalink
Merge branch 'features/matrix' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Axect committed Oct 25, 2024
2 parents ec47ac7 + 206f46d commit 5ad6170
Show file tree
Hide file tree
Showing 19 changed files with 851 additions and 890 deletions.
1,022 changes: 472 additions & 550 deletions src/complex/matrix.rs

Large diffs are not rendered by default.

12 changes: 10 additions & 2 deletions src/fuga/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ pub use crate::traits::{
fp::{FPMatrix, FPVector},
general::Algorithm,
math::{InnerProduct, LinearOp, MatrixProduct, Norm, Normed, Vector, VectorProduct},
matrix::{MatrixTrait, LinearAlgebra},
mutable::{MutFP, MutMatrix},
num::Real,
pointer::{MatrixPtr, Oxide, Redox, RedoxCommon},
Expand All @@ -171,7 +172,14 @@ pub use crate::traits::{
mutable::ParallelMutFP,
};

#[cfg(feature = "complex")]
pub use crate::complex::{
C64,
matrix::*,
};

#[allow(unused_imports)]
#[allow(ambiguous_glob_reexports)]
pub use crate::structure::{
matrix::*,
polynomial::*,
Expand Down Expand Up @@ -226,11 +234,11 @@ pub use crate::numerical::integral::Integral::{
pub use crate::statistics::stat::QType::{
Type1, Type2, Type3, Type4, Type5, Type6, Type7, Type8, Type9,
};
pub use crate::structure::matrix::{
pub use crate::traits::matrix::{
Form::{Diagonal, Identity},
SolveKind::{LU, WAZ},
UPLO::{Upper, Lower}
};
pub use crate::structure::matrix::UPLO::{Upper, Lower};
pub use crate::structure::dataframe::DType::*;
pub use crate::structure::ad::AD::*;
pub use crate::numerical::spline::SlopeMethod::{Akima, Quadratic};
Expand Down
1 change: 1 addition & 0 deletions src/numerical/eigen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
pub use self::EigenMethod::*;
use crate::structure::matrix::Matrix;
use crate::traits::matrix::MatrixTrait;
use crate::util::non_macro::eye_shape;

#[derive(Debug, Copy, Clone)]
Expand Down
2 changes: 1 addition & 1 deletion src/numerical/newton.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::numerical::utils::jacobian;
use crate::structure::matrix::*;
use crate::structure::ad::*;
use crate::traits::{
math::{Norm, Normed, Vector},
mutable::MutFP,
matrix::LinearAlgebra,
};

/// Newton-Raphson Method
Expand Down
3 changes: 2 additions & 1 deletion src/numerical/optimize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@
pub use self::OptMethod::{GaussNewton, GradientDescent, LevenbergMarquardt};
use self::OptOption::{InitParam, MaxIter};
use crate::numerical::utils::jacobian;
use crate::structure::matrix::{LinearAlgebra, Matrix};
use crate::structure::matrix::Matrix;
use crate::traits::matrix::{MatrixTrait, LinearAlgebra};
use crate::structure::ad::{AD, ADVec};
use crate::util::useful::max;
use std::collections::HashMap;
Expand Down
1 change: 1 addition & 0 deletions src/numerical/spline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ use crate::structure::matrix::*;
use crate::structure::polynomial::*;
#[allow(unused_imports)]
use crate::structure::vector::*;
use crate::traits::matrix::LinearAlgebra;
#[allow(unused_imports)]
use crate::util::non_macro::*;
use crate::util::useful::zip_range;
Expand Down
1 change: 1 addition & 0 deletions src/numerical/utils.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::structure::matrix::*;
use crate::traits::matrix::MatrixTrait;
use crate::structure::ad::*;
use crate::structure::ad::AD::*;
use crate::util::non_macro::{cat, zeros};
Expand Down
12 changes: 11 additions & 1 deletion src/prelude/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ pub use crate::traits::{
fp::{FPMatrix, FPVector},
general::Algorithm,
math::{InnerProduct, LinearOp, MatrixProduct, Vector, VectorProduct},
matrix::{MatrixTrait, PQLU, QR, WAZD},
mutable::{MutFP, MutMatrix},
num::Real,
pointer::{MatrixPtr, Oxide, Redox, RedoxCommon},
Expand All @@ -169,7 +170,7 @@ pub use crate::structure::{
ad::AD::*,
matrix::{
combine, diag, gemm, gemv, gen_householder, inv_l, inv_u, matrix, ml_matrix, py_matrix,
r_matrix, Col, Matrix, Row, Shape, PQLU, QR, WAZD,
r_matrix, Col, Matrix, Row, Shape,
},
polynomial::{Polynomial,poly,Calculus,lagrange_polynomial,legendre_polynomial},
vector::*,
Expand All @@ -184,6 +185,15 @@ pub use crate::structure::dataframe::WithCSV;
#[cfg(feature="nc")]
pub use crate::structure::dataframe::WithNetCDF;

#[cfg(feature = "complex")]
#[allow(ambiguous_glob_reexports)]
pub use crate::complex::{
C64,
matrix::*,
vector::*,
integral::*,
};

pub use simpler::{solve, SimplerLinearAlgebra};

#[allow(unused_imports)]
Expand Down
79 changes: 40 additions & 39 deletions src/prelude/simpler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ use crate::numerical::{
};
#[cfg(feature = "parquet")]
use crate::structure::dataframe::{DataFrame, WithParquet};
use crate::structure::matrix::{self, Matrix};
use crate::structure::matrix::Matrix;
use crate::structure::polynomial;
use crate::traits::math::{Norm, Normed};
use crate::traits::matrix::{MatrixTrait, LinearAlgebra, PQLU, WAZD, QR, Form, SolveKind};
#[cfg(feature = "parquet")]
use arrow2::io::parquet::write::CompressionOptions;
#[cfg(feature = "parquet")]
Expand All @@ -28,22 +29,22 @@ pub fn integrate<F: Fn(f64) -> f64 + Copy>(f: F, (a, b): (f64, f64)) -> f64 {
}

/// Simple Linear algebra
pub trait SimplerLinearAlgebra {
fn back_subs(&self, b: &Vec<f64>) -> Vec<f64>;
fn forward_subs(&self, b: &Vec<f64>) -> Vec<f64>;
fn lu(&self) -> matrix::PQLU;
fn waz_diag(&self) -> Option<matrix::WAZD>;
fn waz(&self) -> Option<matrix::WAZD>;
fn qr(&self) -> matrix::QR;
pub trait SimplerLinearAlgebra<M:MatrixTrait> {
fn back_subs(&self, b: &[f64]) -> Vec<f64>;
fn forward_subs(&self, b: &[f64]) -> Vec<f64>;
fn lu(&self) -> PQLU<M>;
fn waz_diag(&self) -> Option<WAZD<M>>;
fn waz(&self) -> Option<WAZD<M>>;
fn qr(&self) -> QR<M>;
#[cfg(feature = "O3")]
fn cholesky(&self) -> Matrix;
fn rref(&self) -> Matrix;
fn cholesky(&self) -> M;
fn rref(&self) -> M;
fn det(&self) -> f64;
fn block(&self) -> (Matrix, Matrix, Matrix, Matrix);
fn inv(&self) -> Matrix;
fn pseudo_inv(&self) -> Matrix;
fn solve(&self, b: &Vec<f64>) -> Vec<f64>;
fn solve_mat(&self, m: &Matrix) -> Matrix;
fn block(&self) -> (M, M, M, M);
fn inv(&self) -> M;
fn pseudo_inv(&self) -> M;
fn solve(&self, b: &[f64]) -> Vec<f64>;
fn solve_mat(&self, m: &M) -> M;
fn is_symmetric(&self) -> bool;
}

Expand Down Expand Up @@ -74,73 +75,73 @@ impl SimpleNorm for Matrix {
}
}

impl SimplerLinearAlgebra for Matrix {
fn back_subs(&self, b: &Vec<f64>) -> Vec<f64> {
matrix::LinearAlgebra::back_subs(self, b)
impl SimplerLinearAlgebra<Matrix> for Matrix {
fn back_subs(&self, b: &[f64]) -> Vec<f64> {
LinearAlgebra::back_subs(self, b)
}

fn forward_subs(&self, b: &Vec<f64>) -> Vec<f64> {
matrix::LinearAlgebra::forward_subs(self, b)
fn forward_subs(&self, b: &[f64]) -> Vec<f64> {
LinearAlgebra::forward_subs(self, b)
}

fn lu(&self) -> matrix::PQLU {
matrix::LinearAlgebra::lu(self)
fn lu(&self) -> PQLU<Matrix> {
LinearAlgebra::lu(self)
}

fn waz_diag(&self) -> Option<matrix::WAZD> {
matrix::LinearAlgebra::waz(self, matrix::Form::Diagonal)
fn waz_diag(&self) -> Option<WAZD<Matrix>> {
LinearAlgebra::waz(self, Form::Diagonal)
}

fn waz(&self) -> Option<matrix::WAZD> {
matrix::LinearAlgebra::waz(self, matrix::Form::Identity)
fn waz(&self) -> Option<WAZD<Matrix>> {
LinearAlgebra::waz(self, Form::Identity)
}

fn qr(&self) -> matrix::QR {
matrix::LinearAlgebra::qr(self)
fn qr(&self) -> QR<Matrix> {
LinearAlgebra::qr(self)
}

#[cfg(feature = "O3")]
fn cholesky(&self) -> Matrix {
matrix::LinearAlgebra::cholesky(self, matrix::UPLO::Lower)
LinearAlgebra::cholesky(self, UPLO::Lower)
}

fn rref(&self) -> Matrix {
matrix::LinearAlgebra::rref(self)
LinearAlgebra::rref(self)
}

fn det(&self) -> f64 {
matrix::LinearAlgebra::det(self)
LinearAlgebra::det(self)
}

fn block(&self) -> (Matrix, Matrix, Matrix, Matrix) {
matrix::LinearAlgebra::block(self)
LinearAlgebra::block(self)
}

fn inv(&self) -> Matrix {
matrix::LinearAlgebra::inv(self)
LinearAlgebra::inv(self)
}

fn pseudo_inv(&self) -> Matrix {
matrix::LinearAlgebra::pseudo_inv(self)
LinearAlgebra::pseudo_inv(self)
}

fn solve(&self, b: &Vec<f64>) -> Vec<f64> {
matrix::LinearAlgebra::solve(self, b, matrix::SolveKind::LU)
fn solve(&self, b: &[f64]) -> Vec<f64> {
LinearAlgebra::solve(self, b, SolveKind::LU)
}

fn solve_mat(&self, m: &Matrix) -> Matrix {
matrix::LinearAlgebra::solve_mat(self, m, matrix::SolveKind::LU)
LinearAlgebra::solve_mat(self, m, SolveKind::LU)
}

fn is_symmetric(&self) -> bool {
matrix::LinearAlgebra::is_symmetric(self)
LinearAlgebra::is_symmetric(self)
}
}

/// Simple solve
#[allow(non_snake_case)]
pub fn solve(A: &Matrix, m: &Matrix) -> Matrix {
matrix::solve(A, m, matrix::SolveKind::LU)
crate::traits::matrix::solve(A, m, SolveKind::LU)
}

/// Simple Chebyshev Polynomial (First Kind)
Expand Down
1 change: 1 addition & 0 deletions src/special/lanczos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
use crate::statistics::ops::{double_factorial, factorial, C};
use crate::structure::matrix::Matrix;
use crate::traits::matrix::MatrixTrait;
use crate::traits::pointer::{Oxide, RedoxCommon};
use crate::util::non_macro::zeros;
use crate::util::useful::sgn;
Expand Down
2 changes: 1 addition & 1 deletion src/statistics/stat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ use std::fmt;
use self::QType::*;
//use crate::structure::dataframe::*;
use crate::structure::matrix::*;
use crate::traits::fp::FPVector;
use crate::traits::matrix::{MatrixTrait, LinearAlgebra};
use order_stat::kth_by;

/// Statistics Trait
Expand Down
Loading

0 comments on commit 5ad6170

Please sign in to comment.