Skip to content

Commit

Permalink
Convertion between identical FitStats
Browse files Browse the repository at this point in the history
  • Loading branch information
Dzuchun committed Nov 25, 2024
1 parent 151f380 commit 658b707
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions nacfahi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,50 @@ where
pub covariance_matrix: GenericMatrix<Model::Scalar, Model::ParamCount, Model::ParamCount>,
}

impl<Model> FitStat<Model>
where
Model: FitModelErrors,
Model::Scalar: RealField,
{
/// Converts [`FitStat`] types, if there's no difference between them internally.
///
/// For example, this works for `FitStat<&mut Model> -> FitStat<Mode>` convertion:
///
/// ```rust
/// # use nacfahi::{models::basic::Constant, fit_stat, FitStat};
/// let x = [1.0, 3.0, -4.0];
/// let y = [-2.0, 5.2, -5.3];
///
/// let mut model = Constant { c: 0.0 };
///
/// let fit_stat: FitStat<&mut Constant<f64>> = fit_stat!(&mut model, x, y);
/// let fit_stat: FitStat<Constant<f64>> = fit_stat.into();
/// ```
#[inline]
pub fn into<OtherModel>(self) -> FitStat<OtherModel>
where
OtherModel: FitModelErrors<
Scalar = Model::Scalar,
ParamCount = Model::ParamCount,
OwnedModel = Model::OwnedModel,
>,
{
let FitStat {
report,
reduced_chi2,
errors,
covariance_matrix,
} = self;

FitStat {
report,
reduced_chi2,
errors,
covariance_matrix,
}
}
}

#[macro_export]
#[cfg(doc)]
#[doc = include_str!("../doc/fit_stat_macro.md")]
Expand Down

0 comments on commit 658b707

Please sign in to comment.