Skip to content

feat: const-ify Lu::det, Ldlt::det, inf_norm, det_errbound, and solve methods #86

@acgetchell

Description

@acgetchell

Dependencies

Summary

Several public methods that are pure computation over [f64; D] / [[f64; D]; D] arrays could be const fn today but aren't. This would enable compile-time evaluation and is consistent with the existing const fn pattern established by det_direct, Vector::dot, etc.

Depends on: #67 (MSRV bump to 1.95, which stabilizes additional const-compatible float intrinsics) and #85 (fix inf_norm before const-ifying it)

Candidates

Easy (no trait methods, just loops and float ops)

  • Lu::det — loop over diagonal with multiply-accumulate. Straightforward.
  • Ldlt::det — same pattern as Lu::det.
  • Matrix::inf_norm — needs manual loop replacing .iter().map().sum() (iterators aren't const-stable). Also depends on f64::abs() being const — check availability at MSRV 1.95.
  • Matrix::det_errbound — uses f64::abs() and mul_add. Same abs() dependency.

Moderate (manual loops replacing iterator chains)

  • Lu::solve_vec — the forward/back substitution loops are already manual; the iterator-based inner loops (enumerate().take(i), enumerate().skip(i+1)) would need conversion to while loops. The is_finite() check needs to be const-compatible.
  • Ldlt::solve_vec — same pattern as Lu::solve_vec.

Blocked (needs generic_const_exprs or other unstable features)

  • gauss_solve and exact methods — use BigInt/BigRational heap types, not const-eligible
  • Augmented matrix types ([T; D+1]) — needs generic_const_exprs (v0.5.0 territory)

Approach

  1. After chore: bump MSRV to Rust 1.95 and adopt new stable features #67 lands, audit which f64 methods (abs, is_finite, is_nan) are const-stable at MSRV 1.95
  2. Convert eligible methods, replacing iterator chains with while loops where needed
  3. Add const evaluation tests (similar to the existing det_direct_is_const_evaluable_* tests)

Benefits

  • Compile-time evaluation of determinants, norms, and solves for known inputs
  • Consistent API: if det_direct and Vector::dot are const, their peers should be too
  • Foundation for v0.5.0's deeper const-generics work

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestrustPull requests that update rust code

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions