Skip to content

Commit 3469e7d

Browse files
committed
Document non-empty constructor and add docs to PR workflows
1 parent 1866101 commit 3469e7d

File tree

5 files changed

+47
-27
lines changed

5 files changed

+47
-27
lines changed

.github/workflows/permanent.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ on:
33
push:
44
branches:
55
- 'master'
6+
pull_request:
67
jobs:
78
document:
89
runs-on: ubuntu-latest

.github/workflows/test.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
name: test
22
on:
3-
- push
4-
- pull_request
3+
push:
4+
branches:
5+
- 'master'
6+
pull_request:
57
jobs:
68
test:
79
name: ${{ matrix.version }}

docs/make.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ makedocs(;
5858
),
5959
checkdocs=:all,
6060
linkcheck=true,
61+
strict=true,
6162
)
6263

6364
deploydocs(; repo="github.com/JuliaGraphs/MetaGraphsNext.jl.git")

src/metagraph.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ end
5656
default_weight=1.0
5757
)
5858
59-
Construct an empty `MetaGraph` based on an empty `graph`, initializing storage with the given metadata types *as positional arguments*.
59+
Construct an empty `MetaGraph` based on an empty `graph`, initializing storage with metadata types *given as positional arguments*.
6060
"""
6161
function MetaGraph(
6262
graph::AbstractGraph{Code},
@@ -96,7 +96,7 @@ end
9696
default_weight=1.0
9797
)
9898
99-
Construct an empty `MetaGraph` based on an empty `graph`, initializing storage with the given metadata types *as keyword arguments*.
99+
Construct an empty `MetaGraph` based on an empty `graph`, initializing storage with metadata types *given as keyword arguments*.
100100
101101
!!! warning "Warning"
102102
This constructor uses keyword arguments for convenience, which means it is type-unstable.
@@ -131,7 +131,7 @@ end
131131
default_weight=1.0,
132132
)
133133
134-
Construct a non-empty `MetaGraph` based on a non-empty `graph` with specified vertex and edge data.
134+
Construct a non-empty `MetaGraph` based on a non-empty `graph` with specified vertex and edge data, *given as positional arguments*.
135135
136136
The data must be given as follows:
137137
- `vertices_description` is a vector of pairs `label => data` (the code of a vertex will correspond to its rank in the list)

test/tutorial/1_basics.jl

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,53 +6,49 @@ using Test #src
66

77
# ## Creating a `MetaGraph`
88

9+
# ### Easiest constructor
10+
911
# We provide a convenience constructor for creating empty graphs, which looks as follows:
1012

1113
colors = MetaGraph(
1214
Graph(); # underlying graph structure
1315
label_type=Symbol, # color name
1416
vertex_data_type=NTuple{3,Int}, # RGB code
15-
edge_data_type=String, # result of the addition between two colors
17+
edge_data_type=Symbol, # result of the addition between two colors
1618
graph_data="additive colors", # tag for the whole graph
1719
)
1820

19-
@test_throws ErrorException @inferred MetaGraph( #src
20-
Graph(); #src
21-
label_type=Symbol, #src
22-
vertex_data_type=NTuple{3,Int}, #src
23-
edge_data_type=String, #src
24-
graph_data="additive colors", #src
25-
) #src
26-
2721
# 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.
2822

29-
# 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 either of the following alternatives:
30-
# 1. Wrap the constructor in a function
31-
# 2. Switch to positional arguments (be careful with the order!)
23+
# ### Type stability
24+
25+
# 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 might need one of the following alternatives: either wrap the constructor in a function...
3226

3327
function colors_constructor()
3428
return MetaGraph(
3529
Graph();
3630
label_type=Symbol,
3731
vertex_data_type=NTuple{3,Int},
38-
edge_data_type=String,
32+
edge_data_type=Symbol,
3933
graph_data="additive colors",
4034
)
4135
end
4236

37+
colors_constructor()
38+
4339
@test @inferred colors_constructor() == colors #src
4440

45-
#-
41+
# ... or switch to positional arguments (be careful with the order!)
4642

47-
colors_stable = MetaGraph(Graph(), Symbol, NTuple{3,Int}, String, "additive colors")
43+
MetaGraph(Graph(), Symbol, NTuple{3,Int}, Symbol, "additive colors")
4844

49-
@test @inferred MetaGraph( #src
45+
@test (@inferred MetaGraph( #src
5046
Graph(), #src
5147
Symbol, #src
5248
NTuple{3,Int}, #src
53-
String, #src
49+
Symbol, #src
5450
"additive colors", #src
55-
) == colors #src
51+
) == colors) #src
5652

5753
# ## Modifying the graph
5854

@@ -70,9 +66,29 @@ colors[:blue] = (0, 0, 255);
7066

7167
# Use `setindex!` with two keys to add a new edge between the given labels and containing the given metadata. Beware that this time, nonexistent labels will throw an error.
7268

73-
colors[:red, :green] = "yellow";
74-
colors[:red, :blue] = "magenta";
75-
colors[:green, :blue] = "cyan";
69+
colors[:red, :green] = :yellow;
70+
colors[:red, :blue] = :magenta;
71+
colors[:green, :blue] = :cyan;
72+
73+
# ### Creating a non-empty graph
74+
75+
# There is a final constructor we haven't mentioned, which allows you to build and fill the `MetaGraph` in one fell swoop. Here's how it works:
76+
77+
graph = Graph(Edge.([(1, 2), (1, 3), (2, 3)]))
78+
vertices_description = [:red => (255, 0, 0), :green => (0, 255, 0), :blue => (0, 0, 255)]
79+
edges_description = [
80+
(:red, :green) => :yellow, (:red, :blue) => :magenta, (:green, :blue) => :cyan
81+
]
82+
83+
colors2 = MetaGraph(graph, vertices_description, edges_description, "additive colors")
84+
colors2 == colors
85+
86+
@test (@inferred MetaGraph( #src
87+
graph, #src
88+
vertices_description, #src
89+
edges_description, #src
90+
"additive colors", #src
91+
) == colors) #src
7692

7793
# ## Accessing graph properties
7894

@@ -105,7 +121,7 @@ colors[:blue]
105121
@test @inferred colors[:blue] == (0, 0, 255) #src
106122
#-
107123
colors[:green, :blue]
108-
@test @inferred colors[:green, :blue] == "cyan" #src
124+
@test @inferred colors[:green, :blue] == :cyan #src
109125

110126
# ## Using vertex codes
111127

0 commit comments

Comments
 (0)