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. ccolamd_l_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_l ( # 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. ccolamd_l_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{T1} , # SuiteSparse_long},
70+ p:: AbstractVector{<:Real} , # {SuiteSparse_long},
71+ cmember:: Union{Ptr{Nothing}, <:AbstractVector{T}} , # SuiteSparse_long
72+ ) where {T1<: Real , 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. ccolamd_l_recommended (length (A), n_row, n_col)
80+ resize! (A, Alen)
81+ stats = zeros (T1, 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 (biadjMat, constraints) = _ccolamd (size (biadjMat, 1 ), biadjMat. rowval, biadjMat. colptr, constraints)
97+
98+
99+
100+ end
0 commit comments