MiniTensor: fix log() failure on ill-conditioned SPD tensors - #15513
Merged
lxmota merged 1 commit intoJul 29, 2026
Conversation
Reproducing CI builds locallyCI builds can be reproduced locally in a container. Requirements: Python 3.9+, Podman, CMake Steps:
|
ikalash
previously approved these changes
Jul 28, 2026
For SPD tensors with condition number above ~1e10, the fully expanded 3x3 determinant used by the Denman-Beavers scaling in sqrt_dbp can cancel catastrophically and return exactly zero (terms of order 1e15 summing to a true determinant of order 1). The scaling factor g = 1/det^(1/6) then becomes Inf, the iterates fill with Inf/NaN, and the pivot search in solve_full_pivot finds no pivot because NaN comparisons are false. With asserts enabled log() aborts; in release builds (-DNDEBUG) the subsequent access S(pivot_row, j) with pivot_row == dimension writes out of bounds. Two changes: - sqrt_dbp: skip the determinant scaling when the computed determinant is zero or the scaling factor is non-finite. The scaling only accelerates convergence, so skipping it affects iteration count, not correctness. In a 500-sample sweep per condition number this restores a 100% success rate at conditions 1e12 and 1e14 (from 78% and 61%) with accuracy unchanged on the samples that previously succeeded. - solve_full_pivot: replace the pivot-search asserts with an explicit error exit so that a singular or non-finite matrix produces a clean failure instead of an out-of-bounds write in release builds. Adds a regression test with an SPD tensor of unit determinant and condition number 1e12 whose expanded determinant cancels to exactly zero in double precision. Signed-off-by: Alejandro Mota <amota@sandia.gov>
lxmota
force-pushed
the
minitensor-log-iss-det-cancellation
branch
from
July 29, 2026 01:21
02fb402 to
66b96c5
Compare
cgcgcg
approved these changes
Jul 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
@trilinos/minitensor
Motivation
For SPD tensors with condition number above ~1e10,
minitensor::log()(inverse scaling and squaring) can abort in debug builds and write out of bounds in release builds. Root cause chain, verified with a debugger on a captured input:sqrt_dbpcancels catastrophically: for the tensor in the added regression test (eigenvalues 1e6, 1, 1e-6; unit determinant) the six terms are of order 1e15 and the computed determinant is exactly 0.0.g = 1/det^(1/6)becomes Inf and floods the iteratesXandMwith Inf.inverse_full_pivot→solve_full_pivot: elimination produces Inf/Inf = NaN, and the next pivot search finds no pivot because NaN comparisons are false.pivot_row < dimensionassert; with-DNDEBUGthe subsequentS(pivot_row, j) /= twithpivot_row == dimensionis an out-of-bounds write.In a 500-sample sweep per condition number,
log()aborted on 22% of random SPD tensors at condition 1e12 and 39% at 1e14.Changes
sqrt_dbp: skip the determinant scaling when the computed determinant is zero or the scaling factor is non-finite. The scaling only accelerates convergence, so skipping it affects iteration count, not correctness.solve_full_pivot: replace the pivot-search asserts withMT_ERROR_EXITso a singular or non-finite matrix produces a clean failure instead of memory corruption in release builds.MiniTensor.LogIllConditionedwith the captured tensor whose expanded determinant cancels to exactly zero.Related Issues
None filed; found during an accuracy/performance study of
log()vslog_sym()on SPD tensors.Testing
test_01.ccgtest suite (33 tests including the new one) passes on Linux x86-64, GCC 16, serial Kokkos.inverse_fast23was also evaluated and rejected: it divides by the same cancellation-prone determinant, and NaN passes itsassert(det != 0), turning the failure into an infinite loop.