Skip to content

Commit 7e7e202

Browse files
perturb_nodes -> remove_nodes (#454)
1 parent 1823e0d commit 7e7e202

File tree

11 files changed

+56
-61
lines changed

11 files changed

+56
-61
lines changed

.github/workflows/tests_GNNGraphs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
matrix:
1616
version:
1717
- '1.10' # Replace this with the minimum Julia version that your package supports.
18-
- '1' # '1' will automatically expand to the latest stable 1.x release of Julia.
18+
# - '1' # '1' will automatically expand to the latest stable 1.x release of Julia.
1919
# - 'pre'
2020
os:
2121
- ubuntu-latest

.github/workflows/tests_GraphNeuralNetworks.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
matrix:
1616
version:
1717
- '1.10' # Replace this with the minimum Julia version that your package supports.
18-
- '1' # '1' will automatically expand to the latest stable 1.x release of Julia.
18+
# - '1' # '1' will automatically expand to the latest stable 1.x release of Julia.
1919
# - 'pre'
2020
os:
2121
- ubuntu-latest

GNNGraphs/Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "GNNGraphs"
22
uuid = "aed8fd31-079b-4b5a-b342-a13352159b8c"
33
authors = ["Carlo Lucibello and contributors"]
4-
version = "0.1.0"
4+
version = "1.0.0"
55

66
[deps]
77
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
@@ -46,7 +46,7 @@ SparseArrays = "1"
4646
Statistics = "1"
4747
StatsBase = "0.34"
4848
cuDNN = "1"
49-
julia = "1.9"
49+
julia = "1.10"
5050

5151
[extras]
5252
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"

GNNGraphs/ext/GNNGraphsCUDAExt.jl

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
module GNNGraphsCUDAExt
2+
3+
using CUDA
4+
using Random, Statistics, LinearAlgebra
5+
using GNNGraphs
6+
using GNNGraphs: COO_T, ADJMAT_T, SPARSE_T
7+
8+
const CUMAT_T = Union{CUDA.AnyCuMatrix, CUDA.CUSPARSE.CuSparseMatrix}
9+
10+
# Query
11+
12+
GNNGraphs._rand_dense_vector(A::CUMAT_T) = CUDA.randn(size(A, 1))
13+
14+
# Transform
15+
16+
GNNGraphs.dense_zeros_like(a::CUMAT_T, T::Type, sz = size(a)) = CUDA.zeros(T, sz)
17+
18+
19+
# Utils
20+
21+
GNNGraphs.iscuarray(x::AnyCuArray) = true
22+
23+
24+
function sort_edge_index(u::AnyCuArray, v::AnyCuArray)
25+
dev = get_device(u)
26+
cdev = cpu_device()
27+
u, v = u |> cdev, v |> cdev
28+
#TODO proper cuda friendly implementation
29+
sort_edge_index(u, v) |> dev
30+
end
31+
32+
33+
end #module

GNNGraphs/ext/GNNGraphsCUDAExt/GNNGraphsCUDAExt.jl

Lines changed: 0 additions & 14 deletions
This file was deleted.

GNNGraphs/ext/GNNGraphsCUDAExt/query.jl

Lines changed: 0 additions & 2 deletions
This file was deleted.

GNNGraphs/ext/GNNGraphsCUDAExt/transform.jl

Lines changed: 0 additions & 2 deletions
This file was deleted.

GNNGraphs/ext/GNNGraphsCUDAExt/utils.jl

Lines changed: 0 additions & 11 deletions
This file was deleted.

GNNGraphs/src/GNNGraphs.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ export add_nodes,
8080
perturb_edges,
8181
remove_nodes,
8282
ppr_diffusion,
83-
drop_nodes,
8483
# from MLUtils
8584
batch,
8685
unbatch,

GNNGraphs/src/transform.jl

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -307,35 +307,27 @@ function remove_nodes(g::GNNGraph{<:COO_T}, nodes_to_remove::AbstractVector)
307307
end
308308

309309
"""
310-
drop_nodes(g::GNNGraph{<:COO_T}, p)
310+
remove_nodes(g::GNNGraph, p)
311311
312-
Randomly drop nodes (and their associated edges) from a GNNGraph based on a given probability.
313-
Dropping nodes is a technique that can be used for graph data augmentation, refering paper [DropNode](https://arxiv.org/pdf/2008.12578.pdf).
312+
Returns a new graph obtained by dropping nodes from `g` with independent probabilities `p`.
314313
315-
# Arguments
316-
- `g`: The input graph from which nodes (and their associated edges) will be dropped.
317-
- `p`: The probability of dropping each node. Default value is `0.5`.
318-
319-
# Returns
320-
A modified GNNGraph with nodes (and their associated edges) dropped based on the given probability.
314+
# Examples
321315
322-
# Example
323316
```julia
324-
using GraphNeuralNetworks
325-
# Construct a GNNGraph
326-
g = GNNGraph([1, 1, 2, 2, 3], [2, 3, 1, 3, 1], num_nodes=3)
327-
# Drop nodes with a probability of 0.5
328-
g_new = drop_node(g, 0.5)
329-
println(g_new)
317+
julia> g = GNNGraph([1, 1, 2, 2, 3, 4], [1, 2, 3, 1, 3, 1])
318+
GNNGraph:
319+
num_nodes: 4
320+
num_edges: 6
321+
322+
julia> g_new = remove_nodes(g, 0.5)
323+
GNNGraph:
324+
num_nodes: 2
325+
num_edges: 2
330326
```
331327
"""
332-
function drop_nodes(g::GNNGraph{<:COO_T}, p = 0.5)
333-
num_nodes = g.num_nodes
334-
nodes_to_remove = filter(_ -> rand() < p, 1:num_nodes)
335-
336-
new_g = remove_nodes(g, nodes_to_remove)
337-
338-
return new_g
328+
function remove_nodes(g::GNNGraph, p::AbstractFloat)
329+
nodes_to_remove = filter(_ -> rand() < p, 1:g.num_nodes)
330+
return remove_nodes(g, nodes_to_remove)
339331
end
340332

341333
"""

0 commit comments

Comments
 (0)