Skip to content

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

Description

@farhadrclass

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)

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions