Skip to content

Commit

Permalink
Merge pull request #1066 from anastasia21112/spaced-out-sparsity
Browse files Browse the repository at this point in the history
Plotting Spaced out Sparsity
  • Loading branch information
ChrisRackauckas authored Nov 30, 2024
2 parents 1f04bd9 + 1d4cf3c commit ccfef91
Showing 1 changed file with 52 additions and 15 deletions.
67 changes: 52 additions & 15 deletions benchmarks/LinearSolve/MatrixDepot.jmd
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ allmatrices_md = listnames("*/*")
@info "Total number of matrices: $(allmatrices_md.content[1].rows)"
times = fill(NaN, length(allmatrices_md.content[1].rows), length(algs))
percentage_sparsity = fill(NaN, length(allmatrices_md.content[1].rows))
spaced_out_sparsity = fill(NaN, length(allmatrices_md.content[1].rows))
matrix_size = fill(NaN, length(allmatrices_md.content[1].rows))
```

Expand All @@ -47,12 +48,37 @@ for z in 1:length(allmatrices_md.content[1].rows)
A = mdopen(currMTX).A
A = convert(SparseMatrixCSC, A)
n = size(A, 1)
matrix_size[z] = n
percentage_sparsity[z] = length(nonzeros(A)) / n^2
@info "$n × $n"


n > 500 && error("Skipping too large matrices")
mtx_copy = copy(A)

@info "$n × $n"
n > 100 && error("Skipping too large matrices")


rows, cols = size(mtx_copy)
new_rows = div(rows, 2)
new_cols = div(cols, 2)
condensed = zeros(Int, new_rows, new_cols)

while size(mtx_copy, 1) > 32 || size(mtx_copy, 2) > 32

rows, cols = size(mtx_copy)
new_rows = div(rows, 2)
new_cols = div(cols, 2)
condensed = sparse(zeros(Int, new_rows, new_cols))

for r in 1:2:rows-1
for c in 1:2:cols-1
block = mtx_copy[r:min(r+1, rows), c:min(c+1, cols)]
condensed[div(r-1, 2) + 1, div(c-1, 2) + 1] = (length(nonzeros(block)) >= 2) ? 1 : 0
end
end

mtx_copy = condensed

end

b = rand(rng, n)
u0 = rand(rng, n)

Expand All @@ -64,17 +90,9 @@ for z in 1:length(allmatrices_md.content[1].rows)
alias_b = true))
times[z,j] = bt
end

#=
p = bar(algnames, times[z, :];
ylabel = "Time/s",
yscale = :log10,
title = "Time on $(currMTX)",
fmt = :png,
legend = :outertopright)
display(p)
=#

matrix_size[z] = n
percentage_sparsity[z] = length(nonzeros(A)) / n^2
spaced_out_sparsity[z] = length(nonzeros(mtx_copy)) * percentage_sparsity[z]
println("successfully factorized $(currMTX)")
catch e
matrix = allmatrices_md.content[1].rows[z]
Expand All @@ -86,6 +104,13 @@ for z in 1:length(allmatrices_md.content[1].rows)
println(e)
end
end

percentage_sparsity = percentage_sparsity[.!isnan.(percentage_sparsity)]
spaced_out_sparsity = spaced_out_sparsity[.!isnan.(spaced_out_sparsity)]
spaced_out_sparsity = replace(spaced_out_sparsity, 0 => 1e-10)
matrix_size = matrix_size[.!isnan.(matrix_size)]
nanrows = any(isnan, times; dims=2)
times = times[.!vec(nanrows), :]
```

```julia
Expand Down Expand Up @@ -122,6 +147,18 @@ p = scatter(matrix_size, times;
legend = :outertopright)
```

```julia
p = scatter(spaced_out_sparsity, times;
ylabel = "Time/s",
yscale = :log10,
xlabel = "Spaced Out Sparsity",
xscale = :log10,
label = algnames_transpose,
title = "Factorization Time vs Spaced Out Sparsity",
fmt = :png,
legend = :outertopright)
```


## Appendix

Expand Down

0 comments on commit ccfef91

Please sign in to comment.