-
Notifications
You must be signed in to change notification settings - Fork 0
refactor(invariants): simplify finite proof wrappers #134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,20 +22,11 @@ pub(crate) struct FiniteVector<const D: usize> { | |
| } | ||
|
|
||
| impl<const D: usize> FiniteVector<D> { | ||
| /// Construct a finite vector without checking the invariant. | ||
| /// | ||
| /// This is crate-internal so raw storage still goes through | ||
| /// [`Vector::try_new`], which preserves diagnostics for rejected entries. | ||
| #[inline] | ||
| pub(crate) const fn new_unchecked(vector: Vector<D>) -> Self { | ||
| Self { vector } | ||
| } | ||
|
|
||
| /// Wrap an already-finite vector for algorithms that carry the invariant | ||
| /// explicitly. | ||
| #[inline] | ||
| pub const fn new(vector: Vector<D>) -> Self { | ||
| Self::new_unchecked(vector) | ||
| Self { vector } | ||
|
Comment on lines
28
to
+29
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This now just rewraps Suggested direction- pub const fn new(vector: Vector<D>) -> Self {
- Self { vector }
+ pub const fn new(vector: Vector<D>) -> Result<Self, LaError> {
+ let mut i = 0;
+ while i < D {
+ if !vector.data[i].is_finite() {
+ return Err(LaError::non_finite_at(i));
+ }
+ i += 1;
+ }
+ Ok(Self { vector })
}If you still need a bypass for locally-proven outputs, keep a clearly named private As per coding guidelines, "Non-finite values (NaN, ±∞) always surface as 🤖 Prompt for AI Agents |
||
| } | ||
|
|
||
| /// Validate raw vector storage and construct a finite vector. | ||
|
|
@@ -45,15 +36,15 @@ impl<const D: usize> FiniteVector<D> { | |
| #[inline] | ||
| pub const fn from_array(data: [f64; D]) -> Result<Self, LaError> { | ||
| match Vector::try_new(data) { | ||
| Ok(vector) => Ok(Self::new_unchecked(vector)), | ||
| Ok(vector) => Ok(Self::new(vector)), | ||
| Err(err) => Err(err), | ||
| } | ||
| } | ||
|
|
||
| /// All-zeros finite vector. | ||
| #[inline] | ||
| pub const fn zero() -> Self { | ||
| Self::new_unchecked(Vector::zero()) | ||
| Self::new(Vector::zero()) | ||
| } | ||
|
|
||
| /// Consume the wrapper and return the underlying raw vector. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FiniteMatrix::newno longer distinguishes checked from unchecked construction.Matrix::from_rows_unchecked(...)still exists, butFiniteMatrix::new(...)now just wraps the raw matrix. So the proof wrapper can still be built from unchecked storage, and the public algorithm helpers below (inf_norm,lu,ldlt,det*) are not actually entering through a validated boundary.Suggested direction
If some internal paths genuinely have a local finiteness proof, keep an explicitly named private unchecked constructor for those sites rather than making
new(...)silently unchecked.As per coding guidelines, "Non-finite values (NaN, ±∞) always surface as
LaError::NonFinite { row, col }with source-location metadata. No silent NaN propagation, nounwrap_or(f64::NAN)."🤖 Prompt for AI Agents