Skip to content

Commit 3b2f4c9

Browse files
committed
AMD Ext, JL 1.10, depr Ccolamd, wip tests
1 parent 4bf5d1a commit 3b2f4c9

File tree

7 files changed

+120
-9
lines changed

7 files changed

+120
-9
lines changed

Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,15 @@ TimeZones = "f269a46b-ccf7-5d73-abea-4c690281aa53"
4949
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
5050

5151
[weakdeps]
52+
AMD = "14f7f29c-3bd6-536c-9a0b-7339e30b5a3e"
5253
DifferentialEquations = "0c46a032-eb83-5123-abaf-570d42b7fbaa"
5354
Flux = "587475ba-b771-5e3f-ad9e-33799f191a9c"
5455
Gadfly = "c91e804a-d5a3-530f-b6f0-dfbca275c004"
5556
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
5657
Interpolations = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59"
5758

5859
[extensions]
60+
IncrInfrApproxMinDegreeExt = "AMD"
5961
IncrInfrDiffEqFactorExt = "DifferentialEquations"
6062
IncrInfrFluxFactorsExt = "Flux"
6163
IncrInfrGadflyExt = "Gadfly"
File renamed without changes.

ext/IncrInfrApproxMinDegreeExt.jl

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
module IncrInfrApproxMinDegreeExt
2+
3+
using AMD
4+
import IncrementalInference: _ccolamd, _ccolamd!
5+
6+
# elseif ordering == :ccolamd
7+
# cons = zeros(SuiteSparse_long, length(adjMat.colptr) - 1)
8+
# cons[findall(x -> x in constraints, permuteds)] .= 1
9+
# p = Ccolamd.ccolamd(adjMat, cons)
10+
# @warn "Ccolamd is experimental in IIF at this point in time."
11+
12+
const KNOBS = 20
13+
const STATS = 20
14+
15+
16+
17+
function _ccolamd!(
18+
n_row, #SuiteSparse_long,
19+
A::AbstractVector{T}, # SuiteSparse_long},
20+
p::AbstractVector, # SuiteSparse_long},
21+
knobs::Union{Ptr{Nothing}, Vector{Float64}},
22+
stats::AbstractVector, #{SuiteSparse_long},
23+
cmember::Union{Ptr{Nothing}, <:AbstractVector}, #{SuiteSparse_long}},
24+
) where T
25+
n_col = length(p) - 1
26+
27+
if length(stats) != STATS
28+
error("stats must hcae length $STATS")
29+
end
30+
if isa(cmember, Vector) && length(cmember) != n_col
31+
error("cmember must have length $n_col")
32+
end
33+
34+
Alen = AMD.recommended(length(A), n_row, n_col)
35+
resize!(A, Alen)
36+
37+
for i in eachindex(A)
38+
A[i] -= 1
39+
end
40+
for i in eachindex(p)
41+
p[i] -= 1
42+
end
43+
err = AMD.ccolamd( # ccolamd_l
44+
n_row,
45+
n_col,
46+
Alen,
47+
A,
48+
p,
49+
knobs,
50+
stats,
51+
cmember
52+
)
53+
54+
if err == 0
55+
AMD.report(stats)
56+
error("call to ccolamd return with error code $(stats[4])")
57+
end
58+
59+
for i in eachindex(p)
60+
p[i] += 1
61+
end
62+
63+
pop!(p) # remove last zero from pivoting vector
64+
return p
65+
end
66+
67+
function ccolamd!(
68+
n_row,
69+
A::AbstractVector{T}, #SuiteSparse_long},
70+
p::AbstractVector, # {SuiteSparse_long},
71+
cmember::Union{Ptr{Nothing}, <:AbstractVector{T}}, # SuiteSparse_long
72+
) where T
73+
n_col = length(p) - 1
74+
75+
if length(cmember) != n_col
76+
error("cmember must have length $n_col")
77+
end
78+
79+
Alen = AMD.recommended(length(A), n_row, n_col)
80+
resize!(A, Alen)
81+
stats = zeros(T, STATS)
82+
return _ccolamd!(n_row, A, p, C_NULL, stats, cmember)
83+
end
84+
85+
function _ccolamd!(
86+
n_row,
87+
A::AbstractVector{T}, # ::Vector{SuiteSparse_long},
88+
p::AbstractVector, # ::Vector{SuiteSparse_long},
89+
constraints = zeros(T,length(p) - 1), # SuiteSparse_long,
90+
) where T
91+
n_col = length(p) - 1
92+
return _ccolamd!(n_row, A, p, constraints)
93+
end
94+
95+
_ccolamd(n_row,A,p,constraints) = _ccolamd!(n_row, copy(A), copy(p), constraints)
96+
_ccolamd(badjMat, constraints) = _ccolamd(size(badjMat, 1), A.rowval, A.colptr, constraints)
97+
98+
99+
100+
end

