Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion GNNGraphs/src/transform.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ end

function remove_self_loops(g::GNNGraph{<:ADJMAT_T})
@assert isempty(g.edata)
A = g.graph
A = copy(g.graph)
A[diagind(A)] .= 0
if A isa AbstractSparseMatrix
dropzeros!(A)
Expand Down
14 changes: 14 additions & 0 deletions GNNGraphs/test/transform.jl
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,20 @@ end
@test size(get_edge_weight(g2)) == (g2.num_edges,)
@test size(g2.edata.e1) == (3, g2.num_edges)
@test size(g2.edata.e2) == (g2.num_edges,)
else
A = [1 1 0
0 1 1
1 0 0]
A_no_loops = [0 1 0
0 0 1
1 0 0]
g = GNNGraph(A; graph_type = GRAPH_T)
g2 = remove_self_loops(g)

@test Matrix(adjacency_matrix(g)) == A
@test Matrix(adjacency_matrix(g2)) == A_no_loops
@test g2.num_edges == count(!iszero, A_no_loops)
@test g.graph !== g2.graph
end
end
end
Expand Down
Loading