Skip to content

Commit 580cc45

Browse files
gdalleamontoison
authored andcommitted
Rename and fix nb edges
1 parent 09dbd7f commit 580cc45

3 files changed

Lines changed: 30 additions & 30 deletions

File tree

docs/src/dev.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ The docstrings on this page describe internals, they are not part of the public
1010
## Graph storage
1111

1212
```@docs
13-
SparseMatrixColorings.SparsePatternCSC
14-
transpose
13+
SparseMatrixColorings.SparsityPatternCSC
1514
SparseMatrixColorings.AdjacencyGraph
1615
SparseMatrixColorings.BipartiteGraph
1716
SparseMatrixColorings.vertices
1817
SparseMatrixColorings.neighbors
18+
transpose
1919
```
2020

2121
## Low-level coloring

src/graph.jl

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
## Standard graph
22

33
"""
4-
SparsePatternCSC{Ti<:Integer}
4+
SparsityPatternCSC{Ti<:Integer}
55
66
Store a sparse matrix (in CSC) without its values, keeping only the pattern of nonzeros.
77
@@ -14,26 +14,26 @@ Copied from `SparseMatrixCSC`:
1414
- `colptr::Vector{Ti}`: column `j` is in `colptr[j]:(colptr[j+1]-1)`
1515
- `rowval::Vector{Ti}`: row indices of stored values
1616
"""
17-
struct SparsePatternCSC{Ti<:Integer}
17+
struct SparsityPatternCSC{Ti<:Integer}
1818
m::Int
1919
n::Int
2020
colptr::Vector{Ti}
2121
rowval::Vector{Ti}
2222
end
2323

24-
SparsePatternCSC(A::SparseMatrixCSC) = SparsePatternCSC(A.m, A.n, A.colptr, A.rowval)
24+
SparsityPatternCSC(A::SparseMatrixCSC) = SparsityPatternCSC(A.m, A.n, A.colptr, A.rowval)
2525

26-
Base.size(S::SparsePatternCSC) = (S.m, S.n)
27-
SparseArrays.nnz(S::SparsePatternCSC) = length(S.rowval)
28-
SparseArrays.rowvals(S::SparsePatternCSC) = S.rowval
29-
SparseArrays.nzrange(S::SparsePatternCSC, j::Integer) = S.colptr[j]:(S.colptr[j + 1] - 1)
26+
Base.size(S::SparsityPatternCSC) = (S.m, S.n)
27+
SparseArrays.nnz(S::SparsityPatternCSC) = length(S.rowval)
28+
SparseArrays.rowvals(S::SparsityPatternCSC) = S.rowval
29+
SparseArrays.nzrange(S::SparsityPatternCSC, j::Integer) = S.colptr[j]:(S.colptr[j + 1] - 1)
3030

3131
"""
32-
transpose(S::SparsePatternCSC)
32+
transpose(S::SparsityPatternCSC)
3333
34-
Return a [`SparsePatternCSC`](@ref) corresponding to the transpose of `S`.
34+
Return a [`SparsityPatternCSC`](@ref) corresponding to the transpose of `S`.
3535
"""
36-
function Base.transpose(S::SparsePatternCSC{T}) where {T}
36+
function Base.transpose(S::SparsityPatternCSC{T}) where {T}
3737
m, n = size(S)
3838
nnzA = nnz(S)
3939
A_colptr = S.colptr
@@ -78,7 +78,7 @@ function Base.transpose(S::SparsePatternCSC{T}) where {T}
7878
end
7979
B_colptr[1] = 1
8080

81-
return SparsePatternCSC{T}(n, m, B_colptr, B_rowval)
81+
return SparsityPatternCSC{T}(n, m, B_colptr, B_rowval)
8282
end
8383

