Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow diagm(v) for a vector v #609

Closed
dpsanders opened this issue Feb 19, 2019 · 10 comments
Closed

Allow diagm(v) for a vector v #609

dpsanders opened this issue Feb 19, 2019 · 10 comments
Labels
feature Indicates new feature / enhancement requests good first issue Good for newcomers help wanted Extra attention is needed

Comments

@dpsanders
Copy link

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
@ararslan
Copy link
Member

This method was explicitly deprecated in JuliaLang/julia#24047, so cc @fredrikekre

@dpsanders
Copy link
Author

I guess the "correct" solution is Diagonal(v).

@StefanKarpinski
Copy link
Member

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).

@StefanKarpinski StefanKarpinski added feature Indicates new feature / enhancement requests help wanted Extra attention is needed good first issue Good for newcomers labels Feb 19, 2019
@eulerkochy
Copy link
Contributor

Are you implying to create a sort-of alias for diagm(v)?

@StefanKarpinski
Copy link
Member

No, just to define the missing method.

@ChanchalKumarMaji
Copy link

Hello, I was planning to contribute towards GSoC 2019. I want to contribute to this issue. Please help me how to start.

@StefanKarpinski
Copy link
Member

Thanks for the interest, @ChanchalKumarMaji. There is already a PR implementing this: JuliaLang/julia#31125.

@ChanchalKumarMaji
Copy link

Ok, thanks for the response, I will look into another issue.

@karthikrangasai
Copy link

@StefanKarpinski , I just submitted a PR for this issue JuliaLang/julia#31210

@StefanKarpinski
Copy link
Member

That's great, however, as I said, there's already a pull request implementing this feature that has gone through several iterations.

@KristofferC KristofferC transferred this issue from JuliaLang/julia Nov 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Indicates new feature / enhancement requests good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

6 participants