CarloLucibello / GraphNeuralNetworks.jl

Graph Neural Networks in Julia
https://carlolucibello.github.io/GraphNeuralNetworks.jl/dev/
MIT License
214 stars 47 forks source link

Add topk features #260

Open aurorarossi opened 1 year ago

aurorarossi commented 1 year ago

With this PR I add the topk_nodes and topk_edges features (see issue https://github.com/CarloLucibello/GraphNeuralNetworks.jl/issues/41).

CarloLucibello commented 1 year ago

I think it is more useful and general to have a function with signature

topk_nodes(g::GNNGraph, x::AbstractArray, k::Int; rev::Bool = true, sortby::Union{Nothing, Int} = nothing)

instead of passing the tensor name.

Also, the docstring needs much more explanation of the purpose of this function, the various arguments, and the returned objects.

Following DGL, I think it is useful to return both the sorted array and permutation. So if we call (y, partialperm) the output:

CarloLucibello commented 5 months ago

Does it work on gpu as well?

aurorarossi commented 5 months ago

Yes, it works on the GPU.

CarloLucibello commented 5 months ago

I think it would be nice to contribute topk_matrix as a topk function in MLUtils.jl and then base this PR on top of that.

Then I would have here two functions, topk_nodes and topk_edges as in Deep Graph Library (https://docs.dgl.ai/generated/dgl.topk_nodes.html#dgl.topk_nodes)