-
Notifications
You must be signed in to change notification settings - Fork 92
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
base: master
Are you sure you want to change the base?
Conversation
This reverts commit b3c00760cac82c6826c807383b87f7bb75d0691a.
I have been messing up with the branches in my pull requests, trying to solve this now
Codecov Report
@@ 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) |
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.
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 |
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.
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)) |
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.
Do we need some special handling for self-loops here?
sm2 /= sum(degree(g).^3)/2 | ||
@test @inferred sm ≈ sm2 | ||
end | ||
end |
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.
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
.
@test @inferred sm ≈ sm2 | ||
sm = s_metric(g, norm=true) |
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.
@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.
@etiennedeg @vboussange This PR already looks quite good, but I think we need to fix a few things before we can merge it. |
This is a port of #1548