Description
openedon Oct 16, 2020
We should allow symmetry/conjugate-symmetry preserving operations on Symmertic/Hermitian matrices.
For example the following failures should not be failures.
julia> AS = Symmetric([1 2; 2 4])
2×2 Symmetric{Int64, Matrix{Int64}}:
1 2
2 4
julia> AS .+= deepcopy(AS)
ERROR: ArgumentError: Cannot set a non-diagonal index in a symmetric matrix
julia> AS .+= 1
ERROR: ArgumentError: Cannot set a non-diagonal index in a symmetric matrix
julia> AS .*= 2
ERROR: ArgumentError: Cannot set a non-diagonal index in a symmetric matrix
julia> map!(x -> x==1 ? 10 : 20, AS, AS) # i suspect this one is harder
ERROR: ArgumentError: Cannot set a non-diagonal index in a symmetric matrix
julia> mul!(deepcopy(AS), AS, 2)
ERROR: ArgumentError: Cannot set a non-diagonal index in a symmetric matrix
These are annoying, they make it hard to write code that is generic to the type of the AbstractArray
;
even when you know that the operation you are doing will be symmertic if the input is etc.
E.g. because you are implementing a linear operator, (I think as a rule linear operators tend to preserve a structure one cares about for a type that represents a particular vector subspace)
To keep this issue focused, lets avoid talking about what to do for asymmetric (/non-conjugate symmetric) operations that can be turned into symmetric (/conjugate symmetric) ones.
i.e. not talking about making it so that after running AH[2,3] = 100
then it is observatory as AH[2,3] == AH[3,2] == 100
.
Just about things that do preserve the symmetry (/conjugate symmetry)
The effect on this on the parent matrix could either be specifically undefined, or define to only set in the given upper/lower, or actually change both.
related: #38055