@@ -220,58 +220,42 @@ Function returns with ARR[sfidx] pointing at newly allocated deepcopy of the
220
220
existing values in getVal(Xi[.label==solvefor]).
221
221
222
222
Notes
223
+ - 2023Q2 intended use, only create VarValsAll the first time a factor added/reconstructed
223
224
- Return values `sfidx` is the element in ARR where `Xi.label==solvefor` and
224
225
- `maxlen` is length of all (possibly resampled) `ARR` contained particles.
225
226
- `Xi` is order sensitive.
226
227
- for initialization, solveFor = Nothing.
227
228
- `P = getPointType(<:InferenceVariable)`
228
-
229
- DevNotes
230
- - FIXME ARR internally should become a NamedTuple
231
229
"""
232
- function _prepParamVec (
233
- Xi:: Vector{<:DFGVariable} ,
234
- solvefor:: Union{Nothing, Symbol} ,
235
- N:: Int = 0 ;
230
+ function _createVarValsAll (
231
+ Xi:: Vector{<:DFGVariable} ;
236
232
solveKey:: Symbol = :default ,
237
233
)
238
234
#
239
- # FIXME refactor to new NamedTuple instead
240
- varParamsAll = getVal .(Xi; solveKey)
241
- # Xi_labels = getLabel.(Xi)
242
- sfidx = if isnothing (solvefor)
243
- 0
244
- else
245
- findfirst (== (solvefor), getLabel .(Xi))
246
- end
247
- # sfidx = isnothing(sfidx) ? 0 : sfidx
235
+ # Note, NamedTuple once upon a time created way too much recompile load on repeat solves, #1564
236
+ varValsAll = map (var_i-> getVal (var_i; solveKey), tuple (Xi... ))
248
237
249
- # this line does nothing...
250
- # maxlen = N # FIXME see #105
251
-
252
- LEN = length .(varParamsAll)
253
- maxlen = maximum ([N; LEN])
238
+ # how many points
239
+ LEN = length .(varValsAll)
240
+ maxlen = maximum (LEN)
241
+ # NOTE, forcing maxlen to N results in errors (see test/testVariousNSolveSize.jl) see #105
242
+ # maxlen = N == 0 ? maxlen : N
254
243
244
+ # allow each variable to have a different number of points, which is resized during compute here
255
245
# resample variables with too few kernels (manifolds points)
256
246
SAMP = LEN .< maxlen
257
247
for i = 1 : length (Xi)
258
248
if SAMP[i]
259
249
Pr = getBelief (Xi[i], solveKey)
260
- _resizePointsVector! (varParamsAll [i], Pr, maxlen)
250
+ _resizePointsVector! (varValsAll [i], Pr, maxlen)
261
251
end
262
252
end
263
253
264
254
# TODO --rather define reusable memory for the proposal
265
255
# we are generating a proposal distribution, not direct replacement for existing memory and hence the deepcopy.
266
- if sfidx > 0
267
- # FIXME , POSSIBLE SOURCE OF HUGE MEMORY CONSUMPTION ALLOCATION
268
- varParamsAll[sfidx] = deepcopy (varParamsAll[sfidx])
269
- end
256
+ # POSSIBLE SOURCE OF HUGE MEMORY CONSUMPTION ALLOCATION
270
257
271
- varValsAll = tuple (varParamsAll... )
272
- # FIXME , forcing maxlen to N results in errors (see test/testVariousNSolveSize.jl) see #105
273
- # maxlen = N == 0 ? maxlen : N
274
- return varValsAll, maxlen, sfidx
258
+ return varValsAll
275
259
end
276
260
277
261
"""
@@ -352,10 +336,12 @@ end
352
336
$SIGNATURES
353
337
354
338
Notes
339
+ - _createCCW is likely only used when adding or reconstructing a new factor in the graph,
340
+ - else use _updateCCW
355
341
- Can be called with `length(Xi)==0`
356
342
"""
357
- function _prepCCW (
358
- Xi:: Vector {<:DFGVariable} ,
343
+ function _createCCW (
344
+ Xi:: AbstractVector {<:DFGVariable} ,
359
345
usrfnc:: T ;
360
346
multihypo:: Union{Nothing, <:Distributions.Categorical} = nothing ,
361
347
nullhypo:: Real = 0.0 ,
@@ -378,7 +364,8 @@ function _prepCCW(
378
364
end
379
365
380
366
# TODO check no Anys, see #1321
381
- _varValsAll, maxlen, sfidx = _prepParamVec (Xi, nothing , 0 ; solveKey) # Nothing for init.
367
+ # NOTE, _varValsAll is only a reference to the actual VND.val memory of each variable
368
+ _varValsAll = _createVarValsAll (Xi; solveKey)
382
369
383
370
manifold = getManifold (usrfnc)
384
371
# standard factor metadata
@@ -435,7 +422,7 @@ function _prepCCW(
435
422
pttypes = getVariableType .(Xi) .| > getPointType
436
423
PointType = 0 < length (pttypes) ? pttypes[1 ] : Vector{Float64}
437
424
if ! isconcretetype (PointType)
438
- @warn " _prepCCW PointType is not concrete $PointType " maxlog= 50
425
+ @warn " _createCCW PointType is not concrete $PointType " maxlog= 50
439
426
end
440
427
441
428
# PointType[],
@@ -487,40 +474,43 @@ approximate convolution computations.
487
474
DevNotes
488
475
- TODO consolidate with others, see https://github.com/JuliaRobotics/IncrementalInference.jl/projects/6
489
476
"""
490
- function _updateCCW ! (
477
+ function _beforeSolveCCW ! (
491
478
F_:: Type{<:AbstractRelative} ,
492
479
ccwl:: CommonConvWrapper{F} ,
493
- Xi :: AbstractVector{<:DFGVariable} ,
494
- solvefor:: Symbol ,
480
+ variables :: AbstractVector{<:DFGVariable} ,
481
+ # solvefor::Symbol,
495
482
N:: Integer ;
496
483
measurement = Vector {Tuple{}} (),
497
484
needFreshMeasurements:: Bool = true ,
498
485
solveKey:: Symbol = :default ,
499
486
) where {F <: AbstractFactor } # F might be Mixture
500
487
#
501
- if length (Xi ) != = 0
488
+ if length (variables ) != = 0
502
489
nothing
503
490
else
504
- @debug (" cannot prep ccw.param list with length(Xi )==0, see DFG #590" )
491
+ @debug (" cannot prep ccw.param list with length(variables )==0, see DFG #590" )
505
492
end
506
493
507
- # FIXME , order of fmd ccwl cf are a little weird and should be revised.
508
- # FIXME maxlen should parrot N (barring multi-/nullhypo issues)
509
- _varValsAll, maxlen, sfidx = _prepParamVec (Xi, solvefor, N; solveKey)
494
+ # TBD, order of fmd ccwl cf are a little weird and should be revised.
495
+ # TODO , maxlen should parrot N (barring multi-/nullhypo issues)
496
+ # set the 'solvefor' variable index -- i.e. which connected variable of the factor is being computed in this convolution.
497
+ # ccwl.varidx[] = findfirst(==(solvefor), getLabel.(variables))
498
+ # everybody use maxlen number of points in belief function estimation
499
+ maxlen = maximum ((N, length .(ccwl. varValsAll)... ,))
510
500
511
- # TODO , ensure all values (not just multihypothesis) is correctly used from here
512
- for (i,varVal) in enumerate (_varValsAll)
513
- resize! (ccwl. varValsAll[i],length (varVal))
514
- ccwl. varValsAll[i][:] = varVal
515
- end
501
+ # # PLAN B, make deep copy of ccwl.varValsAll[ccwl.varidx[]] just before the numerical solve
516
502
517
- # set the 'solvefor' variable index -- i.e. which connected variable of the factor is being computed in this convolution.
518
- ccwl. varidx[] = sfidx
503
+ # maxlen, ccwl.varidx[] = _updateParamVec(variables, solvefor, ccwl.varValsAll, N; solveKey)
504
+ # # TODO , ensure all values (not just multihypothesis) is correctly used from here
505
+ # for (i,varVal) in enumerate(_varValsAll)
506
+ # resize!(ccwl.varValsAll[i],length(varVal))
507
+ # ccwl.varValsAll[i][:] = varVal #TODO Kyk hierna: this looks like it will effectively result in vnd.val memory being overwritten
508
+ # end
519
509
520
510
# TODO better consolidation still possible
521
511
# FIXME ON FIRE, what happens if this is a partial dimension factor? See #1246
522
- # FIXME , confirm this is hypo sensitive selection from Xi , better to use double indexing for clarity getDimension(ccw.fullvariables[hypoidx[sfidx ]])
523
- xDim = getDimension (getVariableType (Xi[sfidx ])) # ccwl.varidx[]
512
+ # FIXME , confirm this is hypo sensitive selection from variables , better to use double indevariablesng for clarity getDimension(ccw.fullvariables[hypoidx[ccwl.varidx[] ]])
513
+ xDim = getDimension (getVariableType (variables[ccwl . varidx[] ])) # ccwl.varidx[]
524
514
# ccwl.xDim = xDim
525
515
# TODO maybe refactor different type or api call?
526
516
@@ -540,23 +530,25 @@ function _updateCCW!(
540
530
# calculate new gradients
541
531
# J = ccwl.gradients(measurement..., pts...)
542
532
543
- return sfidx, maxlen
533
+ return maxlen
544
534
end
545
535
546
- function _updateCCW ! (
536
+ function _beforeSolveCCW ! (
547
537
F_:: Type{<:AbstractPrior} ,
548
538
ccwl:: CommonConvWrapper{F} ,
549
539
Xi:: AbstractVector{<:DFGVariable} ,
550
- solvefor:: Symbol ,
540
+ # solvefor::Symbol,
551
541
N:: Integer ;
552
542
measurement = Vector {Tuple{}} (),
553
543
needFreshMeasurements:: Bool = true ,
554
544
solveKey:: Symbol = :default ,
555
545
) where {F <: AbstractFactor } # F might be Mixture
556
546
# FIXME , NEEDS TO BE CLEANED UP AND WORK ON MANIFOLDS PROPER
557
547
# fnc = ccwl.usrfnc!
558
- sfidx = findfirst (getLabel .(Xi) .== solvefor)
559
- @assert sfidx == 1 " Solving on Prior with CCW should have sfidx=1, priors are unary factors."
548
+ # sfidx = findfirst(getLabel.(Xi) .== solvefor)
549
+ @assert ccwl. varidx[] == 1 " Solving on Prior with CCW should have sfidx=1, priors are unary factors."
550
+ # @assert sfidx == 1 "Solving on Prior with CCW should have sfidx=1, priors are unary factors."
551
+ # ccwl.varidx[] = sfidx
560
552
# sfidx = 1 # why hardcoded to 1, maybe for only the AbstractPrior case here
561
553
562
554
# setup the partial or complete decision variable dimensions for this ccwl object
@@ -570,30 +562,30 @@ function _updateCCW!(
570
562
# update ccwl.measurement values
571
563
updateMeasurement! (ccwl, maxlen; needFreshMeasurements, measurement, _allowThreads= true )
572
564
573
- return sfidx, maxlen
565
+ return maxlen
574
566
end
575
567
576
568
# TODO , can likely deprecate this
577
- function _updateCCW ! (
569
+ function _beforeSolveCCW ! (
578
570
ccwl:: Union{CommonConvWrapper{F}, CommonConvWrapper{Mixture{N_, F, S, T}}} ,
579
571
Xi:: AbstractVector{<:DFGVariable} ,
580
- solvefor:: Symbol ,
572
+ # solvefor::Symbol,
581
573
N:: Integer ;
582
574
kw... ,
583
575
) where {N_, F <: AbstractRelative , S, T}
584
576
#
585
- return _updateCCW ! (F, ccwl, Xi, solvefor , N; kw... )
577
+ return _beforeSolveCCW ! (F, ccwl, Xi, N; kw... )
586
578
end
587
579
588
- function _updateCCW ! (
580
+ function _beforeSolveCCW ! (
589
581
ccwl:: Union{CommonConvWrapper{F}, CommonConvWrapper{Mixture{N_, F, S, T}}} ,
590
582
Xi:: AbstractVector{<:DFGVariable} ,
591
- solvefor:: Symbol ,
583
+ # solvefor::Symbol,
592
584
N:: Integer ;
593
585
kw... ,
594
586
) where {N_, F <: AbstractPrior , S, T}
595
587
#
596
- return _updateCCW ! (F, ccwl, Xi, solvefor , N; kw... )
588
+ return _beforeSolveCCW ! (F, ccwl, Xi, N; kw... )
597
589
end
598
590
599
591
0 commit comments