Skip to content

MiniTensor: modernize the general log() and exp() algorithms - #15515

Merged
lxmota merged 1 commit into
trilinos:developfrom
lxmota:minitensor-log-exp-algorithms
Jul 29, 2026
Merged

MiniTensor: modernize the general log() and exp() algorithms#15515
lxmota merged 1 commit into
trilinos:developfrom
lxmota:minitensor-log-exp-algorithms

Conversation

@lxmota

@lxmota lxmota commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

@trilinos/minitensor

Motivation

The general log() used a transformation-free inverse scaling and squaring whose Denman–Villiers square-root iterations and determinant-based scaling are both expensive and fragile for ill-conditioned input (see #15513), and exp() used the 2005-era parameter selection with rounded threshold constants. This PR brings both up to the current published algorithms, specialized to the small dimensions MiniTensor serves.

Changes

log(), dimensions <= 3 (larger dimensions keep the previous path):

  • Within the Padé trust region (norm_1(A - I) <= 0.72): direct Gauss–Legendre partial-fraction Padé evaluation on the exactly computed A − I. This preserves the relative accuracy of small logarithms, which any similarity-based method loses to the ~eps·norm(A) rounding of the transformation itself.
  • Beyond it: Schur-based inverse scaling and squaring in the spirit of Al-Mohy & Higham, SIAM J. Sci. Comput. 34(4), 2012 — real Schur decomposition (Givens Hessenberg reduction, Francis double-shift QR with the classical difference-form shift vector and standardized 2×2 blocks), exact quasi-triangular square roots instead of Denman–Beavers iterations, Padé on the quasi-triangular factor, and exact recomputation of the diagonal blocks of the logarithm from the eigenvalues. Eigenvalues on the closed negative real axis now produce a clean error instead of non-convergence, and the determinant-scaling failure mode of MiniTensor: fix log() failure on ill-conditioned SPD tensors #15513 is structurally absent from this path.

exp(): parameter selection of Al-Mohy & Higham, SIAM J. Matrix Anal. Appl. 31(3), 2009. Their θ thresholds make the norm-based order choice provably exact short-circuit evaluation of the full algorithm whenever norm_1(A) <= θ13 = 4.25; the norm(A^p)^(1/p) overscaling analysis and the rounding-correction term (with a conservative early exit and binary powering) run only above that threshold. Also fixes a decimal-point typo (9,4e-0) in the scaling_squaring_theta table that silently shifted entries above order 16.

Related Issues

Stacked on #15513 and includes its commit; this PR will be rebased to a single commit once #15513 merges. Follows #15514.

Testing

  • Full MiniTensor gtest suite passes (36 tests), including three new ones: a nonsymmetric logarithm with a complex-conjugate eigenvalue pair recovered through log(exp(L)), the analytic logarithm of a scaled 2×2 rotation, and agreement of exp() with the Taylor series on a nonsymmetric argument.
  • Benchmarked on 500-sample suites per parameter point (35 parameter points for the log, 25 for the exp) against an independent 80-bit eigendecomposition reference:
    • log(): identical accuracy and speed near the identity; 1.8–4.3× more accurate and 1.4–4.7× faster away from it (condition numbers 10 to 1e14); zero failures across 17,500 samples.
    • exp(): median cost and accuracy unchanged; up to 1.8× more accurate at strong stretches; the extreme-norm cases (norm > 4.25) pay up to ~1.9× for the overscaling analysis.

log(), dimensions 3 and below: hybrid of two methods, chosen by the
distance from the identity.

- Within the Pade trust region (norm_1(A - I) <= 0.72) the logarithm is
  a direct Gauss-Legendre partial-fraction Pade evaluation on A - I,
  which is computed exactly. This preserves the relative accuracy of
  small logarithms, which any similarity-based method loses to the
  ~eps*norm(A) rounding of the transformation itself.
- Away from the identity, a Schur-based inverse scaling and squaring in
  the spirit of Al-Mohy and Higham, Improved Inverse Scaling and
  Squaring Algorithms for the Matrix Logarithm, SIAM J. Sci. Comput.
  34(4), 2012: real Schur decomposition (Givens Hessenberg reduction
  plus Francis double-shift QR with standardized 2x2 blocks and the
  classical difference form of the shift vector), exact quasi-triangular
  square roots in place of Denman-Beavers iterations, Pade evaluation on
  the quasi-triangular factor, and exact recomputation of the diagonal
  blocks of the logarithm from the eigenvalues. Inputs with eigenvalues
  on the closed negative real axis fail with a clean error instead of
  failing to converge.

Larger dimensions keep the previous transformation-free path.

Measured on 500-sample suites per parameter point against an 80-bit
eigendecomposition reference: identical accuracy and speed near the
identity, 1.8-4.3x more accurate and 1.4-4.7x faster elsewhere
(condition numbers 10 to 1e14), no failures.

exp(): parameter selection of Al-Mohy and Higham, A New Scaling and
Squaring Algorithm for the Matrix Exponential, SIAM J. Matrix Anal.
Appl. 31(3), 2009. Their theta thresholds make the norm-based order
choice exact short-circuit evaluation of the full algorithm whenever
norm_1(A) <= theta_13 = 4.25, so the norm(A^p)^(1/p) overscaling
analysis and the rounding correction term run only above that
threshold, where they prevent overscaling of nonnormal arguments. The
correction term exits early through a conservative bound and computes
its matrix powers by binary powering. Median cost is unchanged; the
extreme-norm cases pay up to ~1.9x for up to 1.8x accuracy gains at
strong stretches. Also fixes a decimal-point typo (9,4e-0) in the
scaling_squaring_theta table that silently shifted the entries above
order 16.

New tests: nonsymmetric logarithm with a complex-conjugate eigenvalue
pair recovered through log(exp(L)), the analytic logarithm of a scaled
2x2 rotation, and agreement of exp() with the Taylor series on a
nonsymmetric argument.

Signed-off-by: Alejandro Mota <amota@sandia.gov>
@github-actions

Copy link
Copy Markdown

CDash for AT2 results

Reproducing CI builds locally

CI builds can be reproduced locally in a container.

Requirements: Python 3.9+, Podman, CMake

Steps:

  • Check out the branch of the PR locally.
  • Run commonTools/pr_reproducer/reproducer.sh.

@lxmota
lxmota requested review from cgcgcg and ikalash July 29, 2026 02:58
@lxmota lxmota self-assigned this Jul 29, 2026

@ikalash ikalash left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

@lxmota
lxmota merged commit 139ac30 into trilinos:develop Jul 29, 2026
19 of 20 checks passed
@lxmota
lxmota deleted the minitensor-log-exp-algorithms branch July 29, 2026 04:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants