@@ -26,7 +26,7 @@ function CalcFactor(
2626 ccwl:: CommonConvWrapper ;
2727 factor = ccwl. usrfnc!,
2828 _sampleIdx = 0 ,
29- _legacyParams = ccwl. varValsAll,
29+ _legacyParams = ccwl. varValsAll[] ,
3030 _allowThreads = true ,
3131 cache = ccwl. dummyCache,
3232 fullvariables = ccwl. fullvariables,
@@ -211,6 +211,14 @@ function _resizePointsVector!(
211211 return vecP
212212end
213213
214+ function _checkVarValPointers (dfg:: AbstractDFG , fclb:: Symbol )
215+ vars = getVariable .(dfg, getVariableOrder (dfg,fclb))
216+ ptrsV = pointer .(getVal .(vars))
217+ ccw = _getCCW (dfg, fclb)
218+ ptrsC = pointer .(ccw. varValsAll[])
219+ ptrsV, ptrsC
220+ end
221+
214222"""
215223 $(SIGNATURES)
216224
@@ -228,28 +236,33 @@ Notes
228236- `P = getPointType(<:InferenceVariable)`
229237"""
230238function _createVarValsAll (
231- Xi :: Vector {<:DFGVariable} ;
239+ variables :: AbstractVector {<:DFGVariable} ;
232240 solveKey:: Symbol = :default ,
233241)
234242 #
235243 # 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... ))
244+ varValsAll = map (var_i-> getVal (var_i; solveKey), tuple (variables... ))
245+
246+ for (i,vv) in enumerate (varValsAll)
247+ @assert pointer (vv) == pointer (getVal (variables[i]; solveKey)) " Developer check that ccw.varValsAll pointers go to same memory as getVal(variable)"
248+ end
237249
238250 # how many points
239251 LEN = length .(varValsAll)
240252 maxlen = maximum (LEN)
241253 # NOTE, forcing maxlen to N results in errors (see test/testVariousNSolveSize.jl) see #105
242254 # maxlen = N == 0 ? maxlen : N
243255
244- # allow each variable to have a different number of points, which is resized during compute here
245- # resample variables with too few kernels (manifolds points)
246- SAMP = LEN .< maxlen
247- for i = 1 : length (Xi)
248- if SAMP[i]
249- Pr = getBelief (Xi[i], solveKey)
250- _resizePointsVector! (varValsAll[i], Pr, maxlen)
251- end
252- end
256+ # NOTE resize! moves the pointer!!!!!!
257+ # # allow each variable to have a different number of points, which is resized during compute here
258+ # # resample variables with too few kernels (manifolds points)
259+ # SAMP = LEN .< maxlen
260+ # for i = 1:length(variables)
261+ # if SAMP[i]
262+ # Pr = getBelief(variables[i], solveKey)
263+ # _resizePointsVector!(varValsAll[i], Pr, maxlen)
264+ # end
265+ # end
253266
254267 # TODO --rather define reusable memory for the proposal
255268 # we are generating a proposal distribution, not direct replacement for existing memory and hence the deepcopy.
@@ -429,7 +442,7 @@ function _createCCW(
429442 return CommonConvWrapper (;
430443 usrfnc! = usrfnc,
431444 fullvariables,
432- varValsAll = _varValsAll,
445+ varValsAll = Ref ( _varValsAll) ,
433446 dummyCache = userCache,
434447 manifold,
435448 partialDims,
@@ -498,8 +511,9 @@ function _beforeSolveCCW!(
498511 # set the 'solvefor' variable index -- i.e. which connected variable of the factor is being computed in this convolution.
499512 # ccwl.varidx[] = findfirst(==(solvefor), getLabel.(variables))
500513 # everybody use maxlen number of points in belief function estimation
501- maxlen = maximum ((N, length .(ccwl. varValsAll)... ,))
514+ maxlen = maximum ((N, length .(ccwl. varValsAll[] )... ,))
502515
516+ ccwl. varValsAll[] = map (s-> getVal (s; solveKey), tuple (variables... ))
503517 # # PLAN B, make deep copy of ccwl.varValsAll[ccwl.varidx[]] just before the numerical solve
504518
505519 # maxlen, ccwl.varidx[] = _updateParamVec(variables, solvefor, ccwl.varValsAll, N; solveKey)
@@ -558,7 +572,7 @@ function _beforeSolveCCW!(
558572 _setCCWDecisionDimsConv! (ccwl, getDimension (getVariableType (Xi[ccwl. varidx[]])))
559573
560574 solveForPts = getVal (Xi[ccwl. varidx[]]; solveKey)
561- maxlen = maximum ([N; length (solveForPts); length (ccwl. varValsAll[ccwl. varidx[]])]) # calcZDim(ccwl); length(measurement[1])
575+ maxlen = maximum ([N; length (solveForPts); length (ccwl. varValsAll[][ ccwl. varidx[]])]) # calcZDim(ccwl); length(measurement[1])
562576
563577 # FIXME do not divert Mixture for sampling
564578 # update ccwl.measurement values
0 commit comments