-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
rewrite diagm with Pair's #24047
rewrite diagm with Pair's #24047
Conversation
|
Yes, I agree. Will update #23757 and then fix up this. |
0716e7a
to
ea52f6f
Compare
base/linalg/dense.jl
Outdated
for p in kv | ||
inds = diagind(A, p.first) | ||
for (i, val) in enumerate(p.second) | ||
A[inds[i]] = val |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we have this as +=
to be consistent with how the spdiagm
works?
ea52f6f
to
c05f686
Compare
NEWS.md
Outdated
@@ -313,6 +313,8 @@ Library improvements | |||
|
|||
* REPL Undo via Ctrl-/ and Ctrl-_ | |||
|
|||
* `diagm` now accepts several diagonal index/vector pairs ([#24047]). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps "pairs" -> "Pair
s"?
base/linalg/dense.jl
Outdated
|
||
Construct a matrix by placing `v` on the `k`th diagonal. This constructs a full matrix; if | ||
you want a storage-efficient version with fast arithmetic, use [`Diagonal`](@ref) instead. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The note re. Diagonal
might be worth retaining (beyond merely the reference)?
for p in kv | ||
inds = diagind(A, p.first) | ||
for (i, val) in enumerate(p.second) | ||
A[inds[i]] += val |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why +=
rather than =
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be consistent with spdiagm
, since combine
in sparse
defaults to +
. See #24047 (comment) . Do you have another opinion about this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, do IIUC that its purpose is e.g. [sp]diagm(0 => [1, 2, 3], 0 => [4, 5, 6])
yielding [sp]diagm(0 => [5, 7, 9])
? If so, cheers, and thanks! :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think it is the most natural thing to do.
base/linalg/generic.jl
Outdated
@@ -739,13 +739,13 @@ of the [`eltype`](@ref) of `A`. | |||
julia> rank(eye(3)) | |||
3 | |||
|
|||
julia> rank(diagm([1, 0, 2])) | |||
julia> rank(0 => diagm([1, 0, 2])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rank(diagm(0 => [1, 0, 2]))
?
@test Array(imag(T)) == imag(diagm(dv)) + imag(diagm(ev, uplo == :U ? 1 : -1)) | ||
@test Array(abs.(T)) == abs.(diagm(0 => dv, (uplo == :U ? 1 : -1) => ev)) | ||
@test Array(real(T)) == real(diagm(0 => dv, (uplo == :U ? 1 : -1) => ev)) | ||
@test Array(imag(T)) == imag(diagm(0 => dv, (uplo == :U ? 1 : -1) => ev)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These changes are a lovely illustration of how this API change improves things :).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm modulo the minor comments! Thanks @fredrikekre! :)
c05f686
to
71fe871
Compare
Thanks @fredrikekre! :) |
I was wondering if |
Agree: passing a single vector for the main diagonal seems perfectly legit to me, we should keep it. |
ref #23320, #23757