LinearOperator(Matrix) constructor defaults symmetric/hermitian to false even for symmetric input matrices
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 45/100
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:
- Detect that the input matrix satisfies
issymmetric/ishermitianand set the flags accordingly. - Or, if checking the matrix is avoided for performance reasons (since
issymmetricis ), 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
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from JuliaSmoothOptimizers/LinearOperators.jl
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
-
Clarification of required fields for custom operatorsMay be free again @amontoison claimed this 250 days ago, and no pull request is open. Open
JuliaSmoothOptimizers/LinearOperators.jl#412 · 1 comment · 1 reaction · 1 assignee ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
JuliaSmoothOptimizers/LinearOperators.jl#384 · 2 comments ·
-
Regularized Quasi-Newton operatorsMay be free again @molhab claimed this 573 days ago, and no pull request is open. Open
JuliaSmoothOptimizers/LinearOperators.jl#366 · 5 comments · 1 reaction · 2 assignees ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 45/100
All issues in JuliaSmoothOptimizers/LinearOperators.jl
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Sienna-Platform/InfrastructureSystems.jl#675 ·
Maintainers usually reply within 2 days
-
TargetEncoder reuses the first level's shrinkage factor for all levels when m > 0Possibly taken @parth-patel010 claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
JuliaAI/MLJTransforms.jl#95 · 1 comment ·
-
Difficulty 1/5 Under an hour Newbie friendliness 85/100
SciML/RecursiveArrayTools.jl#687 ·
Maintainers usually reply within 3 days
-
Difficulty 1/5 Under an hour Newbie friendliness 65/100
SciML/LinearSolve.jl#1412 ·
Maintainers usually reply within 8 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
SciML/Corleone.jl#179 ·
Maintainers usually reply within 1 day