8484
## Adjacency graph
@@ -99,17 +99,17 @@ The adjacency graph of a symmetrix matric `A ∈ ℝ^{n × n}` is `G(A) = (V, E)
9999
100100
# Fields
101101
102-
- `S::SparsePatternCSC{T}`
102+
- `S::SparsityPatternCSC{T}`
103103
104104
# References
105105
106-
> [_What Color Is Your Jacobian? SparsePatternCSC Coloring for Computing Derivatives_](https://epubs.siam.org/doi/10.1137/S0036144504444711), Gebremedhin et al. (2005)
106+
> [_What Color Is Your Jacobian? SparsityPatternCSC Coloring for Computing Derivatives_](https://epubs.siam.org/doi/10.1137/S0036144504444711), Gebremedhin et al. (2005)
107107
"""
108108
struct AdjacencyGraph{T}
109-
S::SparsePatternCSC{T}
109+
S::SparsityPatternCSC{T}
110110
end
111111

112-
AdjacencyGraph(A::SparseMatrixCSC) = AdjacencyGraph(SparsePatternCSC(A))
112+
AdjacencyGraph(A::SparseMatrixCSC) = AdjacencyGraph(SparsityPatternCSC(A))
113113

114114
pattern(g::AdjacencyGraph) = g.S
115115
nb_vertices(g::AdjacencyGraph) = pattern(g).n
@@ -137,12 +137,12 @@ function nb_edges(g::AdjacencyGraph)
137137
for j in vertices(g)
138138
for k in nzrange(S, j)
139139
i = rowvals(S)[k]
140-
if i != j
140+
if i > j
141141
ne += 1
142142
end
143143
end
144144
end
145-
return ne ÷ 2
145+
return ne
146146
end
147147

148148
maximum_degree(g::AdjacencyGraph) = maximum(Base.Fix1(degree, g), vertices(g))
@@ -171,20 +171,20 @@ When `symmetric_pattern` is `true`, this construction is more efficient.
171171
172172
# Fields
173173
174-
- `S1::SparsePatternCSC{T}`: maps vertices on side `1` to their neighbors
175-
- `S2::SparsePatternCSC{T}`: maps vertices on side `2` to their neighbors
174+
- `S1::SparsityPatternCSC{T}`: maps vertices on side `1` to their neighbors
175+
- `S2::SparsityPatternCSC{T}`: maps vertices on side `2` to their neighbors
176176
177177
# References
178178
179-
> [_What Color Is Your Jacobian? SparsePatternCSC Coloring for Computing Derivatives_](https://epubs.siam.org/doi/10.1137/S0036144504444711), Gebremedhin et al. (2005)
179+
> [_What Color Is Your Jacobian? SparsityPatternCSC Coloring for Computing Derivatives_](https://epubs.siam.org/doi/10.1137/S0036144504444711), Gebremedhin et al. (2005)
180180
"""
181181
struct BipartiteGraph{T<:Integer}
182-
S1::SparsePatternCSC{T}
183-
S2::SparsePatternCSC{T}
182+
S1::SparsityPatternCSC{T}
183+
S2::SparsityPatternCSC{T}
184184
end
185185

186186
function BipartiteGraph(A::SparseMatrixCSC; symmetric_pattern::Bool=false)
187-
S2 = SparsePatternCSC(A) # columns to rows
187+
S2 = SparsityPatternCSC(A) # columns to rows
188188
if symmetric_pattern
189189
checksquare(A) # proxy for checking full symmetry
190190
S1 = S2

test/graph.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using LinearAlgebra
22
using SparseArrays
33
using SparseMatrixColorings:
4-
SparsePatternCSC,
4+
SparsityPatternCSC,
55
AdjacencyGraph,
66
BipartiteGraph,
77
degree,
@@ -11,15 +11,15 @@ using SparseMatrixColorings:
1111
neighbors
1212
using Test
1313

14-
## SparsePatternCSC
14+
## SparsityPatternCSC
1515

16-
@testset "SparsePatternCSC" begin
16+
@testset "SparsityPatternCSC" begin
1717
@testset "Transpose" begin
1818
for _ in 1:1000
1919
A = sprand(rand(100:1000), rand(100:1000), 0.1)
20-
S = SparsePatternCSC(A)
20+
S = SparsityPatternCSC(A)
2121
Sᵀ = transpose(S)
22-
Sᵀ_true = SparsePatternCSC(sparse(transpose(A)))
22+
Sᵀ_true = SparsityPatternCSC(sparse(transpose(A)))
2323
@test Sᵀ.colptr == Sᵀ_true.colptr
2424
@test Sᵀ.rowval == Sᵀ_true.rowval
2525
end

0 commit comments

Comments
 (0)