-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Change diag(A::StructuredMatrix[, k=0]) #24324
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -270,15 +270,15 @@ function triu!(M::Bidiagonal, k::Integer=0) | |
| return M | ||
| end | ||
|
|
||
| function diag(M::Bidiagonal{T}, n::Integer=0) where T | ||
| function diag(M::Bidiagonal, n::Integer=0) | ||
| # every branch call similar(..., ::Int) to make sure the | ||
| # same vector type is returned independent of n | ||
| if n == 0 | ||
| return M.dv | ||
| elseif n == 1 | ||
| return M.uplo == 'U' ? M.ev : zeros(T, size(M,1)-1) | ||
| elseif n == -1 | ||
| return M.uplo == 'L' ? M.ev : zeros(T, size(M,1)-1) | ||
| return copy!(similar(M.dv, length(M.dv)), M.dv) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could the
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moreover, why not simply
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes, that was the idea, to guarantee that we take the same path no matter which diagonal was requested.
Same comment applies; guarantee the same code path. Also julia> copy(1:4)
1:4I don't think the
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good then! I might consider adding comments to make the intention clear for future readers; to someone not acquainted with the subtleties involved, the intention may be far from clear :).
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yea, Ill add that |
||
| elseif (n == 1 && M.uplo == 'U') || (n == -1 && M.uplo == 'L') | ||
| return copy!(similar(M.ev, length(M.ev)), M.ev) | ||
| elseif -size(M,1) <= n <= size(M,1) | ||
| return zeros(T, size(M,1)-abs(n)) | ||
| return fill!(similar(M.dv, size(M,1)-abs(n)), 0) | ||
| else | ||
| throw(ArgumentError(string("requested diagonal, $n, must be at least $(-size(M, 1)) ", | ||
| "and at most $(size(M, 2)) for an $(size(M, 1))-by-$(size(M, 2)) matrix"))) | ||
|
|
||
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.
👍 :)