Skip to content

Commit c28e9ce

Browse files
committed
drop destVarVal args
1 parent 8b70aaf commit c28e9ce

File tree

2 files changed

+39
-31
lines changed

2 files changed

+39
-31
lines changed

src/services/CalcFactor.jl

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ function _beforeSolveCCW!(
504504
F_::Type{<:AbstractRelative},
505505
ccwl::CommonConvWrapper{F},
506506
variables::AbstractVector{<:DFGVariable},
507-
destVarVals::AbstractVector,
507+
# destVarVals::AbstractVector,
508508
sfidx::Int,
509509
N::Integer;
510510
measurement = Vector{Tuple{}}(),
@@ -520,20 +520,28 @@ function _beforeSolveCCW!(
520520

521521
# in forward solve case, important to set which variable is being solved early in this sequence
522522
ccwl.varidx[] = sfidx
523-
523+
524524
# TBD, order of fmd ccwl cf are a little weird and should be revised.
525525
# TODO, maxlen should parrot N (barring multi-/nullhypo issues)
526526
# set the 'solvefor' variable index -- i.e. which connected variable of the factor is being computed in this convolution.
527527
# ccwl.varidx[] = findfirst(==(solvefor), getLabel.(variables))
528528
# everybody use maxlen number of points in belief function estimation
529529
maxlen = maximum((N, length.(ccwl.varValsAll[])...,))
530-
531-
# not type-stable
532-
varvals = [getVal(s; solveKey) for s in variables]
530+
533531
# splice
534-
varvals[sfidx] = destVarVals
532+
# should be type stable
533+
tvarv = tuple(
534+
map(s->getVal(s; solveKey), variables[1:sfidx-1])...,
535+
deepcopy(ccwl.varValsAll[][sfidx]), # destVarVals = deepcopy(ccwl.varValsAll[][sfidx])
536+
map(s->getVal(s; solveKey), variables[sfidx+1:end])...,
537+
)
538+
# not type-stable
539+
# varvals = [getVal(s; solveKey) for s in variables]
540+
# varvals[sfidx] = destVarVals
535541
# varvals_ = [varvals[1:sfidx-1]..., destVarVals, varvals[sfidx+1:end]...]
536-
tvarv = tuple(varvals...)
542+
# tvarv = tuple(varvals...)
543+
544+
537545
# @info "TYPES" typeof(ccwl.varValsAll[]) typeof(tvarv)
538546
ccwl.varValsAll[] = tvarv
539547
# ccwl.varValsAll[] = map(s->getVal(s; solveKey), tuple(variables...))
@@ -576,7 +584,7 @@ function _beforeSolveCCW!(
576584
F_::Type{<:AbstractPrior},
577585
ccwl::CommonConvWrapper{F},
578586
variables::AbstractVector{<:DFGVariable},
579-
destVarVals::AbstractVector,
587+
# destVarVals::AbstractVector,
580588
sfidx::Int,
581589
N::Integer;
582590
measurement = Vector{Tuple{}}(),
@@ -611,25 +619,25 @@ end
611619
function _beforeSolveCCW!(
612620
ccwl::Union{CommonConvWrapper{F}, CommonConvWrapper{Mixture{N_, F, S, T}}},
613621
Xi::AbstractVector{<:DFGVariable},
614-
destVarVals::AbstractVector,
622+
# destVarVals::AbstractVector,
615623
sfidx::Int,
616624
N::Integer;
617625
kw...,
618626
) where {N_, F <: AbstractRelative, S, T}
619627
#
620-
return _beforeSolveCCW!(F, ccwl, Xi, destVarVals, sfidx, N; kw...)
628+
return _beforeSolveCCW!(F, ccwl, Xi, sfidx, N; kw...)
621629
end
622630

623631
function _beforeSolveCCW!(
624632
ccwl::Union{CommonConvWrapper{F}, CommonConvWrapper{Mixture{N_, F, S, T}}},
625633
Xi::AbstractVector{<:DFGVariable},
626-
destVarVals::AbstractVector,
634+
# destVarVals::AbstractVector,
627635
sfidx::Int,
628636
N::Integer;
629637
kw...,
630638
) where {N_, F <: AbstractPrior, S, T}
631639
#
632-
return _beforeSolveCCW!(F, ccwl, Xi, destVarVals, sfidx, N; kw...)
640+
return _beforeSolveCCW!(F, ccwl, Xi, sfidx, N; kw...)
633641
end
634642

635643

src/services/EvalFactor.jl

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,13 @@ function calcVariableDistanceExpectedFractional(
4242
sfidx::Integer,
4343
certainidx::AbstractVector{<:Integer};
4444
kappa::Real = 3.0,
45-
readonlyVarVals = ccwl.varValsAll[][sfidx]
45+
# readonlyVarVals = ccwl.varValsAll[][sfidx]
4646
)
4747
#
48+
@assert sfidx == ccwl.varidx[] "ccwl.varidx[] is expected to be the same as sfidx"
4849
varTypes = getVariableType.(ccwl.fullvariables)
4950
if sfidx in certainidx
50-
msst_ = calcStdBasicSpread(varTypes[sfidx], readonlyVarVals)
51+
msst_ = calcStdBasicSpread(varTypes[sfidx], ccwl.varValsAll[][sfidx])
5152
return kappa * msst_
5253
end
5354
# @assert !(sfidx in certainidx) "null hypo distance does not work for sfidx in certainidx"
@@ -68,7 +69,7 @@ function calcVariableDistanceExpectedFractional(
6869

6970
refMean = getCoordinates(
7071
varTypes[sfidx],
71-
mean(getManifold(varTypes[sfidx]), readonlyVarVals),
72+
mean(getManifold(varTypes[sfidx]), ccwl.varValsAll[][sfidx]),
7273
)
7374

7475
# calc for uncertain and certain
@@ -107,7 +108,7 @@ function addEntropyOnManifold!(
107108
#allocate to change SMatrix to MMatrix
108109
X = allocate(get_vector(M, points[1], Xc, DefaultOrthogonalBasis()))
109110

110-
for idx = 1:length(points)
111+
for idx in 1:length(points)
111112
# build tangent coordinate random
112113
for dim in dimIdx
113114
if (p === :) || dim in p
@@ -145,7 +146,7 @@ function computeAcrossHypothesis!(
145146
sfidx::Int,
146147
maxlen::Int,
147148
mani::ManifoldsBase.AbstractManifold; # maniAddOps::Tuple;
148-
destinationVarVals = deepcopy(ccwl.varValsAll[][sfidx]),
149+
# destinationVarVals = ccwl.varValsAll[][sfidx], # deepcopy
149150
spreadNH::Real = 5.0,
150151
inflateCycles::Int = 3,
151152
skipSolve::Bool = false,
@@ -159,6 +160,7 @@ function computeAcrossHypothesis!(
159160
activehypo = hyporecipe.activehypo
160161
certainidx = hyporecipe.certainidx
161162

163+
@assert ccwl.varidx[] == sfidx "duplicate registers for solve for index should be the same in ccw.varidx"
162164
@assert ccwl.hyporecipe.certainhypo == hyporecipe.certainidx "expected hyporecipe.certainidx to be the same as cached in ccw"
163165
for (hypoidx, vars) in activehypo
164166
count += 1
@@ -171,7 +173,8 @@ function computeAcrossHypothesis!(
171173
ccwl.hyporecipe.activehypo[:] = vars
172174
# end
173175

174-
addEntr = view(destinationVarVals, allelements[count])
176+
# ccwl.varValsAll[][ccwl.varidx[]] should be an alternate/duplicate memory from getVal(variable; solveKey)
177+
addEntr = view(ccwl.varValsAll[][ccwl.varidx[]], allelements[count]) # destinationVarVals
175178

176179
# do proposal inflation step, see #1051
177180
# consider duplicate convolution approximations for inflation off-zero
@@ -183,7 +186,7 @@ function computeAcrossHypothesis!(
183186
sfidx,
184187
certainidx;
185188
kappa = ccwl.inflation,
186-
readonlyVarVals = destinationVarVals,
189+
# readonlyVarVals = ccwl.varValsAll[][ccwl.varidx[]],
187190
)
188191
addEntropyOnManifold!(
189192
mani,
@@ -197,7 +200,7 @@ function computeAcrossHypothesis!(
197200
if skipSolve
198201
@warn("skipping numerical solve operation")
199202
else
200-
approxConvOnElements!(destinationVarVals, ccwl, allelements[count], _slack)
203+
approxConvOnElements!(ccwl.varValsAll[][ccwl.varidx[]], ccwl, allelements[count], _slack)
201204
end
202205
end
203206
elseif hypoidx != sfidx && hypoidx != 0
@@ -206,22 +209,22 @@ function computeAcrossHypothesis!(
206209
# sfidx=2, hypoidx=3: 2 should take a value from 3
207210
# sfidx=3, hypoidx=2: 3 should take a value from 2
208211
# DEBUG sfidx=2, hypoidx=1 -- bad when do something like multihypo=[0.5;0.5] -- issue 424
209-
# destinationVarVals[:,allelements[count]] = view(ccwl.varValsAll[hypoidx],:,allelements[count])
212+
# ccwl.varValsAll[][ccwl.varidx[]][:,allelements[count]] = view(ccwl.varValsAll[hypoidx],:,allelements[count])
210213
# NOTE make alternative case only operate as null hypo
211-
addEntr = view(destinationVarVals, allelements[count])
214+
addEntr = view(ccwl.varValsAll[][ccwl.varidx[]], allelements[count])
212215
# dynamic estimate with user requested speadNH of how much noise to inject (inflation or nullhypo)
213216
spreadDist =
214-
calcVariableDistanceExpectedFractional(ccwl, sfidx, certainidx; kappa = spreadNH,readonlyVarVals = destinationVarVals)
217+
calcVariableDistanceExpectedFractional(ccwl, sfidx, certainidx; kappa = spreadNH) #,readonlyVarVals = ccwl.varValsAll[][ccwl.varidx[]])
215218
addEntropyOnManifold!(mani, addEntr, 1:getDimension(mani), spreadDist)
216219

217220
elseif hypoidx == 0
218221
# basically do nothing since the factor is not active for these allelements[count]
219222
# inject more entropy in nullhypo case
220223
# add noise (entropy) to spread out search in convolution proposals
221-
addEntr = view(destinationVarVals, allelements[count])
224+
addEntr = view(ccwl.varValsAll[][ccwl.varidx[]], allelements[count])
222225
# dynamic estimate with user requested speadNH of how much noise to inject (inflation or nullhypo)
223226
spreadDist =
224-
calcVariableDistanceExpectedFractional(ccwl, sfidx, certainidx; kappa = spreadNH, readonlyVarVals = destinationVarVals)
227+
calcVariableDistanceExpectedFractional(ccwl, sfidx, certainidx; kappa = spreadNH) #, readonlyVarVals = ccwl.varValsAll[][ccwl.varidx[]])
225228
# # make spread (1σ) equal to mean distance of other fractionals
226229
addEntropyOnManifold!(mani, addEntr, 1:getDimension(mani), spreadDist)
227230
else
@@ -337,8 +340,7 @@ function evalPotentialSpecific(
337340
# add user desired measurement values if 0 < length
338341
# 2023Q2, ccwl.varValsAll always points at the variable.VND.val memory locations
339342
# remember when doing approxConv to make a deepcopy of the destination memory first.
340-
destinationVarVals = deepcopy(ccwl.varValsAll[][sfidx])
341-
maxlen = _beforeSolveCCW!(ccwl, variables, destinationVarVals, sfidx, N; solveKey, needFreshMeasurements, measurement)
343+
maxlen = _beforeSolveCCW!(ccwl, variables, sfidx, N; solveKey, needFreshMeasurements, measurement)
342344

343345
# Check which variables have been initialized
344346
isinit = map(x -> isInitialized(x), variables)
@@ -367,7 +369,7 @@ function evalPotentialSpecific(
367369
sfidx,
368370
maxlen,
369371
mani;
370-
destinationVarVals,
372+
# destinationVarVals,
371373
spreadNH,
372374
inflateCycles,
373375
skipSolve,
@@ -415,8 +417,7 @@ function evalPotentialSpecific(
415417
#
416418

417419
# Prep computation variables
418-
destinationVarVals = deepcopy(ccwl.varValsAll[][sfidx])
419-
maxlen = _beforeSolveCCW!(ccwl, variables, destinationVarVals, sfidx, N; solveKey, needFreshMeasurements, measurement)
420+
maxlen = _beforeSolveCCW!(ccwl, variables, sfidx, N; solveKey, needFreshMeasurements, measurement)
420421

421422
# # FIXME, NEEDS TO BE CLEANED UP AND WORK ON MANIFOLDS PROPER
422423
fnc = ccwl.usrfnc!
@@ -622,7 +623,6 @@ function _evalFactorTemporary!(
622623
solveKey::Symbol = :default,
623624
newFactor::Bool = true,
624625
_slack = nothing,
625-
# FIXME ON FIRE ADD destinationVarVals,
626626
buildgraphkw...,
627627
)
628628
#

0 commit comments

Comments
 (0)