@@ -19,15 +19,11 @@ References to graph or features are hold in this type.
19
19
- `edge_feature`: edge features attached to graph.
20
20
- `gloabl_feature`: gloabl graph features attached to graph.
21
21
"""
22
- struct FeaturedGraph{T,S,R,Q} <: AbstractFeaturedGraph
23
- graph:: Ref{T}
24
- nf:: Ref{S}
25
- ef:: Ref{R}
26
- gf:: Ref{Q}
27
-
28
- function FeaturedGraph (graph:: T , nf:: S , ef:: R , gf:: Q ) where {T,S<: AbstractMatrix ,R<: AbstractMatrix ,Q<: AbstractVector }
29
- new {T,S,R,Q} (Ref (graph), Ref (nf), Ref (ef), Ref (gf))
30
- end
22
+ mutable struct FeaturedGraph{T,S,R,Q} <: AbstractFeaturedGraph
23
+ graph:: T
24
+ nf:: S
25
+ ef:: R
26
+ gf:: Q
31
27
end
32
28
33
29
FeaturedGraph () = FeaturedGraph (zeros (0 ,0 ), zeros (0 ,0 ), zeros (0 ,0 ), zeros (0 ))
@@ -42,97 +38,97 @@ FeaturedGraph(graph::T, nf::AbstractMatrix) where {T} = FeaturedGraph(graph, nf,
42
38
Get referenced graph.
43
39
"""
44
40
graph (:: NullGraph ) = nothing
45
- graph (fg:: FeaturedGraph ) = fg. graph[]
41
+ graph (fg:: FeaturedGraph ) = fg. graph
46
42
47
43
"""
48
44
node_feature(::AbstractFeaturedGraph)
49
45
50
46
Get node feature attached to graph.
51
47
"""
52
48
node_feature (:: NullGraph ) = nothing
53
- node_feature (fg:: FeaturedGraph ) = fg. nf[]
49
+ node_feature (fg:: FeaturedGraph ) = fg. nf
54
50
55
51
"""
56
52
edge_feature(::AbstractFeaturedGraph)
57
53
58
54
Get edge feature attached to graph.
59
55
"""
60
56
edge_feature (:: NullGraph ) = nothing
61
- edge_feature (fg:: FeaturedGraph ) = fg. ef[]
57
+ edge_feature (fg:: FeaturedGraph ) = fg. ef
62
58
63
59
"""
64
60
global_feature(::AbstractFeaturedGraph)
65
61
66
62
Get global feature attached to graph.
67
63
"""
68
64
global_feature (:: NullGraph ) = nothing
69
- global_feature (fg:: FeaturedGraph ) = fg. gf[]
65
+ global_feature (fg:: FeaturedGraph ) = fg. gf
70
66
71
67
has_graph (:: NullGraph ) = false
72
- has_graph (fg:: FeaturedGraph ) = fg. graph[] != zeros (0 ,0 )
68
+ has_graph (fg:: FeaturedGraph ) = fg. graph != zeros (0 ,0 )
73
69
74
70
has_node_feature (:: NullGraph ) = false
75
- has_node_feature (fg:: FeaturedGraph ) = fg. nf[] != zeros (0 ,0 )
71
+ has_node_feature (fg:: FeaturedGraph ) = fg. nf != zeros (0 ,0 )
76
72
77
73
has_edge_feature (:: NullGraph ) = false
78
- has_edge_feature (fg:: FeaturedGraph ) = fg. ef[] != zeros (0 ,0 )
74
+ has_edge_feature (fg:: FeaturedGraph ) = fg. ef != zeros (0 ,0 )
79
75
80
76
has_global_feature (:: NullGraph ) = false
81
- has_global_feature (fg:: FeaturedGraph ) = fg. gf[] != zeros (0 )
77
+ has_global_feature (fg:: FeaturedGraph ) = fg. gf != zeros (0 )
82
78
83
79
"""
84
80
adjacency_list(::AbstractFeaturedGraph)
85
81
86
82
Get adjacency list of graph.
87
83
"""
88
84
adjacency_list (:: NullGraph ) = [zeros (0 )]
89
- adjacency_list (fg:: FeaturedGraph ) = adjacency_list (fg. graph[] )
85
+ adjacency_list (fg:: FeaturedGraph ) = adjacency_list (fg. graph)
90
86
91
87
"""
92
88
nv(::AbstractFeaturedGraph)
93
89
94
90
Get node number of graph.
95
91
"""
96
92
nv (:: NullGraph ) = 0
97
- nv (fg:: FeaturedGraph ) = nv (fg. graph[] )
98
- nv (fg:: FeaturedGraph{T} ) where {T<: AbstractMatrix } = size (fg. graph[] , 1 )
99
- nv (fg:: FeaturedGraph{T} ) where {T<: AbstractVector } = length (fg. graph[] )
93
+ nv (fg:: FeaturedGraph ) = nv (fg. graph)
94
+ nv (fg:: FeaturedGraph{T} ) where {T<: AbstractMatrix } = size (fg. graph, 1 )
95
+ nv (fg:: FeaturedGraph{T} ) where {T<: AbstractVector } = length (fg. graph)
100
96
101
97
"""
102
98
ne(::AbstractFeaturedGraph)
103
99
104
100
Get edge number of graph.
105
101
"""
106
102
ne (:: NullGraph ) = 0
107
- ne (fg:: FeaturedGraph ) = ne (fg. graph[] )
108
- ne (fg:: FeaturedGraph{T} ) where {T<: AbstractVector } = sum (map (length, fg. graph[] ))÷ 2
103
+ ne (fg:: FeaturedGraph ) = ne (fg. graph)
104
+ ne (fg:: FeaturedGraph{T} ) where {T<: AbstractVector } = sum (map (length, fg. graph))÷ 2
109
105
110
106
111
107
112
108
# # Linear algebra API for AbstractFeaturedGraph
113
109
114
- adjacency_matrix (fg:: FeaturedGraph , T:: DataType = eltype (fg. graph[] )) = adjacency_matrix (fg. graph[] , T)
110
+ adjacency_matrix (fg:: FeaturedGraph , T:: DataType = eltype (fg. graph)) = adjacency_matrix (fg. graph, T)
115
111
116
- function degrees (fg:: FeaturedGraph , T:: DataType = eltype (fg. graph[] ); dir:: Symbol = :out )
117
- degrees (fg. graph[] , T; dir= dir)
112
+ function degrees (fg:: FeaturedGraph , T:: DataType = eltype (fg. graph); dir:: Symbol = :out )
113
+ degrees (fg. graph, T; dir= dir)
118
114
end
119
115
120
- function degree_matrix (fg:: FeaturedGraph , T:: DataType = eltype (fg. graph[] ); dir:: Symbol = :out )
121
- degree_matrix (fg. graph[] , T; dir= dir)
116
+ function degree_matrix (fg:: FeaturedGraph , T:: DataType = eltype (fg. graph); dir:: Symbol = :out )
117
+ degree_matrix (fg. graph, T; dir= dir)
122
118
end
123
119
124
- function inv_sqrt_degree_matrix (fg:: FeaturedGraph , T:: DataType = eltype (fg. graph[] ); dir:: Symbol = :out )
125
- inv_sqrt_degree_matrix (fg. graph[] , T; dir= dir)
120
+ function inv_sqrt_degree_matrix (fg:: FeaturedGraph , T:: DataType = eltype (fg. graph); dir:: Symbol = :out )
121
+ inv_sqrt_degree_matrix (fg. graph, T; dir= dir)
126
122
end
127
123
128
- function laplacian_matrix (fg:: FeaturedGraph , T:: DataType = eltype (fg. graph[] ); dir:: Symbol = :out )
129
- laplacian_matrix (fg. graph[] , T; dir= dir)
124
+ function laplacian_matrix (fg:: FeaturedGraph , T:: DataType = eltype (fg. graph); dir:: Symbol = :out )
125
+ laplacian_matrix (fg. graph, T; dir= dir)
130
126
end
131
127
132
- function normalized_laplacian (fg:: FeaturedGraph , T:: DataType = eltype (fg. graph[] ); selfloop:: Bool = false )
133
- normalized_laplacian (fg. graph[] , T; selfloop= selfloop)
128
+ function normalized_laplacian (fg:: FeaturedGraph , T:: DataType = eltype (fg. graph); selfloop:: Bool = false )
129
+ normalized_laplacian (fg. graph, T; selfloop= selfloop)
134
130
end
135
131
136
132
function scaled_laplacian (fg:: FeaturedGraph , T:: DataType = eltype (fg. graph[]))
137
- scaled_laplacian (fg. graph[] , T)
133
+ scaled_laplacian (fg. graph, T)
138
134
end
0 commit comments