use crate::{
model::SeparableNonlinearModel,
problem::{RhsType, SeparableProblem},
};
#[cfg(feature = "__lapack")]
use colpiv_qr::QrDecomp;
use levenberg_marquardt::LeastSquaresProblem;
use nalgebra::{ComplexField, Const, DMatrix, Dyn, Owned, Scalar};
mod svd;
#[cfg(feature = "__lapack")]
use nalgebra::RealField;
#[cfg(feature = "__lapack")]
#[cfg_attr(
docsrs,
doc(cfg(any(
feature = "lapack-netlib",
feature = "lapack-mkl",
feature = "lapack-mkl-static-seq",
feature = "lapack-mkl-static-par",
feature = "lapack-mkl-dynamic-seq",
feature = "lapack-mkl-dynamic-par",
feature = "lapack-openblas",
feature = "lapack-accelerate",
feature = "lapack-custom"
)))
)]
pub mod colpiv_qr;
#[cfg(feature = "__lapack")]
#[cfg_attr(
docsrs,
doc(cfg(any(
feature = "lapack-netlib",
feature = "lapack-mkl",
feature = "lapack-mkl-static-seq",
feature = "lapack-mkl-static-par",
feature = "lapack-mkl-dynamic-seq",
feature = "lapack-mkl-dynamic-par",
feature = "lapack-openblas",
feature = "lapack-accelerate",
feature = "lapack-custom"
)))
)]
pub use colpiv_qr::GeneralQrLinearSolver;
#[cfg(feature = "__lapack")]
use nalgebra_lapack::qr::QrReal;
#[cfg(feature = "__lapack")]
use num_traits::Float;
pub use svd::SvdLinearSolver;
#[cfg(feature = "__lapack")]
#[cfg_attr(
docsrs,
doc(cfg(any(
feature = "lapack-netlib",
feature = "lapack-mkl",
feature = "lapack-mkl-static-seq",
feature = "lapack-mkl-static-par",
feature = "lapack-mkl-dynamic-seq",
feature = "lapack-mkl-dynamic-par",
feature = "lapack-openblas",
feature = "lapack-accelerate",
feature = "lapack-custom"
)))
)]
#[allow(type_alias_bounds)]
pub type LevMarProblemCpQr<Model: SeparableNonlinearModel, Rhs> = LevMarProblem<
Model,
Rhs,
GeneralQrLinearSolver<
Model::ScalarType,
nalgebra_lapack::ColPivQR<Model::ScalarType, Dyn, Dyn>,
>,
>;
#[cfg(feature = "__lapack")]
#[cfg_attr(
docsrs,
doc(cfg(any(
feature = "lapack-netlib",
feature = "lapack-mkl",
feature = "lapack-mkl-static-seq",
feature = "lapack-mkl-static-par",
feature = "lapack-mkl-dynamic-seq",
feature = "lapack-mkl-dynamic-par",
feature = "lapack-openblas",
feature = "lapack-accelerate",
feature = "lapack-custom"
)))
)]
#[allow(type_alias_bounds)]
pub type LevMarProblemQr<Model: SeparableNonlinearModel, Rhs> = LevMarProblem<
Model,
Rhs,
GeneralQrLinearSolver<Model::ScalarType, nalgebra_lapack::QR<Model::ScalarType, Dyn, Dyn>>,
>;
#[allow(type_alias_bounds)]
pub type LevMarProblemSvd<Model: SeparableNonlinearModel, Rhs> =
LevMarProblem<Model, Rhs, SvdLinearSolver<Model::ScalarType>>;
#[derive(Debug)]
pub struct LevMarProblem<Model, Rhs, Solver>
where
Model::ScalarType: Scalar + ComplexField + Copy,
Solver: LinearSolver<ScalarType = Model::ScalarType>,
Rhs: RhsType,
Model: SeparableNonlinearModel,
{
pub(crate) separable_problem: SeparableProblem<Model, Rhs>,
pub(crate) cached: Option<Solver>,
}
impl<Model, Rhs, Solver> From<SeparableProblem<Model, Rhs>> for LevMarProblem<Model, Rhs, Solver>
where
Model::ScalarType: Scalar + ComplexField + Copy,
Solver: LinearSolver<ScalarType = Model::ScalarType>,
Rhs: RhsType,
Model: SeparableNonlinearModel,
Self: LeastSquaresProblem<
Model::ScalarType,
Dyn,
Dyn,
ParameterStorage = Owned<Model::ScalarType, Dyn, Const<1>>,
>,
{
fn from(problem: SeparableProblem<Model, Rhs>) -> Self {
let mut this = Self {
separable_problem: problem,
cached: None,
};
this.set_params(&this.separable_problem.model.params());
this
}
}
pub trait LinearSolver: std::fmt::Debug + sealed::Sealed {
type ScalarType: Scalar;
fn linear_coefficients_matrix(self) -> DMatrix<Self::ScalarType>;
}
#[cfg(feature = "__lapack")]
impl<ScalarType: RealField, Qrd> sealed::Sealed for GeneralQrLinearSolver<ScalarType, Qrd>
where
ScalarType: Scalar + ComplexField + QrReal + RealField + Float,
Qrd: QrDecomp<ScalarType>,
{
}
impl<ScalarType: ComplexField> sealed::Sealed for SvdLinearSolver<ScalarType> {}
pub mod sealed {
pub trait Sealed {}
}