Commit 5ddc8b1
Fix underdetermined SVD in Rust OLS (n < k case)
For underdetermined systems (n < k), thin SVD returns:
- U: (n, n)
- S: (n,) - only n singular values
- V: (k, n) - only n right singular vectors
The bug was creating s_inv_uty with size k instead of s.len()=min(n,k),
causing a dimension mismatch in the dot product vt.t().dot(&s_inv_uty).
Fix: Use s.len() for s_inv_uty array size, which correctly handles both
overdetermined (n >= k) and underdetermined (n < k) cases.
Addresses P1 bug identified in PR #115 code review.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>1 parent f771663 commit 5ddc8b1
1 file changed
Lines changed: 31 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
119 | 119 | | |
120 | 120 | | |
121 | 121 | | |
122 | | - | |
| 122 | + | |
| 123 | + | |
123 | 124 | | |
124 | | - | |
| 125 | + | |
125 | 126 | | |
126 | 127 | | |
127 | 128 | | |
| |||
360 | 361 | | |
361 | 362 | | |
362 | 363 | | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
363 | 392 | | |
0 commit comments