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

[Port] New s_metric method #28

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

etiennedeg
Copy link
Member

This is a port of #1548

@codecov
Copy link

codecov bot commented Nov 7, 2021

Codecov Report

Merging #28 (007de78) into master (6ab2160) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master      #28   +/-   ##
=======================================
  Coverage   99.45%   99.46%           
=======================================
  Files         106      107    +1     
  Lines        5554     5562    +8     
=======================================
+ Hits         5524     5532    +8     
  Misses         30       30           

"""

function s_metric(g::AbstractGraph{T}; norm=true) where T
s = zero(T)
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe zero(T) is not the right type here. For small graphs it might be something like Int8 that would overflow quite soon. Maybe it is best, to use Int here, or Float64, then the resulting type would be the same no matter if norm is set to true or false.

```
"""

function s_metric(g::AbstractGraph{T}; norm=true) where T
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
function s_metric(g::AbstractGraph{T}; norm=true) where T
function s_metric(g::AbstractGraph{T}; norm::Bool=true) where T

function s_metric(g::AbstractGraph{T}; norm=true) where T
s = zero(T)
for e in edges(g)
s += outdegree(g, src(e)) * indegree(g, dst(e))
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need some special handling for self-loops here?

sm2 /= sum(degree(g).^3)/2
@test @inferred sm ≈ sm2
end
end
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we have some tests here for graphs different from random graphs? I am especially thinking about graphs with self-loops and isolated vertices.

Also, it would be good to test with graphs of eltype different than Int.

Comment on lines +8 to +9
@test @inferred sm ≈ sm2
sm = s_metric(g, norm=true)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
@test @inferred sm sm2
sm = s_metric(g, norm=true)
@test sm sm2
sm = @inferred s_metric(g, norm=true)

The inferred macro is used to check if a function is type stable, i.e. the compiler can infer its resulting argument. What you are testing here is, if is type stable, which is probably not what you want.

@simonschoelly
Copy link
Contributor

@etiennedeg @vboussange This PR already looks quite good, but I think we need to fix a few things before we can merge it.

@gdalle gdalle added the enhancement New feature or request label Jun 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants