Skip to content

Commit 177af13

Browse files
committed
Faster depermutation in simplicial selinv
Previous depermutation was unbearably slow. New approach is much faster, at the cost of a bit more memory.
1 parent 29802a5 commit 177af13

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "SelectedInversion"
22
uuid = "043bf095-3f01-458a-9f1c-8cf4448fe908"
33
authors = ["Tim Weiland <[email protected]> and contributors"]
4-
version = "0.1.3"
4+
version = "0.1.4"
55

66
[deps]
77
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

src/selinv_simplicial.jl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,16 @@ function selinv_simplicial(F::SparseArrays.CHOLMOD.Factor; depermute = false)
4848

4949
p = F.p
5050
if depermute
51-
return (Z = Symmetric(Z, :L)[invperm(p), invperm(p)], p = p)
51+
# Symmetric(Z)[invperm(p), invperm(p)], but much faster
52+
# ... at the cost of more memory
53+
rows, cols, vals = findnz(sparse(Symmetric(Z)))
54+
p_rows, p_cols = p[rows], p[cols]
55+
new_rows = [p_rows; p_cols]
56+
new_cols = [p_cols; p_rows]
57+
new_vals = [vals; vals]
58+
n = size(Z, 1)
59+
Z = sparse(new_rows, new_cols, new_vals, n, n, (x, y) -> x)
60+
return (Z = Z, p = p)
5261
else
5362
return (Z = Symmetric(Z, :L), p = p)
5463
end

0 commit comments

Comments
 (0)