You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/metagraph.jl
+96-48Lines changed: 96 additions & 48 deletions
Original file line number
Diff line number
Diff line change
@@ -16,12 +16,12 @@ Vertex labels have type `Label`, while vertex (resp. edge, resp. graph) metadata
16
16
It is recommended not to set `Label` to an integer type, so as to avoid confusion between vertex labels and vertex codes (which have type `Code<:Integer`).
17
17
18
18
# Fields
19
-
- `graph::Graph`: underlying, data-less graph with vertex indices of type `Code`
19
+
- `graph::Graph`: underlying, data-less graph with vertex codes of type `Code`
20
20
- `vertex_labels::Dict{Code,Label}`: dictionary mapping vertex codes to vertex labels
21
-
- `vertex_properties::Dict{Label,Tuple{Code,VertexData}}`: dictionary mapping vertex labels to vertex codes & data
22
-
- `edge_data::Dict{Tuple{Label,Label},EdgeData}`: dictionary mapping edge labels such as `(label_u, label_v)` to edge data
23
-
- `graph_data::GraphData`: global data for the graph object
24
-
- `weight_function::WeightFunction`: function computing edge weight from edge data, its output must have the same type as `default_weight`
Copy file name to clipboardExpand all lines: test/tutorial/1_basics.jl
+35-18Lines changed: 35 additions & 18 deletions
Original file line number
Diff line number
Diff line change
@@ -6,17 +6,31 @@ using Test #src
6
6
7
7
# ## Creating a `MetaGraph`
8
8
9
-
# We provide a default constructor which looks as follows:
9
+
# We provide a convenience constructor for creating empty graphs, which looks as follows:
10
10
11
11
colors =MetaGraph(
12
12
Graph(); # underlying graph structure
13
-
Label=Symbol, # color name
14
-
VertexData=NTuple{3,Int}, # RGB code
15
-
EdgeData=String, # result of the addition between two colors
13
+
label_type=Symbol, # color name
14
+
vertex_data_type=NTuple{3,Int}, # RGB code
15
+
edge_data_type=String, # result of the addition between two colors
16
16
graph_data="additive colors", # tag for the whole graph
17
17
)
18
18
19
-
# The `Label` type defines how vertices will be referred to, it can be anything but an integer type (to avoid confusion with codes, see below). The `VertexData` and `EdgeData` type determine what kind of data will be associated with each vertex and edge. Finally, `graph_data` can contain an arbitrary object associated with the graph as a whole.
19
+
# The `label_type` argument defines how vertices will be referred to, it can be anything but an integer type (to avoid confusion with codes, see below). The `vertex_data_type` and `edge_data_type` type determine what kind of data will be associated with each vertex and edge. Finally, `graph_data` can contain an arbitrary object associated with the graph as a whole.
20
+
21
+
# However, since this constructor receives types as keyword arguments, it is type-unstable. Casual users may not care, but if your goal is performance, you should use the following syntax instead, which relies on positional arguments.
# All kinds of metadata can be accessed with `getindex`:
64
78
65
79
colors[]
66
-
@test colors[] =="additive colors"#src
80
+
@test@inferredcolors[] =="additive colors"#src
67
81
#-
68
82
colors[:blue]
69
-
@test colors[:blue] == (0, 0, 255) #src
83
+
@test@inferredcolors[:blue] == (0, 0, 255) #src
70
84
#-
71
85
colors[:green, :blue]
72
-
@test colors[:green, :blue] =="cyan"#src
86
+
@test@inferredcolors[:green, :blue] =="cyan"#src
73
87
74
88
# ## Using vertex codes
75
89
76
90
# In the absence of removal, vertex codes correspond to order of insertion in the underlying graph. They are the ones used by most algorithms in the Graphs.jl ecosystem.
77
91
78
92
code_for(colors, :red)
79
-
@testcode_for(colors, :red) ==1#src
93
+
@test@inferredcode_for(colors, :red) ==1#src
80
94
#-
81
95
code_for(colors, :blue)
82
96
@testcode_for(colors, :blue) ==3#src
83
97
84
98
# You can retrieve the associated labels as follows:
85
99
86
100
label_for(colors, 1)
87
-
@testlabel_for(colors, 1) ==:red#src
101
+
@test@inferredlabel_for(colors, 1) ==:red#src
88
102
#-
89
103
label_for(colors, 3)
90
104
@testlabel_for(colors, 3) ==:blue#src
@@ -93,32 +107,35 @@ label_for(colors, 3)
93
107
94
108
# The most simple way to add edge weights is to speficy a default weight for all of them.
@test@inferredweighttype(weighted_default) == Int #src
103
117
104
118
# You can use the `weight_function` keyword to specify a function which will transform edge metadata into a weight. This weight must always be the same type as the `default_weight`.
0 commit comments