1
+ struct TemporalSnapshotsGNNGraph
2
+ num_nodes:: Vector{Int}
3
+ num_edges:: Vector{Int}
4
+ num_snapshots:: Int
5
+ snapshots:: Vector{<:GNNGraph}
6
+ tgdata:: DataStore
7
+ end
8
+
9
+ function TemporalSnapshotsGNNGraph (snapshots:: AbstractVector{<:GNNGraph} )
10
+ @assert all ([s. num_nodes == snapshots[1 ]. num_nodes for s in snapshots]) " all snapshots must have the same number of nodes"
11
+ return TemporalSnapshotsGNNGraph (
12
+ [s. num_nodes for s in snapshots],
13
+ [s. num_edges for s in snapshots],
14
+ length (snapshots),
15
+ snapshots,
16
+ DataStore ()
17
+ )
18
+ end
19
+
20
+ function Base.:(== )(tsg1:: TemporalSnapshotsGNNGraph , tsg2:: TemporalSnapshotsGNNGraph )
21
+ tsg1 === tsg2 && return true
22
+ for k in fieldnames (typeof (tsg1))
23
+ getfield (tsg1, k) != getfield (tsg2, k) && return false
24
+ end
25
+ return true
26
+ end
27
+
28
+ function Base. getindex (tg:: TemporalSnapshotsGNNGraph , t:: Int )
29
+ return tg. snapshots[t]
30
+ end
31
+
32
+ function Base. getindex (tg:: TemporalSnapshotsGNNGraph , t:: AbstractVector )
33
+ return TemporalSnapshotsGNNGraph (tg. num_nodes[t], tg. num_edges[t], length (t), tg. snapshots[t], tg. tgdata)
34
+ end
35
+
36
+ function add_snapshot (tg:: TemporalSnapshotsGNNGraph , t:: Int , g:: GNNGraph )
37
+ @assert g. num_nodes == tg. num_nodes[t] " number of nodes must match"
38
+ num_nodes= tg. num_nodes
39
+ num_edges = tg. num_edges
40
+ snapshots = tg. snapshots
41
+ num_snapshots = tg. num_snapshots + 1
42
+ insert! (num_nodes, t, g. num_nodes)
43
+ insert! (num_edges, t, g. num_edges)
44
+ insert! (snapshots, t, g)
45
+ return TemporalSnapshotsGNNGraph (num_nodes, num_edges, num_snapshots, snapshots, tg. tgdata)
46
+ end
47
+
48
+ function remove_snapshot (tg:: TemporalSnapshotsGNNGraph , t:: Int )
49
+ num_nodes= tg. num_nodes
50
+ num_edges = tg. num_edges
51
+ snapshots = tg. snapshots
52
+ num_snapshots = tg. num_snapshots - 1
53
+ deleteat! (num_nodes, t)
54
+ deleteat! (num_edges, t)
55
+ deleteat! (snapshots, t)
56
+ return TemporalSnapshotsGNNGraph (num_nodes, num_edges, num_snapshots, snapshots, tg. tgdata)
57
+ end
58
+
59
+ function Base. show (io:: IO , tsg:: TemporalSnapshotsGNNGraph )
60
+ print (io, " TemporalSnapshotsGNNGraph($(tsg. num_snapshots) ) with " )
61
+ print_feature_t (io, tsg. tgdata)
62
+ print (io, " data" )
63
+ end
64
+
65
+ function Base. show (io:: IO , :: MIME"text/plain" , tsg:: TemporalSnapshotsGNNGraph )
66
+ if get (io, :compact , false )
67
+ print (io, " TemporalSnapshotsGNNGraph($(tsg. num_snapshots) ) with " )
68
+ print_feature_t (io, tsg. tgdata)
69
+ print (io, " data" )
70
+ else
71
+ print (io,
72
+ " TemporalSnapshotsGNNGraph:\n num_nodes: $(tsg. num_nodes) \n num_edges: $(tsg. num_edges) \n num_snapshots: $(tsg. num_snapshots) " )
73
+ if ! isempty (tsg. tgdata)
74
+ print (io, " \n tgdata:" )
75
+ for k in keys (tsg. tgdata)
76
+ print (io, " \n\t $k = $(shortsummary (tsg. tgdata[k])) " )
77
+ end
78
+ end
79
+ end
80
+ end
81
+
82
+
83
+ function print_feature_t (io:: IO , feature)
84
+ if ! isempty (feature)
85
+ if length (keys (feature)) == 1
86
+ k = first (keys (feature))
87
+ v = first (values (feature))
88
+ print (io, " $(k) : $(dims2string (size (v))) " )
89
+ else
90
+ print (io, " (" )
91
+ for (i, (k, v)) in enumerate (pairs (feature))
92
+ print (io, " $k : $(dims2string (size (v))) " )
93
+ if i == length (feature)
94
+ print (io, " )" )
95
+ else
96
+ print (io, " , " )
97
+ end
98
+ end
99
+ end
100
+ else
101
+ print (io, " no" )
102
+ end
103
+ end
0 commit comments