Skip to content

Commit f74f0b1

Browse files
committed
type assertions to work around performance of captured variables julia#15726
1 parent cc12736 commit f74f0b1

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/degeneracy.jl

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,13 @@ julia> k_core(g, 2)
150150
2
151151
3
152152
4
153-
5
153+
5
154154
```
155155
"""
156156
function k_core(g::AbstractGraph, k=-1; corenum=core_number(g))
157157
if (k == -1)
158-
k = maximum(corenum) # max core
158+
# type assertion for inference (performance of captured variables julia#15726)
159+
k::Int = maximum(corenum) # max core
159160
end
160161

161162
return findall(x -> x >= k, corenum)
@@ -210,15 +211,16 @@ julia> k_shell(g, 2)
210211
"""
211212
function k_shell(g::AbstractGraph, k=-1; corenum=core_number(g))
212213
if k == -1
213-
k = maximum(corenum)
214+
# type assertion for inference (performance of captured variables julia#15726)
215+
k::Int = maximum(corenum)
214216
end
215217
return findall(x -> x == k, corenum)
216218
end
217219

218220
"""
219221
k_crust(g[, k]; corenum=core_number(g))
220222
221-
Return a vector of vertices in the k-crust of `g`.
223+
Return a vector of vertices in the k-crust of `g`.
222224
If `k` is not specified, return the crust of the core with
223225
the largest degree.
224226
@@ -267,15 +269,16 @@ julia> k_crust(g, 2)
267269
"""
268270
function k_crust(g, k=-1; corenum=core_number(g))
269271
if k == -1
270-
k = maximum(corenum) - 1
272+
# type assertion for inference (performance of captured variables julia#15726)
273+
k::Int = maximum(corenum) - 1
271274
end
272275
return findall(x -> x <= k, corenum)
273276
end
274277

275278
"""
276279
k_corona(g, k; corenum=core_number(g))
277280
278-
Return a vector of vertices in the k-corona of `g`.
281+
Return a vector of vertices in the k-corona of `g`.
279282
280283
The k-corona is the subgraph of vertices in the [`k-core`](@ref k_core) which
281284
have exactly `k` neighbors in the k-core.

0 commit comments

Comments
 (0)