diff --git a/GNNGraphs/src/convert.jl b/GNNGraphs/src/convert.jl index 6735a9d27..de129ab92 100644 --- a/GNNGraphs/src/convert.jl +++ b/GNNGraphs/src/convert.jl @@ -137,7 +137,7 @@ function to_dense(A::ADJMAT_T, T = nothing; dir = :out, num_nodes = nothing, A = T.(A) end if !weighted - A = map(x -> ifelse(x > 0, T(1), T(0)), A) + A = binarize(A, T) end return A, num_nodes, num_edges end diff --git a/GNNGraphs/test/query.jl b/GNNGraphs/test/query.jl index 54aab409b..f5c08001e 100644 --- a/GNNGraphs/test/query.jl +++ b/GNNGraphs/test/query.jl @@ -272,6 +272,15 @@ end @test gw == [1, 1, 1] end + + @testset "fmt" begin + Asparse = adjacency_matrix(g, weighted = false, fmt = :sparse) + @test Asparse isa AbstractSparseMatrix + Adense = adjacency_matrix(g, weighted = false, fmt = :dense) + @test Adense isa AbstractMatrix + @test !(Adense isa AbstractSparseMatrix) + @test collect(Asparse) == Adense + end end @testset "khop_adj" begin diff --git a/GNNlib/ext/GNNlibCUDAExt.jl b/GNNlib/ext/GNNlibCUDAExt.jl index 9cfe45089..8a231c768 100644 --- a/GNNlib/ext/GNNlibCUDAExt.jl +++ b/GNNlib/ext/GNNlibCUDAExt.jl @@ -3,7 +3,7 @@ module GNNlibCUDAExt using CUDA using Random, Statistics, LinearAlgebra using GNNlib: GNNlib, propagate, copy_xj, e_mul_xj, w_mul_xj -using GNNGraphs: GNNGraph, COO_T, SPARSE_T, to_dense, to_sparse +using GNNGraphs: GNNGraph, COO_T, SPARSE_T, to_dense, to_sparse, adjacency_matrix using ChainRulesCore: @non_differentiable const CUDA_COO_T = Tuple{T, T, V} where {T <: AnyCuArray{<:Integer}, V <: Union{Nothing, AnyCuArray}}