use crate::prelude::*;
use crate::util::Weights;
use nalgebra::Dyn;
use nalgebra::{ComplexField, DMatrix, MatrixView, Scalar, VectorView};
mod builder;
pub use builder::SeparableProblemBuilder;
pub use builder::SeparableProblemBuilderError;
pub trait RhsType: std::fmt::Debug {}
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct SingleRhs;
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct MultiRhs;
impl RhsType for MultiRhs {}
impl RhsType for SingleRhs {}
#[derive(Clone)]
#[allow(non_snake_case)]
pub struct SeparableProblem<Model, Rhs: RhsType>
where
Model: SeparableNonlinearModel,
Model::ScalarType: Scalar + ComplexField + Copy,
{
pub(crate) Y_w: DMatrix<Model::ScalarType>,
pub(crate) model: Model,
pub(crate) weights: Weights<Model::ScalarType, Dyn>,
phantom: std::marker::PhantomData<Rhs>,
}
impl<Model, Rhs: RhsType> std::fmt::Debug for SeparableProblem<Model, Rhs>
where
Model: SeparableNonlinearModel,
Model::ScalarType: Scalar + ComplexField + Copy,
{
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("SeparableProblem")
.field("y_w", &self.Y_w)
.field("model", &"/* omitted */")
.field("weights", &self.weights)
.finish()
}
}
impl<Model> SeparableProblem<Model, MultiRhs>
where
Model: SeparableNonlinearModel,
Model::ScalarType: Scalar + ComplexField + Copy,
{
pub fn weighted_data(&self) -> MatrixView<'_, Model::ScalarType, Dyn, Dyn> {
self.Y_w.as_view()
}
}
impl<Model> SeparableProblem<Model, SingleRhs>
where
Model: SeparableNonlinearModel,
Model::ScalarType: Scalar + ComplexField + Copy,
{
pub fn weighted_data(&self) -> VectorView<'_, Model::ScalarType, Dyn> {
debug_assert_eq!(
self.Y_w.ncols(),
1,
"data matrix must have exactly one column for single right hand side. This indicates a programming error in the library."
);
self.Y_w.as_view()
}
}
impl<Model, Rhs: RhsType> SeparableProblem<Model, Rhs>
where
Model: SeparableNonlinearModel,
Model::ScalarType: Scalar + ComplexField + Copy,
{
pub fn model(&self) -> &Model {
&self.model
}
pub fn weights(&self) -> &Weights<Model::ScalarType, Dyn> {
&self.weights
}
}