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

adjacency_matrix: Collect neighbors before sorting them #71

Merged
merged 2 commits into from
Dec 23, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/linalg/spectral.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function _adjacency_matrix(g::AbstractGraph, T::DataType, neighborfn::Function,
nz -= 1
end
end
dsts = sort(neighborfn(g, j)) # TODO for most graphs it might not be necessary to sort
dsts = sort!(collect(neighborfn(g, j))) # TODO for most graphs it might not be necessary to sort
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In place sort! can be algorithmically a fair bit slower than the out of place version.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my benchmark, it seemed to be rather equivalent and to allocate less, but you are probably more knowledgeable than me

colpt[j + 1] = colpt[j] + length(dsts)
append!(rowval, dsts)
end
Expand Down