-
Notifications
You must be signed in to change notification settings - Fork 39
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)