Skip to content

Fix eigen decomposition failing to compile for autodiff of complex matrices - #3484

Closed
jachymb wants to merge 1 commit into
stan-dev:developfrom
jachymb:bugfix/eigen-sym-complex-nested-fwd
Closed

jachymb wants to merge 1 commit into
stan-dev:developfrom
jachymb:bugfix/eigen-sym-complex-nested-fwd

Conversation

@jachymb

@jachymb jachymb commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #3477, see details there. I also adjusted wrong error messages, that were likely the result of a careless copypaste.

Important note: The decomposition is actually buggy for general complex-valued matrices anyway, this just makes it compile in the first place!! I will resolve the bugs in a separate PR.

Done with help of claude.

Tests

Added new tests that cover the autodiff for complex eigendecompose_sym, eigenvalues_sym and eigenvectors_sym.
This problem mostly went unnoticed simply because the tests weren't there.

Side Effects

None.

Release notes

Fixed eigen decomposition failing to compile for autodiff of complex matrices.

Checklist

  • Copyright holder: Jáchym Barvínek jachymb@gmail.com

    The copyright holder is typically you or your assignee, such as a university or company. By submitting this pull request, the copyright holder is agreeing to the license the submitted work under the following licenses:
    - Code: BSD 3-clause (https://opensource.org/licenses/BSD-3-Clause)
    - Documentation: CC-BY 4.0 (https://creativecommons.org/licenses/by/4.0/)

  • the basic tests are passing

    • unit tests pass (to run, use: ./runTests.py test/unit)
    • header checks pass, (make test-headers)
    • dependencies checks pass, (make test-math-dependencies)
    • docs build, (make doxygen)
    • code passes the built in C++ standards checks (make cpplint)
  • the code is written in idiomatic C++ and changes are documented in the doxygen

  • the new changes are tested

check_symmetric compared the off-diagonal entries with value_of, which
leaves std::complex<var> for std::complex<fvar<var>>, and fabs of that
does not compile (libstdc++'s std::abs reads __rep). Compare with
value_of_rec instead; for fvar<var> this also stops the check from
recording nodes on the tape. The difference is now a plain double or
std::complex<double>, so call stan::math::abs instead of fabs behind
two using-declarations.

eigenvectors_sym (prim and OpenCL) passed "eigenvalues_sym" as the
function name for its error messages.
@jachymb

jachymb commented Oct 24, 2026

Copy link
Copy Markdown
Contributor Author

Actually, I'm closing this, I think the bugs are too severe to go silently, which would happen with this fix. Better crash the compilation than produce garbage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

eigendecompose_sym, eigenvalues_sym and eigenvectors_sym do not compile for complex matrices of fvar<var> or fvar<fvar<double>>

1 participant