@@ -30,11 +30,35 @@ cols = [:red, :blue, :green, :magenta, :turqoise] # one color per alg
30
30
allmatrices_md = listnames("*/*")
31
31
32
32
@info "Total number of matrices: $(allmatrices_md.content[1].rows)"
33
+
33
34
times = fill(NaN, length(allmatrices_md.content[1].rows), length(algs))
34
35
percentage_sparsity = fill(NaN, length(allmatrices_md.content[1].rows))
35
36
spaced_out_sparsity = fill(NaN, length(allmatrices_md.content[1].rows))
36
37
matrix_size = fill(NaN, length(allmatrices_md.content[1].rows))
37
- bandedness = fill(NaN, length(allmatrices_md.content[1].rows))
38
+ bandedness_five = fill(NaN, length(allmatrices_md.content[1].rows))
39
+ bandedness_ten = fill(NaN, length(allmatrices_md.content[1].rows))
40
+ bandedness_twenty = fill(NaN, length(allmatrices_md.content[1].rows))
41
+
42
+ function compute_bandedness(A, bandwidth)
43
+ n = size(A, 1)
44
+ total_band_positions = 0
45
+ non_zero_in_band = 0
46
+ bandwidth = bandwidth
47
+ for r in 1:n
48
+ for c in 1:n
49
+ if abs(r - c) <= bandwidth
50
+ total_band_positions += 1 # This position belongs to the band
51
+ if A[r, c] != 0
52
+ non_zero_in_band += 1 # This element is non-zero in the band
53
+ end
54
+ end
55
+ end
56
+ end
57
+
58
+ percentage_filled = non_zero_in_band / total_band_positions * 100
59
+ return percentage_filled
60
+ end
61
+
38
62
```
39
63
40
64
```julia
@@ -50,18 +74,16 @@ for z in 1:length(allmatrices_md.content[1].rows)
50
74
A = convert(SparseMatrixCSC, A)
51
75
n = size(A, 1)
52
76
53
-
54
77
mtx_copy = copy(A)
55
78
56
79
@info "$n × $n"
57
80
n > 100 && error("Skipping too large matrices")
58
81
59
-
82
+ ## COMPUTING SPACED OUT SPARSITY
60
83
rows, cols = size(mtx_copy)
61
84
new_rows = div(rows, 2)
62
85
new_cols = div(cols, 2)
63
86
condensed = zeros(Int, new_rows, new_cols)
64
-
65
87
while size(mtx_copy, 1) > 32 || size(mtx_copy, 2) > 32
66
88
67
89
rows, cols = size(mtx_copy)
@@ -74,12 +96,11 @@ for z in 1:length(allmatrices_md.content[1].rows)
74
96
block = mtx_copy[r:min(r+1, rows), c:min(c+1, cols)]
75
97
condensed[div(r-1, 2) + 1, div(c-1, 2) + 1] = (length(nonzeros(block)) >= 2) ? 1 : 0
76
98
end
77
- end
78
-
79
- mtx_copy = condensed
80
-
99
+ end
100
+ mtx_copy = condensed
81
101
end
82
102
103
+ ## COMPUTING FACTORIZATION TIME
83
104
b = rand(rng, n)
84
105
u0 = rand(rng, n)
85
106
@@ -92,22 +113,13 @@ for z in 1:length(allmatrices_md.content[1].rows)
92
113
times[z,j] = bt
93
114
end
94
115
95
- total_band_positions = 0
96
- non_zero_in_band = 0
97
- bandwidth = 5
98
- for r in 1:n
99
- for c in 1:n
100
- if abs(r - c) <= bandwidth
101
- total_band_positions += 1 # This position belongs to the band
102
- if A[r, c] != 0
103
- non_zero_in_band += 1 # This element is non-zero in the band
104
- end
105
- end
106
- end
107
- end
116
+ bandedness_five[z] = compute_bandedness(A, 5)
117
+ bandedness_ten[z] = compute_bandedness(A, 10)
118
+ bandedness_twenty[z] = compute_bandedness(A, 20)
119
+ percentage_sparsity[z] = length(nonzeros(A)) / n^2
120
+ spaced_out_sparsity[z] = length(nonzeros(mtx_copy)) * percentage_sparsity[z]
121
+ matrix_size[z] = n
108
122
109
- percentage_filled = non_zero_in_band / total_band_positions * 100
110
- bandedness[z] = percentage_filled
111
123
#=
112
124
p = bar(algnames, times[z, :];
113
125
ylabel = "Time/s",
133
145
percentage_sparsity = percentage_sparsity[.!isnan.(percentage_sparsity)]
134
146
spaced_out_sparsity = spaced_out_sparsity[.!isnan.(spaced_out_sparsity)]
135
147
spaced_out_sparsity = replace(spaced_out_sparsity, 0 => 1e-10)
148
+ bandedness_five = bandedness_five[.!isnan.(bandedness_five)]
149
+ bandedness_five = replace(bandedness_five, 0 => 1e-10)
150
+ bandedness_ten = bandedness_ten[.!isnan.(bandedness_ten)]
151
+ bandedness_ten = replace(bandedness_ten, 0 => 1e-10)
152
+ bandedness_twenty = bandedness_twenty[.!isnan.(bandedness_twenty)]
153
+ bandedness_twenty = replace(bandedness_twenty, 0 => 1e-10)
136
154
matrix_size = matrix_size[.!isnan.(matrix_size)]
137
155
nanrows = any(isnan, times; dims=2)
138
156
times = times[.!vec(nanrows), :]
@@ -161,41 +179,62 @@ p = scatter(percentage_sparsity, times;
161
179
```
162
180
163
181
```julia
164
- p = scatter(bandedness , times;
182
+ p = scatter(matrix_size , times;
165
183
ylabel = "Time/s",
166
184
yscale = :log10,
167
- xlabel = "Bandedness ",
185
+ xlabel = "Matrix Size ",
168
186
xscale = :log10,
169
187
label = algnames_transpose,
170
- title = "Factorization Time vs Bandedness ",
188
+ title = "Factorization Time vs Matrix Size ",
171
189
fmt = :png,
172
190
legend = :outertopright)
173
191
```
174
192
175
193
```julia
176
- p = scatter(matrix_size , times;
194
+ p = scatter(spaced_out_sparsity , times;
177
195
ylabel = "Time/s",
178
196
yscale = :log10,
179
- xlabel = "Matrix Size ",
197
+ xlabel = "Spaced Out Sparsity ",
180
198
xscale = :log10,
181
199
label = algnames_transpose,
182
- title = "Factorization Time vs Matrix Size ",
200
+ title = "Factorization Time vs Spaced Out Sparsity ",
183
201
fmt = :png,
184
202
legend = :outertopright)
185
203
```
186
204
187
205
```julia
188
- p = scatter(spaced_out_sparsity , times;
206
+ p = scatter(bandedness_five , times;
189
207
ylabel = "Time/s",
190
208
yscale = :log10,
191
- xlabel = "Spaced Out Sparsity ",
209
+ xlabel = "Bandedness ",
192
210
xscale = :log10,
193
211
label = algnames_transpose,
194
- title = "Factorization Time vs Spaced Out Sparsity",
212
+ title = "Factorization Time vs Bandedness, Bandwidth=5",
213
+ fmt = :png,
214
+ legend = :outertopright)
215
+ ```
216
+ ```julia
217
+ p = scatter(bandedness_ten, times;
218
+ ylabel = "Time/s",
219
+ yscale = :log10,
220
+ xlabel = "Bandedness",
221
+ xscale = :log10,
222
+ label = algnames_transpose,
223
+ title = "Factorization Time vs Bandedness, Bandwidth=10",
224
+ fmt = :png,
225
+ legend = :outertopright)
226
+ ```
227
+ ```julia
228
+ p = scatter(bandedness_twenty, times;
229
+ ylabel = "Time/s",
230
+ yscale = :log10,
231
+ xlabel = "Bandedness",
232
+ xscale = :log10,
233
+ label = algnames_transpose,
234
+ title = "Factorization Time vs Bandedness, Bandwidth=20",
195
235
fmt = :png,
196
236
legend = :outertopright)
197
237
```
198
-
199
238
200
239
## Appendix
201
240
0 commit comments