LinearOperator(Matrix) constructor defaults symmetric/hermitian to false even for symmetric input matrices

Open
#393 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
julia
Domain
tooling

Research direction

The entry point is the LinearOperator(H_dense) constructor; reproduce the Julia example and inspect how symmetric and hermitian flags are initialized for Matrix and AbstractMatrix inputs. Compare behavior for Symmetric and Hermitian wrappers, then run focused constructor tests covering the expected flags and confirm downstream solver selection is preserved.

Written by the indexing model from the issue text.

Description

Description
When constructing a LinearOperator from a standard dense Matrix (or AbstractMatrix) that is symmetric or Hermitian, the resulting operator does not automatically detect or inherit these properties. It defaults symmetric and hermitian to false.

While explicit keywords (symmetric=true) can force these properties, users expect the constructor to inspect the input matrix properties or default to the correct state when issymmetric(A) is true, similar to how other Julia types might behave.

Steps to Reproduce

using LinearOperators, LinearAlgebra

n = 5
# Create a real symmetric matrix manually
H_dense = rand(n, n)
H_dense = H_dense + H_dense'

# Verify the matrix is actually Hermitian/Symmetric
println("Is input hermitian? ", ishermitian(H_dense)) # Output: true

# Wrap in LinearOperator
H_op = LinearOperator(H_dense)

# Inspect properties
display(H_op)

Observed Behavior
The resulting LinearOperator has both flags set to false:

Linear operator
  nrow: 5
  ncol: 5
  eltype: Float64
  symmetric: false
  hermitian: false
  nprod:   0
  ntprod:  0
  nctprod: 0

Expected Behavior
The LinearOperator should either:

  1. Detect that the input matrix satisfies issymmetric/ishermitian and set the flags accordingly.
  2. Or, if checking the matrix is avoided for performance reasons (since issymmetric is ), this behavior should be explicitly warned or documented, as it breaks downstream solvers that rely on these properties (e.g., Krylov methods choosing CG over GMRES).

Potential Fix/Suggestion
If checks are undesirable during construction, perhaps the constructor should check if the input is wrapped in LinearAlgebra.Symmetric or LinearAlgebra.Hermitian and inherit properties from those types automatically.

Environment

  • Julia version: 1.11.x
  • LinearOperators.jl version: (Current Main)
Dominant language
Julia
Stars
214
Forks
46
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from JuliaSmoothOptimizers/LinearOperators.jl

All issues in JuliaSmoothOptimizers/LinearOperators.jl

Similar issues

More Julia issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.