Skip to content

Commit 1e57882

Browse files
InterdisciplinaryPhysicsTeamClaudMorpitmonticone
committed
Clean docstrings
Co-Authored-By: Claudio Moroni <[email protected]> Co-Authored-By: Pietro Monticone <[email protected]>
1 parent 294c00e commit 1e57882

File tree

7 files changed

+31
-22
lines changed

7 files changed

+31
-22
lines changed

src/halfedge.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ weight(he::HalfEdge) = he.weight
3535
"""
3636
metadata(he::HalfEdge)
3737
38-
Return the metadata associated to the edge
38+
Return the metadata associated to the edge.
3939
"""
4040
metadata(he::HalfEdge) = he.metadata
4141

src/multilayeredge.jl

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,25 +97,24 @@ Return and edge between `dst(e)` and `src(e)` with same `weight(e)` and `metadat
9797
"""
9898
Base.reverse(e::MultilayerEdge) = MultilayerEdge(dst(e), src(e), weight(e), metadata(e))
9999

100-
"""
101-
compare_multilayeredges(lhs::MultilayerEdge, rhs::MultilayerEdge;check_weight::Bool = false, check_metadata::Bool = false)
102-
"""
100+
# Compare multilayer edges
103101
function compare_multilayeredges(lhs::MultilayerEdge, rhs::MultilayerEdge;check_weight::Bool = false, check_metadata::Bool = false)
102+
# Check source
104103
_check_src = lhs.src == rhs.src ? true : return false
104+
# check destination
105105
_check_dst = lhs.dst == rhs.dst ? true : return false
106-
106+
# Check weight
107107
_check_weight = false
108108
if check_weight
109109
_check_weight = lhs.weight == rhs.weight ? true : return false
110110
end
111-
111+
# Check metadata
112112
_check_metadata = false
113113
if check_metadata
114114
_check_metadata = lhs.metadata == rhs.metadata ? true : return false
115115
else
116116
_check_metadata = true
117117
end
118-
119118
return true
120119
end
121120

src/subgraphs/abstractsubgraph.jl

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Graphs.has_vertex(subgraph::S, v::T) where {T,S<:AbstractSubGraph{T}} = has_ver
3333
3434
Return the number of vertices in `subgraph`.
3535
"""
36-
Graphs.nv(subgraph::AbstractSubGraph) = nv(subgraph.graph) #length(vertices(subgraph))
36+
Graphs.nv(subgraph::AbstractSubGraph) = nv(subgraph.graph)
3737

3838
"""
3939
vertices(subgraph::AbstractSubGraph)
@@ -121,9 +121,11 @@ mv_neighbors(subgraph::AbstractSubGraph, mv::MultilayerVertex) = mv_outneighbors
121121
Return `v` associated with `V`.
122122
"""
123123
function get_v(subgraph::AbstractSubGraph, V::MultilayerVertex)
124+
# Convert V to a bare vertex
124125
bare_V = get_bare_mv(V)
126+
# Check if subgraph has this vertex
125127
has_vertex(subgraph, bare_V) || return nothing
126-
128+
# Get the list of edges
127129
subgraph.v_V_associations(bare_V)
128130
end
129131

@@ -134,10 +136,11 @@ end
134136
Return the `MultilayerVertex` whose internal representation is `v`.
135137
"""
136138
function get_V(subgraph::S, v::T; perform_checks::Bool = false) where {T,U, S <: AbstractSubGraph{T,U}}
139+
# Check if v is a vertex label in subgraph
137140
if perform_checks
138141
haskey(subgraph.v_V_associations,v) || throw(ErrorException("$v is not an integer label of any vertex in the subgraph"))
139142
end
140-
143+
# Return the vertex object
141144
return subgraph.v_V_associations[v]
142145
end
143146

@@ -150,11 +153,13 @@ end
150153
Return `V` together with its metadata.
151154
"""
152155
function get_rich_mv(subgraph::S, i::T; perform_checks::Bool = false) where {T,U, S <: AbstractSubGraph{T,U}}
156+
# Make sure that i is a valid vertex in the subgraph
153157
if perform_checks
154158
haskey(subgraph.v_V_associations,i) || throw(ErrorException("$i is not an integer label of any vertex in the subgraph"))
155159
end
156-
160+
# Get the bare vertex corresponding to i
157161
bare_V = subgraph.v_V_associations[i]
162+
# Return the vertex as a multilayer vertex
158163
return MV(bare_V.node, bare_V.layer, get_metadata(subgraph, bare_V))
159164
end
160165

@@ -171,7 +176,7 @@ end
171176
"""
172177
get_metadata(subgraph::AbstractSubGraph, bare_mv::MultilayerVertex)
173178
174-
Return the metadata of the vertex `bare_mv` in `subgraph` (metadata assigend to `bare_mv` will be discarded).
179+
Return the metadata of the vertex `bare_mv` in `subgraph` (metadata assigned to `bare_mv` will be discarded).
175180
"""
176181
get_metadata(subgraph::AbstractSubGraph, bare_mv::MultilayerVertex) =_get_vertex_metadata(subgraph.graph, get_v(subgraph, bare_mv))
177182

@@ -211,14 +216,12 @@ Return the number of edges in `subgraph`.
211216
"""
212217
Graphs.ne(subgraph::AbstractSubGraph) = ne(subgraph.graph)
213218

214-
215-
216219
"""
217220
edges(subgraph::S) where {T,U,S<:AbstractSubGraph{T,U}}
218221
219222
Return an iterator over all the edges of `subgraph`.
220223
"""
221-
function Graphs.edges(subgraph::S) where {T,U,S<:AbstractSubGraph{T,U}} # = subgraph.edge_list
224+
function Graphs.edges(subgraph::S) where {T,U,S<:AbstractSubGraph{T,U}}
222225
(
223226
MultilayerEdge(
224227
get_rich_mv(subgraph, src),
@@ -344,11 +347,14 @@ SimpleWeightedGraphs.weights(subgraph::S) where {T,U,S<:AbstractSubGraph{T,U}} =
344347
Overload equality for `AbstractSubGraph`s.
345348
"""
346349
function Base.:(==)(x::AbstractSubGraph, y::AbstractSubGraph)
350+
# Check that each field in AbstractSubGraph is equal in x and y
347351
for field in fieldnames(AbstractSubGraph)
352+
# If the field is not equal in x and y, return false
348353
if @eval $x.$field != $y.$field
349354
return false
350355
end
351356
end
357+
# If all fields are equal in x and y, return true
352358
return true
353359
end
354360

src/subgraphs/interlayerdescriptor.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,13 @@ end
4040
# Outer constructor that does not require name, edge_metadata_function and transfer_vertex_metadata
4141
InterlayerDescriptor(layer_1::Symbol, layer_2::Symbol, null_graph::G, weighttype::Type{U}; default_edge_weight::Function = (src, dst) -> nothing, default_edge_metadata::Function = (src, dst) -> NamedTuple(), transfer_vertex_metadata::Bool = false, name::Symbol = Symbol("interlayer_$(layer_1)_$(layer_2)") ) where {T,U, G <: AbstractGraph{T}}= InterlayerDescriptor(name, layer_1, layer_2, null_graph, default_edge_weight, default_edge_metadata, transfer_vertex_metadata, weighttype) # edge_weight_function::Function = (src,dst) -> one(U), edge_metadata_function::Function = (src,dst) -> NamedTuple(),
4242

43+
# This function is called whenever one tries to access a field of an object of type InterlayerDescriptor
4344
function Base.getproperty(descriptor::InterlayerDescriptor, f::Symbol)
44-
45+
# If the field is one of the ones listed below, return its value
4546
if f (:name, :layer_1, :layer_2, :null_graph, :transfer_vertex_metadata, :default_edge_metadata,:default_edge_weight )
4647
Base.getfield(descriptor, f)
48+
# Otherwise, if the field is layers_names, return the names of the two layers
4749
elseif f == :layers_names
4850
[descriptor.layer_1, descriptor.layer_2]
4951
end
50-
5152
end

src/vertices/abstractvertex.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""
22
abstract type AbstractVertex
33
4-
An abstract type for vertices that may not be represented by Integer and for which it may be inappropriate to use a graph with vertex-level metadata
4+
An abstract type for vertices that may not be represented by Integer and for which it may be inappropriate to use a graph with vertex-level metadata.
55
"""
66
abstract type AbstractVertex end

src/vertices/missingvertex.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""
22
MissingVertex
33
4-
A mutable struct that acts as a placeholder for a vertex that is missing in a Layer. It is mutable so that it may be added more than once to `Bijections` from Bijections.jl.s
4+
A mutable struct that acts as a placeholder for a vertex that is missing in a Layer. It is mutable so that it may be added more than once to the `Bijections` struct from Bijections.jl.
55
"""
66
mutable struct MissingVertex <: AbstractVertex end

src/vertices/multilayervertex.jl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
44
An abstract type representing an abstract MultilayerGraph vertex.
55
"""
6-
abstract type AbstractMultilayerVertex{S} <: AbstractVertex end #<: AbstractVertex{S} end
6+
abstract type AbstractMultilayerVertex{S} <: AbstractVertex end
77

88
"""
99
MultilayerVertex{N <: Integer} <: AbstractMultilayerVertex{N}
@@ -97,14 +97,17 @@ Return the metadata associated to `mv`.
9797
"""
9898
metadata(mv::MultilayerVertex) = mv.metadata
9999

100+
# Compare multilayer vertices
100101
function compare_multilayervertices(V1::MultilayerVertex, V2::MultilayerVertex; check_metadata = false)
102+
# Check if the two nodes are the same
101103
V1.node == V2.node || return false
104+
# Check if the two layers are the same
102105
V1.layer == V2.layer || return false
103-
106+
# Check if the two metadata are the same
104107
if check_metadata
105108
V1.metadata == V2.metadata || return false
106109
end
107-
110+
# Return true if all tests passed
108111
return true
109112
end
110113

0 commit comments

Comments
 (0)