Audit finding
- ID:
AUD-024
- Status: Verified defect
- Severity: High
- Confidence: High
- Audited revision:
2f479320d805a1f9f35ebe4afaaeeded48913a94
Problem
ConditionNumber() applies an absolute 1e-12 zero-row/norm threshold. This makes classification depend on matrix units rather than conditioning. It also screens only near-zero rows before calling assert-based Gaussian elimination.
Source:
|
{ |
|
namespace detail |
|
{ |
|
template<typename T, std::size_t N> |
|
bool HasZeroRow(const math::SquareMatrix<T, N>& a) |
|
{ |
|
for (std::size_t i = 0; i < N; ++i) |
|
{ |
|
bool allZero = true; |
|
for (std::size_t j = 0; j < N; ++j) |
|
{ |
|
if (math::Abs(a.at(i, j)) > static_cast<T>(1e-12)) |
|
{ |
|
allZero = false; |
|
break; |
|
} |
|
} |
|
if (allZero) |
|
return true; |
|
} |
|
return false; |
|
} |
|
} |
|
|
|
template<typename T, std::size_t N> |
|
[[nodiscard]] OPTIMIZE_FOR_SPEED std::optional<T> ConditionNumber(const math::SquareMatrix<T, N>& a) |
|
{ |
|
static_assert(std::is_floating_point_v<T>, "ConditionNumber supports floating-point types"); |
|
if (detail::HasZeroRow(a)) |
|
return std::nullopt; |
|
T normA = math::OneNorm(a); |
|
if (normA < static_cast<T>(1e-12)) |
|
return std::nullopt; |
|
auto invA = SolveSystem(a, math::SquareMatrix<T, N>::Identity()); |
|
return normA * math::OneNorm(invA); |
|
} |
|
} |
Reproduction
diag(5e-13, 5e-13) is invertible with condition number one, but returns nullopt. A dependent-row matrix with no near-zero row passes the screen and reaches a zero pivot.
Acceptance criteria
Audit finding
AUD-0242f479320d805a1f9f35ebe4afaaeeded48913a94Problem
ConditionNumber()applies an absolute1e-12zero-row/norm threshold. This makes classification depend on matrix units rather than conditioning. It also screens only near-zero rows before calling assert-based Gaussian elimination.Source:
numerical-toolbox-cpp/numerical/solvers/ConditionNumber.hpp
Lines 15 to 51 in 2f47932
Reproduction
diag(5e-13, 5e-13)is invertible with condition number one, but returnsnullopt. A dependent-row matrix with no near-zero row passes the screen and reaches a zero pivot.Acceptance criteria