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

Fix ne for self-loops #2

Merged
merged 2 commits into from
Nov 22, 2021
Merged

Fix ne for self-loops #2

merged 2 commits into from
Nov 22, 2021

Conversation

yuehhua
Copy link
Contributor

@yuehhua yuehhua commented Nov 2, 2021

This feature should be fixed first. Execution performance could have room to discuss.

@yuehhua
Copy link
Contributor Author

yuehhua commented Nov 19, 2021

@SimonDanisch Would you please review this PR? Thank you.

@SimonDanisch
Copy link
Member

Uh, I don't know this package :D
I guess you want to ping @simonschoelly or @matbesancon ;)

@yuehhua
Copy link
Contributor Author

yuehhua commented Nov 20, 2021

@SimonDanisch Sorry for tagging you. Thank you for pinging the right person.

@@ -18,7 +18,7 @@ mutable struct SimpleWeightedGraph{T<:Integer, U<:Real} <: AbstractSimpleWeighte

end

ne(g::SimpleWeightedGraph) = nnz(g.weights) ÷ 2
ne(g::SimpleWeightedGraph) = (nnz(g.weights) + count(diag(g.weights) .!= 0)) ÷ 2
Copy link
Member

Choose a reason for hiding this comment

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

I think the assumption is, that ne is kind of fast. Ideally we would solve this by either storing the number of edges or the number of self-loops in a separate field, but I guess for now we can also just query for the diagonal elements.

But diag does also allocate a new Vector, so I think we should at least some non-allocating function here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe nselfloop helps?

@simonschoelly
Copy link
Member

Thanks for your changes. In the future we probably should also make a distinction between values that are zero and values that are not in the structure of the sparse matrix, but for now I will just merge this and tag a new patch version, in order to make packages depending on this work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants