@@ -220,58 +220,42 @@ Function returns with ARR[sfidx] pointing at newly allocated deepcopy of the
220220existing values in getVal(Xi[.label==solvefor]).
221221
222222Notes
223+ - 2023Q2 intended use, only create VarValsAll the first time a factor added/reconstructed
223224- Return values `sfidx` is the element in ARR where `Xi.label==solvefor` and
224225- `maxlen` is length of all (possibly resampled) `ARR` contained particles.
225226- `Xi` is order sensitive.
226227- for initialization, solveFor = Nothing.
227228- `P = getPointType(<:InferenceVariable)`
228-
229- DevNotes
230- - FIXME ARR internally should become a NamedTuple
231229"""
232- function _prepParamVec (
233- Xi:: Vector{<:DFGVariable} ,
234- solvefor:: Union{Nothing, Symbol} ,
235- N:: Int = 0 ;
230+ function _createVarValsAll (
231+ Xi:: Vector{<:DFGVariable} ;
236232 solveKey:: Symbol = :default ,
237233)
238234 #
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... ))
248237
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
254243
244+ # allow each variable to have a different number of points, which is resized during compute here
255245 # resample variables with too few kernels (manifolds points)
256246 SAMP = LEN .< maxlen
257247 for i = 1 : length (Xi)
258248 if SAMP[i]
259249 Pr = getBelief (Xi[i], solveKey)
260- _resizePointsVector! (varParamsAll [i], Pr, maxlen)
250+ _resizePointsVector! (varValsAll [i], Pr, maxlen)
261251 end
262252 end
263253
264254 # TODO --rather define reusable memory for the proposal
265255 # 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
270257
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
275259end
276260
277261"""
@@ -352,10 +336,12 @@ end
352336 $SIGNATURES
353337
354338Notes
339+ - _createCCW is likely only used when adding or reconstructing a new factor in the graph,
340+ - else use _updateCCW
355341- Can be called with `length(Xi)==0`
356342"""
357- function _prepCCW (
358- Xi:: Vector {<:DFGVariable} ,
343+ function _createCCW (
344+ Xi:: AbstractVector {<:DFGVariable} ,
359345 usrfnc:: T ;
360346 multihypo:: Union{Nothing, <:Distributions.Categorical} = nothing ,
361347 nullhypo:: Real = 0.0 ,
@@ -378,7 +364,8 @@ function _prepCCW(
378364 end
379365
380366 # 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)
382369
383370 manifold = getManifold (usrfnc)
384371 # standard factor metadata
@@ -435,7 +422,7 @@ function _prepCCW(
435422 pttypes = getVariableType .(Xi) .| > getPointType
436423 PointType = 0 < length (pttypes) ? pttypes[1 ] : Vector{Float64}
437424 if ! isconcretetype (PointType)
438- @warn " _prepCCW PointType is not concrete $PointType " maxlog= 50
425+ @warn " _createCCW PointType is not concrete $PointType " maxlog= 50
439426 end
440427
441428 # PointType[],
@@ -487,40 +474,43 @@ approximate convolution computations.
487474DevNotes
488475- TODO consolidate with others, see https://github.com/JuliaRobotics/IncrementalInference.jl/projects/6
489476"""
490- function _updateCCW ! (
477+ function _beforeSolveCCW ! (
491478 F_:: Type{<:AbstractRelative} ,
492479 ccwl:: CommonConvWrapper{F} ,
493- Xi :: AbstractVector{<:DFGVariable} ,
494- solvefor:: Symbol ,
480+ variables :: AbstractVector{<:DFGVariable} ,
481+ # solvefor::Symbol,
495482 N:: Integer ;
496483 measurement = Vector {Tuple{}} (),
497484 needFreshMeasurements:: Bool = true ,
498485 solveKey:: Symbol = :default ,
499486) where {F <: AbstractFactor } # F might be Mixture
500487 #
501- if length (Xi ) != = 0
488+ if length (variables ) != = 0
502489 nothing
503490 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" )
505492 end
506493
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)... ,))
510500
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
516502
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
519509
520510 # TODO better consolidation still possible
521511 # 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[]
524514 # ccwl.xDim = xDim
525515 # TODO maybe refactor different type or api call?
526516
@@ -540,23 +530,25 @@ function _updateCCW!(
540530 # calculate new gradients
541531 # J = ccwl.gradients(measurement..., pts...)
542532
543- return sfidx, maxlen
533+ return maxlen
544534end
545535
546- function _updateCCW ! (
536+ function _beforeSolveCCW ! (
547537 F_:: Type{<:AbstractPrior} ,
548538 ccwl:: CommonConvWrapper{F} ,
549539 Xi:: AbstractVector{<:DFGVariable} ,
550- solvefor:: Symbol ,
540+ # solvefor::Symbol,
551541 N:: Integer ;
552542 measurement = Vector {Tuple{}} (),
553543 needFreshMeasurements:: Bool = true ,
554544 solveKey:: Symbol = :default ,
555545) where {F <: AbstractFactor } # F might be Mixture
556546 # FIXME , NEEDS TO BE CLEANED UP AND WORK ON MANIFOLDS PROPER
557547 # 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
560552 # sfidx = 1 # why hardcoded to 1, maybe for only the AbstractPrior case here
561553
562554 # setup the partial or complete decision variable dimensions for this ccwl object
@@ -570,30 +562,30 @@ function _updateCCW!(
570562 # update ccwl.measurement values
571563 updateMeasurement! (ccwl, maxlen; needFreshMeasurements, measurement, _allowThreads= true )
572564
573- return sfidx, maxlen
565+ return maxlen
574566end
575567
576568# TODO , can likely deprecate this
577- function _updateCCW ! (
569+ function _beforeSolveCCW ! (
578570 ccwl:: Union{CommonConvWrapper{F}, CommonConvWrapper{Mixture{N_, F, S, T}}} ,
579571 Xi:: AbstractVector{<:DFGVariable} ,
580- solvefor:: Symbol ,
572+ # solvefor::Symbol,
581573 N:: Integer ;
582574 kw... ,
583575) where {N_, F <: AbstractRelative , S, T}
584576 #
585- return _updateCCW ! (F, ccwl, Xi, solvefor , N; kw... )
577+ return _beforeSolveCCW ! (F, ccwl, Xi, N; kw... )
586578end
587579
588- function _updateCCW ! (
580+ function _beforeSolveCCW ! (
589581 ccwl:: Union{CommonConvWrapper{F}, CommonConvWrapper{Mixture{N_, F, S, T}}} ,
590582 Xi:: AbstractVector{<:DFGVariable} ,
591- solvefor:: Symbol ,
583+ # solvefor::Symbol,
592584 N:: Integer ;
593585 kw... ,
594586) where {N_, F <: AbstractPrior , S, T}
595587 #
596- return _updateCCW ! (F, ccwl, Xi, solvefor , N; kw... )
588+ return _beforeSolveCCW ! (F, ccwl, Xi, N; kw... )
597589end
598590
599591
0 commit comments