Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix vector DataStore #505

Merged
merged 3 commits into from
Oct 25, 2024
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: 2 additions & 0 deletions GNNGraphs/src/GNNGraphs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,6 @@ include("gatherscatter.jl")
include("mldatasets.jl")
export mldataset2gnngraph

include("deprecations.jl")

end #module
10 changes: 1 addition & 9 deletions GNNGraphs/src/datastore.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,7 @@ function Base.getproperty(ds::DataStore, s::Symbol)
end
end

function Base.getproperty(vds::Vector{DataStore}, s::Symbol)
if s === :_n
return [getn(ds) for ds in vds]
elseif s === :_data
return [getdata(ds) for ds in vds]
else
return [getdata(ds)[s] for ds in vds]
end
end


function Base.setproperty!(ds::DataStore, s::Symbol, x)
@assert s != :_n "cannot set _n directly"
Expand Down
13 changes: 13 additions & 0 deletions GNNGraphs/src/deprecations.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## Deprecated in V0.6

function Base.getproperty(vds::Vector{DataStore}, s::Symbol)
if s ∈ (:ref, :size) # these are arrays fields in V0.11
return getfield(vds, s)
elseif s === :_n
return [getn(ds) for ds in vds]
elseif s === :_data
return [getdata(ds) for ds in vds]
else
return [getdata(ds)[s] for ds in vds]
end
end
8 changes: 3 additions & 5 deletions GNNGraphs/test/datastore.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@ end
@test_throws DimensionMismatch ds.z=rand(12)
ds.z = [1:10;]
@test ds.z == [1:10;]
vec = [DataStore(10, (:x => x,)), DataStore(10, (:x => x, :y => rand(2, 10)))]
@test vec.x == [x, x]
@test_throws KeyError vec.z
@test vec._n == [10, 10]
@test vec._data == [Dict(:x => x), Dict(:x => x, :y => vec[2].y)]

# issue #504, where vector creation failed
@test fill(DataStore(), 3) isa Vector
end

@testset "setindex!" begin
Expand Down
14 changes: 8 additions & 6 deletions GraphNeuralNetworks/docs/src/temporalgraph.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,15 @@ GNNGraph:
```

## Data Features

Node, edge, and graph features can be added at construction time or later using:
A temporal graph can stode global feautre for the entire time series in the `tgdata` filed.
Also, each snapshot can store node, edge, and graph features in the `ndata`, `edata`, and `gdata` fields, respectively.

```jldoctest
julia> snapshots = [rand_graph(10,20; ndata = rand(3,10)), rand_graph(10,14; ndata = rand(4,10)), rand_graph(10,22; ndata = rand(5,10))]; # node features at construction time

julia> tg = TemporalSnapshotsGNNGraph(snapshots);

julia> tg.tgdata.y = rand(3,1); # graph features after construction
julia> tg.tgdata.y = rand(3,1); # add global features after construction

julia> tg
TemporalSnapshotsGNNGraph:
Expand All @@ -109,7 +109,7 @@ TemporalSnapshotsGNNGraph:
tgdata:
y = 3×1 Matrix{Float64}

julia> tg.ndata # vector of Datastore for node features
julia> tg.ndata # vector of DataStore containing node features for each snapshot
3-element Vector{DataStore}:
DataStore(10) with 1 element:
x = 3×10 Matrix{Float64}
Expand All @@ -118,8 +118,10 @@ julia> tg.ndata # vector of Datastore for node features
DataStore(10) with 1 element:
x = 5×10 Matrix{Float64}

julia> typeof(tg.ndata.x) # vector containing the x feature of each snapshot
Vector{Matrix{Float64}}
julia> [ds.x for ds in tg.ndata]; # vector containing the x feature of each snapshot

julia> [g.x for g in tg.snapshots]; # same vector as above, now accessing
# the x feature directly from the snapshots
```

## Graph convolutions on TemporalSnapshotsGNNGraph
Expand Down
Loading