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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
//! Vector-tier primitives for box-constrained NLLS: the Coleman-Li
//! affine scaling vectors and friends.
//!
//! Three element-wise operations the [`Trf`](crate::solver::Trf) solver
//! needs that aren't generic enough to live in `math.rs`:
//!
//! - **Coleman-Li affine scaling** — `d²` and the `C` diagonal from
//! Branch-Coleman-Li 1999 eqs (i)–(iv) (`source.marker.md:54-59` in
//! `references/branch-coleman-li-1999/`). Defines the diagonal
//! trust-region scaling matrix `D = diag(|v|^{-1/2})` and the
//! curvature correction `C = D·diag(g)·J^v·D` that's also diagonal.
//! - **Strict-interior step-back** — largest `τ` keeping `x + τ·s` in
//! the box, used to cut the unconstrained Newton step back to the
//! feasible region. The TRF caller multiplies by `θ < 1` to keep
//! iterates in the *open* box (D is undefined where `v_i = 0`).
//! - **Scaled gradient ∞-norm** — the `‖D·g‖_∞` first-order optimality
//! measure, computed from `g` and `d²` without materializing `D·g`.
//!
//! Per-backend implementations in `vec.rs`, `nalgebra_backend.rs`,
//! `ndarray_backend.rs`, `faer_backend.rs`. All four backends are
//! supported — the operations are pure element-wise, no LA dependency,
//! so the vector-tier coverage is honest across the corpus.
/// Box-constrained NLLS vector primitives. Implemented for every
/// vector backend basin ships (`Vec<f64>`, `nalgebra::DVector<f64>`,
/// `ndarray::Array1<f64>`, `faer::Col<f64>`).
///
/// Used exclusively by the [`Trf`](crate::solver::Trf) solver today.
/// The trait groups three otherwise-unrelated element-wise operations
/// because they share their caller and have no other users — splitting
/// would just inflate the solver's `where` clause.
/// Helper for the case dispatch in `compute_cl_scaling` — writes
/// `(d_sq_i, c_diag_i)` for one component given the local `(x, g, l, u)`.
/// Per-backend impls call this on each index to share the arithmetic;
/// generic over `f64` only because every backend stores `f64` scalars.
pub
/// Helper for `project_strictly_inside` — per-component clamp into the
/// *open* box. Returns the projected value.
pub
/// Helper for `max_feasible_step` — per-component limit, returning
/// `f64::INFINITY` when `step_i = 0` or the relevant bound is infinite.
pub