ext/WeakDepsPrototypes.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11

2+
# AMD.jl
3+
function _ccolamd! end
4+
function _ccolamd end
5+
26
# Flux.jl
37
function MixtureFluxModels end
48

src/IncrementalInference.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,11 @@ using MetaGraphs
5656
using Logging
5757
using PrecompileTools
5858

59-
# bringing in BSD 3-clause ccolamd
60-
include("services/ccolamd.jl")
61-
using SuiteSparse.CHOLMOD: SuiteSparse_long # For CCOLAMD constraints.
62-
using .Ccolamd
59+
# JL 1.10 transition to IncrInfrApproxMinDegreeExt instead
60+
# # bringing in BSD 3-clause ccolamd
61+
# include("services/ccolamd.jl")
62+
# using SuiteSparse.CHOLMOD: SuiteSparse_long # For CCOLAMD constraints.
63+
# using .Ccolamd
6364

6465
# likely overloads or not exported by the upstream packages
6566
import Base: convert, ==, getproperty

src/services/BayesNet.jl

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,13 @@ function getEliminationOrder(
4343
q, r, p = qr(A, (v"1.7" <= VERSION ? ColumnNorm() : Val(true)))
4444
p .= p |> reverse
4545
elseif ordering == :ccolamd
46-
cons = zeros(SuiteSparse_long, length(adjMat.colptr) - 1)
46+
cons = zeros(length(adjMat.colptr) - 1)
4747
cons[findall(x -> x in constraints, permuteds)] .= 1
48-
p = Ccolamd.ccolamd(adjMat, cons)
49-
@warn "Ccolamd is experimental in IIF at this point in time."
48+
p = _ccolamd(adjMat, cons)
49+
# cons = zeros(SuiteSparse_long, length(adjMat.colptr) - 1)
50+
# cons[findall(x -> x in constraints, permuteds)] .= 1
51+
# p = Ccolamd.ccolamd(adjMat, cons)
52+
@warn "Integration via AMD.ccolamd under development and replaces pre-Julia 1.9 direct ccall approach."
5053
else
5154
@error("getEliminationOrder -- cannot do the requested ordering $(ordering)")
5255
end
@@ -61,8 +64,8 @@ function addBayesNetVerts!(dfg::AbstractDFG, elimOrder::Array{Symbol, 1})
6164
#
6265
for pId in elimOrder
6366
vert = DFG.getVariable(dfg, pId)
64-
if getSolverData(vert).BayesNetVertID == nothing ||
65-
getSolverData(vert).BayesNetVertID == :_null # Special serialization case of nothing
67+
if getSolverData(vert).BayesNetVertID == nothing ||
68+
getSolverData(vert).BayesNetVertID == :_null # Special serialization case of nothing
6669
@debug "[AddBayesNetVerts] Assigning $pId.data.BayesNetVertID = $pId"
6770
getSolverData(vert).BayesNetVertID = pId
6871
else

test/testCcolamdOrdering.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using AMD
12
using IncrementalInference
23
using Test
34

0 commit comments

Comments
 (0)