use eigenvalues::{self, Eigen, SymEigen};
use solve_linear::{SolveLinear, SymmetricSolveLinear};
use super::error::*;
use super::scalar::LinxalScalar;
use impl_prelude::*;
use svd::{SVD, SVDSolution, SVDComputeVectors};
pub trait LinxalMatrixInto<F: LinxalScalar> {
fn eigenvalues_into(self)
-> Result<Array<F::Complex, Ix1>, EigenError>;
fn eigenvalues_vectors_into(self,
compute_left: bool,
compute_right: bool)
-> Result<eigenvalues::types::Solution<F, F::Complex>, EigenError>;
fn symmetric_eigenvalues_into(self,
uplo: Symmetric)
-> Result<Array<F::RealPart, Ix1>, EigenError>;
fn solve_linear_into<D1: DataMut<Elem = F> + DataOwned<Elem = F>>
(self, b: ArrayBase<D1, Ix1>)
-> Result<ArrayBase<D1, Ix1>, SolveError>;
fn solve_symmetric_linear_into<D1: DataMut<Elem = F> + DataOwned<Elem = F>>
(self, b: ArrayBase<D1, Ix1>, uplo: Symmetric)
-> Result<ArrayBase<D1, Ix1>, SolveError>;
fn solve_multi_linear_into<D1: DataMut<Elem = F> + DataOwned<Elem = F>>
(self, b: ArrayBase<D1, Ix2>)
-> Result<ArrayBase<D1, Ix2>, SolveError>;
fn solve_symmetric_multi_linear_into<D1: DataMut<Elem = F> + DataOwned<Elem = F>>
(self, b: ArrayBase<D1, Ix2>, uplo: Symmetric)
-> Result<ArrayBase<D1, Ix2>, SolveError>;
fn svd_full_into(self) -> Result<SVDSolution<F>, SVDError>;
fn svd_econ_into(self) -> Result<SVDSolution<F>, SVDError>;
fn singular_values_into(self) -> Result<Array<F::RealPart, Ix1>, SVDError>;
fn conj_into(self) -> Self;
}
impl<F: LinxalScalar, D: DataMut<Elem = F> + DataOwned<Elem = F>> LinxalMatrixInto<F> for ArrayBase<D, Ix2> {
fn eigenvalues_into(self) -> Result<Array<F::Complex, Ix1>, EigenError> {
Eigen::compute_into(self, false, false).map(|sol| sol.values)
}
fn eigenvalues_vectors_into(self,
compute_left: bool,
compute_right: bool)
-> Result<eigenvalues::types::Solution<F, F::Complex>, EigenError> {
Eigen::compute_into(self, compute_left, compute_right)
}
fn symmetric_eigenvalues_into(self,
uplo: Symmetric) -> Result<Array<F::RealPart, Ix1>, EigenError> {
SymEigen::compute_into(self, uplo)
}
fn solve_linear_into<D1: DataMut<Elem = F> + DataOwned<Elem = F>>
(self, b: ArrayBase<D1, Ix1>)
-> Result<ArrayBase<D1, Ix1>, SolveError> {
SolveLinear::compute_into(self, b)
}
fn solve_symmetric_linear_into<D1: DataMut<Elem = F> + DataOwned<Elem = F>>
(self, b: ArrayBase<D1, Ix1>, uplo: Symmetric)
-> Result<ArrayBase<D1, Ix1>, SolveError> {
SymmetricSolveLinear::compute_into(self, uplo, b)
}
fn solve_multi_linear_into<D1: DataMut<Elem = F> + DataOwned<Elem = F>>
(self, b: ArrayBase<D1, Ix2>)
-> Result<ArrayBase<D1, Ix2>, SolveError> {
SolveLinear::compute_multi_into(self, b)
}
fn solve_symmetric_multi_linear_into<D1: DataMut<Elem = F> + DataOwned<Elem = F>>
(self, b: ArrayBase<D1, Ix2>, uplo: Symmetric)
-> Result<ArrayBase<D1, Ix2>, SolveError> {
SymmetricSolveLinear::compute_multi_into(self, uplo, b)
}
fn svd_full_into(self) -> Result<SVDSolution<F>, SVDError> {
SVD::compute_into(self, SVDComputeVectors::Full)
}
fn svd_econ_into(self) -> Result<SVDSolution<F>, SVDError> {
SVD::compute_into(self, SVDComputeVectors::Economic)
}
fn singular_values_into(self) -> Result<Array<F::RealPart, Ix1>, SVDError> {
SVD::compute_into(self, SVDComputeVectors::None).map(|x| x.values)
}
fn conj_into(self) -> Self {
self.mapv_into(|x| x.cj())
}
}