1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//! Error and preflight-block enums for survival marginal-slope fitting,
//! with their `Display`/`Error`/`From` conversions. Self-contained: no
//! dependency on the fitting machinery.
#[derive(Debug, Clone)]
pub enum SurvivalMarginalSlopeError {
/// Spec, data, or runtime configuration failed input validation
/// (finite/non-negative weights, derivative_guard > 0, supported
/// base_link, frailty constraints, missing block state, etc.).
InvalidInput { reason: String },
/// Lengths, row/column counts, basis widths, or coefficient block
/// sizes do not agree (covariance dim vs z, design rows vs n,
/// basis/beta length mismatch, post-update beta length, time
/// constraints A vs b, hessian_matvec dim mismatch, ...).
IncompatibleDimensions { reason: String },
/// A row's transformed time derivative or structural slack fell
/// below `derivative_guard` (`qd1 < guard`), violating the
/// monotonicity contract.
MonotonicityViolation { reason: String },
/// A numerical step produced a non-finite, non-positive, or
/// internally inconsistent quantity that downstream code cannot
/// consume (e.g. non-positive `D`, non-positive `chi1`, calibration
/// derivative disagrees with the direct evaluation, transformed
/// derivative not strictly positive).
NumericalFailure { reason: String },
/// An integration / outer-optimization step failed to converge to
/// the requested tolerance (intercept residual, REML outer loop).
IntegrationFailed { reason: String },
/// The requested combination of options is not implemented (non-
/// probit base link, flexible row calculus with K > 1, spatial psi
/// for unsupported block roles, ...).
UnsupportedConfiguration { reason: String },
}
/// Block tag used by the joint training-row preflight diagnostic.
/// Names a single block in the joint design layout
/// `[time | marginal | logslope | score_warp? | link_dev?]`.
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum JointPreflightBlock {
Time,
Marginal,
Logslope,
ScoreWarp,
LinkDev,
}
impl std::fmt::Display for JointPreflightBlock {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let name = match self {
JointPreflightBlock::Time => "time",
JointPreflightBlock::Marginal => "marginal",
JointPreflightBlock::Logslope => "logslope",
JointPreflightBlock::ScoreWarp => "score_warp",
JointPreflightBlock::LinkDev => "link_dev",
};
f.write_str(name)
}
}
crate::impl_reason_error_boilerplate! {
SurvivalMarginalSlopeError {
InvalidInput,
IncompatibleDimensions,
MonotonicityViolation,
NumericalFailure,
IntegrationFailed,
UnsupportedConfiguration,
}
}
impl From<String> for SurvivalMarginalSlopeError {
/// Inbound conversion from helpers in this module (and adjacent
/// families) that still surface `Result<_, String>`. The text is
/// preserved verbatim; `InvalidInput` is the catch-all category for
/// strings produced outside this module.
fn from(reason: String) -> SurvivalMarginalSlopeError {
SurvivalMarginalSlopeError::InvalidInput { reason }
}
}