Skip to content

Commit ea6bcfe

Browse files
aurorarossinatemagdallesimonschoelly
authored
Uniform code style (#190)
* Fix typos * Fix comment typo * Housekeeping * Add and remove spaces * Update src/dominatingset/minimal_dom_set.jl Co-authored-by: Emanuele Natale <[email protected]> * Apply JuliaFormatter and add it (+ Aqua) to testing * Fix formatting fail on Windows * Update src/SimpleGraphs/generators/randgraphs.jl Co-authored-by: Simon Schölly <[email protected]> * Fix contributing guidelines + add Blue style and formatting * Fix formatting bug in vf2.jl by ignoring function * Fix ignore vf2.jl for formatting on Windows Co-authored-by: Emanuele Natale <[email protected]> Co-authored-by: Guillaume Dalle <[email protected]> Co-authored-by: Simon Schölly <[email protected]>
1 parent 4fce15b commit ea6bcfe

File tree

219 files changed

+6005
-4278
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

219 files changed

+6005
-4278
lines changed

.JuliaFormatter.toml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
style = "blue"

CONTRIBUTING.md

+38-22
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,32 @@ Following these guidelines will reduce friction and improve the speed at which y
55

66
## Bug reports
77

8-
If you notice code that crashes, is incorrect, or is too slow, please file a bug report. The report should be raised as a github issue with a minimal working example that reproduces the condition.
8+
If you notice code that crashes, is incorrect, or is too slow, please file a bug report. The report should be raised as a GitHub issue with a minimal working example that reproduces the condition.
99
The example should include any data needed. If the problem is incorrectness, then please post the correct result along with an incorrect result.
1010

1111
Please include version numbers of all relevant libraries and Julia itself.
1212

1313
## Development guidelines
1414

15-
- Correctness is a necessary requirement; efficiency is desirable. Once you have a correct implementation, make a Pull Request (PR) so we can help improve performance.
16-
- PRs should contain one logical enhancement to the codebase.
17-
- Squash commits in a PR.
18-
- If you want to introduce a new feature, open an issue to discuss a feature before you start coding (this maximizes the likelihood of patch acceptance).
19-
- Minimize dependencies on external packages, and avoid introducing new dependencies that would increase the compilation time by a lot.
15+
Here are a few principles to keep in mind when writing a Pull Request (PR).
16+
17+
### Correctness
18+
19+
- Correctness is a necessary requirement. Add tests to make sure that any new function displays the right behavior.
20+
- Since Graphs.jl supports multiple implementations of the graph data structure using the `AbstractGraph` [type](https://juliagraphs.github.io/Graphs.jl/latest/types.html#AbstractGraph-Type-1), you should refrain from using the internal fields of structs such as `fadjlist`. Instead, you should use the functions provided in the API. Code that is instrumental to defining a concrete graph type can use the internal structure of that type.
2021
- Put type assertions on all function arguments where conflict may arise (use abstract types, `Union`, or `Any` if necessary).
21-
- If the algorithm was presented in a paper, include a reference to the paper (_e.g._, a proper academic citation along with an eprint link).
2222
- Take steps to ensure that code works correctly and efficiently on edge cases (disconnected graphs, empty graphs, ...).
2323
- We can accept code that does not work for directed graphs as long as it comes with an explanation of what it would take to make it work for directed graphs.
24-
- Prefer the short circuiting conditional over `if`/`else` when convenient, and where state is not explicitly being mutated (*e.g.*, `condition && error("message")` is good; `condition && i += 1` is not).
24+
25+
### Style
26+
27+
- Write your code using Invenia's [BlueStyle](https://github.com/invenia/BlueStyle)
28+
- Format it with [JuliaFormatter](https://github.com/domluna/JuliaFormatter.jl) before pushing
29+
30+
### Efficiency
31+
32+
- Once you have a correct implementation, make a PR so we can help improve performance.
33+
- Minimize dependencies on external packages, and avoid introducing new dependencies that would increase the compilation time by a lot.
2534
- Write code to reuse memory wherever possible. For example:
2635

2736
```julia
@@ -34,7 +43,9 @@ function f(g, v)
3443
return sum(storage)
3544
end
3645
```
46+
3747
should be rewritten as two functions
48+
3849
```julia
3950
function f(g::AbstractGraph, v::Integer)
4051
storage = Vector{Int}(undef, nv(g))
@@ -49,45 +60,50 @@ function f!(g::AbstractGraph, v::Integer, storage::AbstractVector{Int})
4960
return sum(storage)
5061
end
5162
```
63+
5264
This gives users the option of reusing memory and improving performance.
5365

54-
### Minimizing use of internal struct fields
66+
### Misc
5567

56-
Since Graphs supports multiple implementations of the graph data structure using the `AbstractGraph` [type](https://juliagraphs.github.io/Graphs.jl/latest/types.html#AbstractGraph-Type-1), you should refrain from using the internal fields of structs such as `fadjlist`. Instead, you should use the functions provided in the API.
57-
Code that is instrumental to defining a concrete graph type can use the internal structure of that type.
68+
- If the algorithm was presented in a paper, include a reference to the paper (_e.g._, a proper academic citation along with an eprint link).
5869

59-
## Git usage
70+
## Git(Hub) usage
6071

6172
### Getting started on a package contribution
6273

63-
In order to make it easier for you to contribute and review Pull Requests (PRs),
64-
it would be better to be familiar with git fundamentals.
65-
74+
In order to make it easier for you to contribute and review PRs, it would be better to be familiar with Git fundamentals.
6675
Most importantly:
76+
6777
- clone the repository from JuliaGraphs/Graphs.jl
68-
- fork the repository on your own github account
78+
- fork the repository on your own GitHub account
6979
- make the modification to the repository, test and document all your changes
7080
- push to the fork you created
7181
- open a PR.
7282

7383
See the [JuMP documentation](https://jump.dev/JuMP.jl/dev/developers/contributing/) for a more detailed guide.
7484

75-
### Advanced: visualize opened PRs locally:
85+
### PR hygiene
86+
87+
- PRs should contain one logical enhancement to the codebase.
88+
- Squash commits in a PR.
89+
- If you want to introduce a new feature, open an issue to discuss a feature before you start coding (this maximizes the likelihood of patch acceptance).
90+
91+
### Advanced: visualize opened PRs locally
7692

77-
In order to make it easier for you to review Pull Requests (PRs), you can add this to your git config file, which should be located at `PACKAGE_LOCATION/.git/config`, where `PACKAGE_LOCATION` is where the Graphs.jl was cloned.
93+
In order to make it easier for you to review PRs, you can add this to your git config file, which should be located at `PACKAGE_LOCATION/.git/config`, where `PACKAGE_LOCATION` is where the Graphs.jl was cloned.
7894
If you added the package with the `] dev` command, it is likely at `$HOME/.julia/dev/Graphs`.
7995

8096
These instructions were taken from [this gist](https://gist.github.com/piscisaureus/3342247).
8197

82-
Locate the section for your github remote in the `.git/config` file. It looks like this:
98+
Locate the section for your GitHub remote in the `.git/config` file. It looks like this:
8399

84100
```
85101
[remote "origin"]
86102
fetch = +refs/heads/*:refs/remotes/origin/*
87103
url = [email protected]:JuliaGraphs/Graphs.jl.git
88104
```
89105

90-
Now add the line `fetch = +refs/pull/*/head:refs/remotes/origin/pr/*` to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:
106+
Now add the line `fetch = +refs/pull/*/head:refs/remotes/origin/pr/*` to this section. Obviously, change the GitHub URL to match your project's URL. It ends up looking like this:
91107

92108
```
93109
[remote "origin"]
@@ -96,7 +112,7 @@ Now add the line `fetch = +refs/pull/*/head:refs/remotes/origin/pr/*` to this se
96112
fetch = +refs/pull/*/head:refs/remotes/origin/pr/*
97113
```
98114

99-
Now fetch all the pull requests:
115+
Now fetch all the PRs:
100116

101117
```
102118
$ git fetch origin
@@ -108,7 +124,7 @@ From github.com:JuliaGraphs/Graphs.jl
108124
...
109125
```
110126

111-
To check out a particular pull request:
127+
To check out a particular PR:
112128

113129
```
114130
$ git checkout pr/999

Project.toml

+8-1
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,25 @@ SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
1616
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
1717

1818
[compat]
19+
Aqua = "0.5"
1920
ArnoldiMethod = "0.1, 0.2"
2021
Compat = "3.40, 4"
2122
DataStructures = "0.17, 0.18"
23+
Documenter = "0.27"
2224
Inflate = "0.1.3"
25+
JuliaFormatter = "1"
2326
SimpleTraits = "0.9"
27+
StableRNGs = "1"
2428
julia = "1.6"
2529

2630
[extras]
31+
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
2732
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
2833
DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab"
34+
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
35+
JuliaFormatter = "98e50ef6-434e-11e9-1051-2b60c6c9e899"
2936
StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"
3037
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
3138

3239
[targets]
33-
test = ["Base64", "DelimitedFiles", "StableRNGs", "Test"]
40+
test = ["Aqua", "Base64", "DelimitedFiles", "Documenter", "JuliaFormatter", "StableRNGs", "Test"]

README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Graphs.jl
22

3-
[![Build Status](https://github.com/JuliaGraphs/Graphs.jl/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/JuliaGraphs/Graphs.jl/actions/workflows/ci.yml?query=branch%3Amaster) [![codecov.io](http://codecov.io/github/JuliaGraphs/Graphs.jl/coverage.svg?branch=master)](http://codecov.io/github/JuliaGraphs/Graphs.jl?branch=master) [![](https://img.shields.io/badge/docs-latest-blue.svg)](https://juliagraphs.org/Graphs.jl/dev/)
3+
[![Documentation](https://img.shields.io/badge/docs-latest-blue.svg)](https://juliagraphs.org/Graphs.jl/dev/)
4+
[![Build status](https://github.com/JuliaGraphs/Graphs.jl/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/JuliaGraphs/Graphs.jl/actions/workflows/ci.yml?query=branch%3Amaster)
5+
[![Code coverage](http://codecov.io/github/JuliaGraphs/Graphs.jl/coverage.svg?branch=master)](http://codecov.io/github/JuliaGraphs/Graphs.jl?branch=master)
6+
[![Code style: Blue](https://img.shields.io/badge/code%20style-blue-4495d1.svg)](https://github.com/invenia/BlueStyle)
47

58
## Overview
69

benchmark/benchmarks.jl

+5-9
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
11
using BenchmarkTools
22
using Graphs
33

4-
54
DIGRAPHS = Dict{String,DiGraph}(
6-
"complete100" => complete_digraph(100),
7-
"path500" => path_digraph(500)
5+
"complete100" => complete_digraph(100), "path500" => path_digraph(500)
86
)
97

108
GRAPHS = Dict{String,Graph}(
11-
"complete100" => complete_graph(100),
12-
"tutte" => smallgraph(:tutte),
13-
"path500" => path_graph(500)
9+
"complete100" => complete_graph(100),
10+
"tutte" => smallgraph(:tutte),
11+
"path500" => path_graph(500),
1412
)
1513

16-
1714
suite = BenchmarkGroup()
1815
include("core.jl")
1916

20-
2117
tune!(suite);
22-
results = run(suite, verbose = true, seconds = 10)
18+
results = run(suite; verbose=true, seconds=10)

benchmark/centrality.jl

+23-23
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11

22
@benchgroup "centrality" begin
3-
@benchgroup "graphs" begin
4-
for (name, g) in GRAPHS
5-
@bench "$(name): degree" Graphs.degree_centrality($g)
6-
@bench "$(name): closeness" Graphs.closeness_centrality($g)
7-
if nv(g) < 1000
8-
@bench "$(name): betweenness" Graphs.betweenness_centrality($g)
9-
@bench "$(name): katz" Graphs.katz_centrality($g)
10-
end
11-
end
12-
end #graphs
13-
@benchgroup "digraphs" begin
14-
for (name, g) in DIGRAPHS
15-
@bench "$(name): degree" Graphs.degree_centrality($g)
16-
@bench "$(name): closeness" Graphs.closeness_centrality($g)
17-
if nv(g) < 1000
18-
@bench "$(name): betweenness" Graphs.betweenness_centrality($g)
19-
@bench "$(name): katz" Graphs.katz_centrality($g)
20-
end
21-
if nv(g) < 500
22-
@bench "$(name): pagerank" Graphs.pagerank($g)
23-
end
24-
end
25-
end # digraphs
3+
@benchgroup "graphs" begin
4+
for (name, g) in GRAPHS
5+
@bench "$(name): degree" Graphs.degree_centrality($g)
6+
@bench "$(name): closeness" Graphs.closeness_centrality($g)
7+
if nv(g) < 1000
8+
@bench "$(name): betweenness" Graphs.betweenness_centrality($g)
9+
@bench "$(name): katz" Graphs.katz_centrality($g)
10+
end
11+
end
12+
end # graphs
13+
@benchgroup "digraphs" begin
14+
for (name, g) in DIGRAPHS
15+
@bench "$(name): degree" Graphs.degree_centrality($g)
16+
@bench "$(name): closeness" Graphs.closeness_centrality($g)
17+
if nv(g) < 1000
18+
@bench "$(name): betweenness" Graphs.betweenness_centrality($g)
19+
@bench "$(name): katz" Graphs.katz_centrality($g)
20+
end
21+
if nv(g) < 500
22+
@bench "$(name): pagerank" Graphs.pagerank($g)
23+
end
24+
end
25+
end # digraphs
2626
end # centrality

benchmark/connectivity.jl

+12-10
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
@benchgroup "connectivity" begin
2-
@benchgroup "digraphs" begin
3-
for (name, g) in DIGRAPHS
4-
@bench "$(name): strongly_connected_components" Graphs.strongly_connected_components($g)
5-
end
6-
end # digraphs
7-
@benchgroup "graphs" begin
8-
for (name, g) in GRAPHS
9-
@bench "$(name): connected_components" Graphs.connected_components($g)
10-
end
11-
end # graphs
2+
@benchgroup "digraphs" begin
3+
for (name, g) in DIGRAPHS
4+
@bench "$(name): strongly_connected_components" Graphs.strongly_connected_components(
5+
$g
6+
)
7+
end
8+
end # digraphs
9+
@benchgroup "graphs" begin
10+
for (name, g) in GRAPHS
11+
@bench "$(name): connected_components" Graphs.connected_components($g)
12+
end
13+
end # graphs
1214
end # connectivity

benchmark/core.jl

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
suite["core"] = BenchmarkGroup(["nv", "edges", "has_edge"])
22

3-
43
# nv
54
suite["core"]["nv"] = BenchmarkGroup(["graphs", "digraphs"])
6-
suite["core"]["nv"]["graphs"] = @benchmarkable [nv(g) for (n,g) in $GRAPHS]
7-
suite["core"]["nv"]["digraphs"] = @benchmarkable [nv(g) for (n,g) in $DIGRAPHS]
5+
suite["core"]["nv"]["graphs"] = @benchmarkable [nv(g) for (n, g) in $GRAPHS]
6+
suite["core"]["nv"]["digraphs"] = @benchmarkable [nv(g) for (n, g) in $DIGRAPHS]
87

98
# iterate edges
109
function iter_edges(g::AbstractGraph)
@@ -16,8 +15,8 @@ function iter_edges(g::AbstractGraph)
1615
end
1716

1817
suite["core"]["edges"] = BenchmarkGroup(["graphs", "digraphs"])
19-
suite["core"]["edges"]["graphs"] = @benchmarkable [iter_edges(g) for (n,g) in $GRAPHS]
20-
suite["core"]["edges"]["digraphs"] = @benchmarkable [iter_edges(g) for (n,g) in $DIGRAPHS]
18+
suite["core"]["edges"]["graphs"] = @benchmarkable [iter_edges(g) for (n, g) in $GRAPHS]
19+
suite["core"]["edges"]["digraphs"] = @benchmarkable [iter_edges(g) for (n, g) in $DIGRAPHS]
2120

2221
# has edge
2322
function all_has_edge(g::AbstractGraph)
@@ -34,5 +33,5 @@ function all_has_edge(g::AbstractGraph)
3433
end
3534

3635
suite["core"]["has_edge"] = BenchmarkGroup(["graphs", "digraphs"])
37-
suite["core"]["has_edge"]["graphs"] = @benchmark [all_has_edge(g) for (n,g) in $GRAPHS]
38-
suite["core"]["has_edge"]["digraphs"] = @benchmark [all_has_edge(g) for (n,g) in $DIGRAPHS]
36+
suite["core"]["has_edge"]["graphs"] = @benchmark [all_has_edge(g) for (n, g) in $GRAPHS]
37+
suite["core"]["has_edge"]["digraphs"] = @benchmark [all_has_edge(g) for (n, g) in $DIGRAPHS]

benchmark/edges.jl

+5-5
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ end
3232

3333
n = 10000
3434
@benchgroup "edges" begin
35-
@bench "$(n): fille" fille($n)
36-
@bench "$(n): fillp" fillp($n)
37-
a, b = fille(n), fillp(n)
38-
@bench "$(n): tsume" tsum($a)
39-
@bench "$(n): tsump" tsum($b)
35+
@bench "$(n): fille" fille($n)
36+
@bench "$(n): fillp" fillp($n)
37+
a, b = fille(n), fillp(n)
38+
@bench "$(n): tsume" tsum($a)
39+
@bench "$(n): tsump" tsum($b)
4040
end # edges

benchmark/insertions.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
@benchgroup "insertions" begin
2-
n = 10000
3-
@bench "ER Generation" g = SimpleGraph($n, 16 * $n)
2+
n = 10000
3+
@bench "ER Generation" g = SimpleGraph($n, 16 * $n)
44
end

benchmark/parallel/egonets.jl

+2-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ using BenchmarkTools
2222
return a
2323
end
2424

25-
2625
function mapvertices(f, g::Graph)
2726
n = nv(g)
2827
a = zeros(Int, n)
@@ -43,13 +42,13 @@ using BenchmarkTools
4342

4443
function comparison(f, g)
4544
println("Mulithreaded on $(Threads.nthreads())")
46-
b1 = @benchmark mapvertices($f, $g)
45+
b1 = @benchmark mapvertices($f, $g)
4746
println(b1)
4847

4948
println("singlethreaded")
5049
b2 = @benchmark mapvertices_single($f, $g)
5150
println(b2)
52-
println("done")
51+
return println("done")
5352
end
5453

5554
nv_ = 10000

benchmark/traversals.jl

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
@benchgroup "traversals" begin
2-
@benchgroup "graphs" begin
3-
for (name, g) in GRAPHS
4-
@bench "$(name): bfs_tree" Graphs.bfs_tree($g, 1)
5-
@bench "$(name): dfs_tree" Graphs.dfs_tree($g, 1)
6-
end
7-
end # graphs
8-
@benchgroup "digraphs" begin
9-
for (name, g) in DIGRAPHS
10-
@bench "$(name): bfs_tree" Graphs.bfs_tree($g, 1)
11-
@bench "$(name): dfs_tree" Graphs.dfs_tree($g, 1)
12-
end
13-
end # digraphs
2+
@benchgroup "graphs" begin
3+
for (name, g) in GRAPHS
4+
@bench "$(name): bfs_tree" Graphs.bfs_tree($g, 1)
5+
@bench "$(name): dfs_tree" Graphs.dfs_tree($g, 1)
6+
end
7+
end # graphs
8+
@benchgroup "digraphs" begin
9+
for (name, g) in DIGRAPHS
10+
@bench "$(name): bfs_tree" Graphs.bfs_tree($g, 1)
11+
@bench "$(name): dfs_tree" Graphs.dfs_tree($g, 1)
12+
end
13+
end # digraphs
1414
end # traversals

0 commit comments

Comments
 (0)