It would be useful to allow diagm(v)
for a vector v
, for the common case of wanting that vector on the main diagonal:
julia> using LinearAlgebra
julia> v = [3, 4]
2-element Array{Int64,1}:
3
4
julia> diagm(v)
ERROR: MethodError: no method matching diagm(::Array{Int64,1})
Closest candidates are:
diagm(::Pair{#s623,#s622} where #s622<:(AbstractArray{T,1} where T) where #s623<:Integer...) at /Users/osx/buildbot/slave/package_osx64/build/usr/share/julia/stdlib/v1.1/LinearAlgebra/src/dense.jl:291
Stacktrace:
[1] top-level scope at none:0
julia> diagm(0=>v)
2脳2 Array{Int64,2}:
3 0
0 4
This method was explicitly deprecated in #24047, so cc @fredrikekre
I guess the "correct" solution is Diagonal(v)
.
Eh, I don't see why we need to be fussy about this. Let's just allow diagm(v)
as a shorthand for the very common case diagm(0 => v)
.
Are you implying to create a sort-of alias for diagm(v)
?
No, just to define the missing method.
Hello, I was planning to contribute towards GSoC 2019. I want to contribute to this issue. Please help me how to start.
Thanks for the interest, @ChanchalKumarMaji. There is already a PR implementing this: https://github.com/JuliaLang/julia/pull/31125.
Ok, thanks for the response, I will look into another issue.
@StefanKarpinski , I just submitted a PR for this issue https://github.com/JuliaLang/julia/pull/31210
That's great, however, as I said, there's already a pull request implementing this feature that has gone through several iterations.
Most helpful comment
I guess the "correct" solution is
Diagonal(v)
.