#2008·warp

FEM QR routines return NaNs for large float32 matrices

Author: shi-ericCreated Sep 29, 2026Updated Sep 29, 2026
Labelsbug

Bug Description

A symmetric float32 matrix with entries around 1e19 causes householder_qr_decomposition(), symmetric_eigenvalues_qr(), and inverse_qr() to return nonfinite values. The same matrix scaled to 1e18 works. Its condition number is 3, and its expected eigenvalues and inverse fit in float32.

python
import numpy as np
import warp as wp
from warp.fem.linalg import householder_qr_decomposition, inverse_qr, symmetric_eigenvalues_qr


@wp.kernel(enable_backward=False)
def reproduce(scale: float, matrices: wp.array[wp.mat22], eigenvalues: wp.array[wp.vec2]):
    a = scale * wp.mat22(2.0, 1.0, 1.0, 2.0)
    q, r = householder_qr_decomposition(a)
    d, _ = symmetric_eigenvalues_qr(a, 0.0)
    matrices[0] = a
    matrices[1] = q
    matrices[2] = r
    matrices[3] = inverse_qr(a)
    eigenvalues[0] = d


for scale in (1.0e18, 1.0e19):
    matrices = wp.empty(4, dtype=wp.mat22, device="cpu")
    eigenvalues = wp.empty(1, dtype=wp.vec2, device="cpu")
    wp.launch(reproduce, dim=1, inputs=[scale, matrices, eigenvalues], device="cpu")
    a, q, r, inverse = matrices.numpy()
    d = eigenvalues.numpy()[0]
    print(scale, {
        name: bool(np.isfinite(value).all())
        for name, value in (
            ("A", a), ("Q", q), ("R", r),
            ("eigenvalues", d), ("inverse", inverse),
        )
    })
1e+18 {'A': True, 'Q': True, 'R': True, 'eigenvalues': True, 'inverse': True}
1e+19 {'A': True, 'Q': False, 'R': False, 'eigenvalues': False, 'inverse': False}

The 1e19 input is finite, but Q, R, the eigenvalues, and the inverse themselves contain NaNs. The failure also reproduces on CUDA.

The first Householder vector contains (2e19, 1e19). Its squared length is 5e38, above the float32 maximum, although the length itself is representable. _householder_reflection() rescales vectors when their norm is too small but does not handle this overflow.

Expected Behavior

Q and R should be finite and reconstruct the input within float32 precision. The eigenvalues should be approximately 1e19 and 3e19, and inverse_qr() should return a finite inverse.

System Information

  • Warp 1.19.0.dev0, commit 8c0efd486a2d5e939ebee2d0a9536aae5b95327f. The FEM QR implementation matches commit a596470bafe6805c10fb2ce83ba47857253d37dd.
  • Python 3.12.13 on Linux x86_64.
  • Reproduced on CPU and an NVIDIA RTX PRO 6000 Blackwell CUDA device with CUDA Toolkit 13.4 and Driver 13.2.

Related: #1985 addressed underflow for small inputs.