Product of a scalar with Symmetric is not symmetric (while Symmetric times scalar is)

julia> using LinearAlgebra
julia> A = Symmetric(rand(4,4))
4×4 Symmetric{Float64,Array{Float64,2}}:
 0.0410142  0.31574   0.0784682  0.649851
 0.31574    0.315311  0.908595   0.376246
 0.0784682  0.908595  0.758999   0.965215
 0.649851   0.376246  0.965215   0.13525
julia> A*2.0
4×4 Symmetric{Float64,Array{Float64,2}}:
 0.0820284  0.631481  0.156936  1.2997
 0.631481   0.630623  1.81719   0.752492
 0.156936   1.81719   1.518     1.93043
 1.2997     0.752492  1.93043   0.270501
julia> 2.0*A
4×4 Array{Float64,2}:
 0.0820284  0.631481  0.156936  1.2997
 0.631481   0.630623  1.81719   0.752492
 0.156936   1.81719   1.518     1.93043
 1.2997     0.752492  1.93043   0.270501
1 Like

Can you open an issue at the JuliaLang/julia repo on GitHub and link to this thread?
The problematic lines are julia/symmetric.jl at da964d6178c5b22e9dc4b1dd8489f052f4b73e94 · JuliaLang/julia · GitHub which should probably be updated as

diff --git a/stdlib/LinearAlgebra/src/symmetric.jl b/stdlib/LinearAlgebra/src/symmetric.jl
index b5f6204..d8aad50 100644
--- a/stdlib/LinearAlgebra/src/symmetric.jl
+++ b/stdlib/LinearAlgebra/src/symmetric.jl
@@ -442,9 +442,9 @@ mul!(C::StridedMatrix{T}, A::StridedMatrix{T}, B::Hermitian{T,<:StridedMatrix})
 
 for T in (:Symmetric, :Hermitian), op in (:*, :/)
     # Deal with an ambiguous case
-    @eval ($op)(A::$T, x::Bool) = ($T)(($op)(A.data, x), sym_uplo(A.uplo))
+    @eval ($op)(A::$T, x::Bool) = broadcast($op, A, x)
     S = T == :Hermitian ? :Real : :Number
-    @eval ($op)(A::$T, x::$S) = ($T)(($op)(A.data, x), sym_uplo(A.uplo))
+    @eval ($op)(A::$T, x::$S) = broadcast($op, A, x)
 end
 
 function factorize(A::HermOrSym{T}) where T
1 Like

Done! Also noticed that the addition between symmetric matrices was not working.

[EDIT : ] link to Github issue https://github.com/JuliaLang/julia/issues/29392

1 Like

You mean that the result is not of type Symmetric? See Adding (SymTri)Diagonal, Symmetric or Hermitian matrices together · Issue #22550 · JuliaLang/julia · GitHub

Yes exactly!