-
-
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
Implement sorting for Eigen #24536
Closed
Closed
Implement sorting for Eigen #24536
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a7340a0
Implement sort!(::Eigen)
468709f
Add tests
e5aa710
Remove redundant `Base.LinAlg.`
5af6876
Let default sorting be `eigsortby`
0594363
Add kw..., call sort in test
447ea8e
Define copy and refine docstrings for Eigen
c65c90f
Add (@ref)s and manual entries
53b0be2
More tests
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,6 +71,35 @@ isperm(p::Tuple{}) = true | |
isperm(p::Tuple{Int}) = p[1] == 1 | ||
isperm(p::Tuple{Int,Int}) = ((p[1] == 1) & (p[2] == 2)) | ((p[1] == 2) & (p[2] == 1)) | ||
|
||
#swap columns i and j of a, in-place | ||
function swapcols!(a::AbstractMatrix, i, j) | ||
i == j && return | ||
cols = indices(a,2) | ||
(i in cols && j in cols) || throw(BoundsError()) | ||
for k in indices(a,1) | ||
@inbounds a[k,i],a[k,j] = a[k,j],a[k,i] | ||
end | ||
end | ||
# like permute!! applied to each row of a, in-place in a (overwriting p). | ||
function permutecols!!(a::AbstractMatrix, p::AbstractVector{<:Integer}) | ||
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. might be generally useful to have and export, along with corresponding |
||
count = 0 | ||
start = 0 | ||
while count < length(p) | ||
ptr = start = findnext(!iszero, p, start+1) | ||
next = p[start] | ||
count += 1 | ||
while next != start | ||
swapcols!(a, ptr, next) | ||
p[ptr] = 0 | ||
ptr = next | ||
next = p[next] | ||
count += 1 | ||
end | ||
p[ptr] = 0 | ||
end | ||
a | ||
end | ||
|
||
function permute!!(a, p::AbstractVector{<:Integer}) | ||
count = 0 | ||
start = 0 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
would be clearer with spaces after the outer commas