80
80
struct CostF_RLM!{T}
81
81
points:: Vector{T}
82
82
costfuns:: Vector{<:CalcFactorManopt}
83
+ # varLabels::Vector{Symbol} @TODO add
83
84
end
84
85
85
86
function CostF_RLM! (costfuns:: Vector{<:CalcFactorManopt} , frontals_p:: Vector{T} , separators_p:: Vector{T} ) where T
154
155
# function JacF_RLM!(M, costF!; basis_domain::AbstractBasis = DefaultOrthonormalBasis())
155
156
function JacF_RLM! (M, costF!, p, fg= nothing ; basis_domain:: AbstractBasis = DefaultOrthogonalBasis (), sparse= ! isnothing (fg))
156
157
157
- # p = costF!.points
158
-
159
158
# Why does this error?
160
159
# res = Vector(mapreduce(f -> f(p), vcat, costF!.costfuns))
161
160
res = reduce (vcat, map (f -> f (p), Vector (costF!. costfuns)))
@@ -168,7 +167,7 @@ function JacF_RLM!(M, costF!, p, fg=nothing; basis_domain::AbstractBasis = Defau
168
167
169
168
if sparse
170
169
factLabels = collect (getproperty .(costF!. costfuns, :faclbl ))
171
- sparsity = eltype (res).(getSparsityPattern (fg, ls (fg) , factLabels))
170
+ sparsity = eltype (res).(getSparsityPattern (fg, costF! . varLabels , factLabels))
172
171
colorvec = matrix_colors (sparsity)
173
172
else
174
173
sparsity = nothing
@@ -247,26 +246,32 @@ end
247
246
248
247
# TODO this function is not the sparsity pattern yet, it just fills in all entries from the biadjacency matrix
249
248
# TODO allow getting sparcity pattern for a subfg
249
+ # OLD 0.424040 seconds (940.11 k allocations: 45.512 MiB)
250
+ # NEW 0.001552 seconds (2.04 k allocations: 1.816 MiB)
250
251
function getSparsityPattern (fg, varLabels, factLabels)
251
252
biadj = getBiadjacencyMatrix (fg; varLabels, factLabels)
252
253
253
254
vdims = getDimension .(getVariable .(fg, biadj. varLabels))
254
255
fdims = getDimension .(getFactor .(fg, biadj. facLabels))
256
+
257
+ c_end = cumsum (vdims)
258
+ r_end = cumsum (fdims)
255
259
256
- sm = map (eachindex (biadj. B)) do i
257
- vdim = vdims[i[2 ]]
258
- fdim = fdims[i[1 ]]
259
- if biadj. B[i] > 0
260
- trues (fdim,vdim)
261
- else
262
- falses (fdim,vdim)
263
- end
264
- end
260
+ C_range = range .(c_end - vdims .+ 1 , c_end)
261
+ R_range = range .(r_end - fdims .+ 1 , r_end)
265
262
266
- return SparseMatrixCSC ( mortar (sm) )
263
+ ROWS, COLS, _ = findnz (biadj . B )
267
264
265
+ iter = reduce (vcat, map (zip (ROWS, COLS)) do (R,C)
266
+ vec (CartesianIndices ((R_range[R], C_range[C])))
267
+ end )
268
+
269
+ vec (CartesianIndices ((R_range[2 ], C_range[1 ])))
270
+
271
+ return sparse (getindex .(iter,1 ), getindex .(iter,2 ), ones (Bool, length (iter)))
268
272
end
269
273
274
+
270
275
function solve_RLM (
271
276
fg,
272
277
frontals:: Vector{Symbol} = ls (fg);
446
451
447
452
# HEX solve
448
453
# sparse J 0.025235 seconds (133.65 k allocations: 9.964 MiB
449
- # new 0.013486 seconds (36.16 k allocations: 2.593 MiB)
454
+ # new1 0.013486 seconds (36.16 k allocations: 2.593 MiB)
455
+ # new2 0.010764 seconds (34.61 k allocations: 3.111 MiB)
450
456
# dense J 0.022079 seconds (283.54 k allocations: 18.146 MiB)
451
457
452
458
function solve_RLM_sparse (fg; kwargs... )
0 commit comments