-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathstructured.jl
More file actions
75 lines (68 loc) · 2.19 KB
/
structured.jl
File metadata and controls
75 lines (68 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
using ArrayInterface: ArrayInterface
using BandedMatrices: BandedMatrix, brand
using BlockBandedMatrices: BandedBlockBandedMatrix, BlockBandedMatrix
using LinearAlgebra
using SparseArrays
using SparseMatrixColorings
using Test
@testset "Diagonal" begin
for n in (1, 2, 10, 100)
A = Diagonal(rand(n))
test_structured_coloring_decompression(A)
end
end;
@testset "Bidiagonal" begin
for n in (2, 10, 100)
A1 = Bidiagonal(rand(n), rand(n - 1), :U)
A2 = Bidiagonal(rand(n), rand(n - 1), :L)
test_structured_coloring_decompression(A1)
test_structured_coloring_decompression(A2)
end
end;
@testset "Tridiagonal" begin
for n in (2, 10, 100)
A = Tridiagonal(rand(n - 1), rand(n), rand(n - 1))
test_structured_coloring_decompression(A)
end
end;
@testset "BandedMatrices" begin
@testset for (m, n) in [(10, 20), (20, 10)], l in 0:5, u in 0:5
A = brand(m, n, l, u)
test_structured_coloring_decompression(A)
end
end;
@testset "BlockBandedMatrices" begin
for (mb, nb) in [(10, 20), (20, 10)], lb in 0:3, ub in 0:3, _ in 1:10
rows = rand(1:5, mb)
cols = rand(1:5, nb)
A = BlockBandedMatrix{Float64}(rand(sum(rows), sum(cols)), rows, cols, (lb, ub))
test_structured_coloring_decompression(A)
end
end;
@testset "BandedBlockBandedMatrices" begin
for (mb, nb) in [(10, 20), (20, 10)], lb in 0:3, ub in 0:3, _ in 1:10
rows = rand(5:10, mb)
cols = rand(5:10, nb)
λ = rand(0:5)
μ = rand(0:5)
A = BandedBlockBandedMatrix{Float64}(
rand(sum(rows), sum(cols)), rows, cols, (lb, ub), (λ, μ)
)
test_structured_coloring_decompression(A)
end
end;
# See https://github.com/JuliaDiff/SparseMatrixColorings.jl/pull/299
@testset "SparsityPatternCSC $T" for T in [Int, Float32]
S = sparse(T[
0 0 1 1 0 1
1 0 0 0 1 0
0 1 0 0 1 0
0 1 1 0 0 0
])
P = SparseMatrixColorings.SparsityPatternCSC(S)
problem = ColoringProblem()
algo = GreedyColoringAlgorithm()
result = coloring(P, problem, algo)
B = compress(S, result)
@test decompress(B, result) isa SparseMatrixCSC{T,Int}
end;