Skip to content

Commit 65e1715

Browse files
authored
Use CalcFactorNormSq as functor (#1786)
* Use CalcFactorNormSq as functor * Force svector for performance * Fix deconv manifold and init NOTE #1786 (comment)
1 parent c49e4b0 commit 65e1715

File tree

7 files changed

+132
-178
lines changed

7 files changed

+132
-178
lines changed

src/Factors/Mixture.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,8 @@ function sampleFactor(cf::CalcFactor{<:Mixture}, N::Int = 1)
126126
cf.cache,
127127
cf.fullvariables,
128128
cf.solvefor,
129-
cf.manifold
129+
cf.manifold,
130+
cf.measurement
130131
)
131132
smpls = [getSample(cf_) for _ = 1:N]
132133
# smpls = Array{Float64,2}(undef,s.dims,N)

src/entities/CalcFactor.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,16 @@ struct CalcFactorNormSq{
3535
X,
3636
C,
3737
VT <: Tuple,
38-
M <: AbstractManifold
38+
M <: AbstractManifold,
39+
MEAS
3940
} <: CalcFactor{FT}
4041
""" the interface compliant user object functor containing the data and logic """
4142
factor::FT
4243
""" what is the sample (particle) id for which the residual is being calculated """
4344
_sampleIdx::Int
4445
""" legacy support for variable values old functor residual functions.
4546
TBD, this is still being used by DERelative factors. """
46-
_legacyParams::X
47+
_legacyParams::X #TODO rename to varValsHypo for consistent naming? and not not legacy any more
4748
""" allow threading for either sampling or residual calculations (workaround for thread yield issue) """
4849
_allowThreads::Bool
4950
""" user cache of arbitrary type, overload the [`preambleCache`](@ref) function. NOT YET THREADSAFE """
@@ -56,6 +57,7 @@ struct CalcFactorNormSq{
5657
# which index is being solved for?
5758
solvefor::Int
5859
manifold::M
60+
measurement::MEAS
5961
end
6062

6163
#TODO deprecate after CalcFactor is updated to CalcFactorNormSq

src/services/CalcFactor.jl

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ function CalcFactorNormSq(
4343
cache,
4444
tuple(fullvariables...),
4545
solvefor,
46-
manifold
46+
manifold,
47+
ccwl.measurement,
4748
)
4849
end
4950

@@ -395,8 +396,7 @@ function _createCCW(
395396
solvefor = length(Xi)
396397
fullvariables = tuple(Xi...) # convert(Vector{DFGVariable}, Xi)
397398
# create a temporary CalcFactor object for extracting the first sample
398-
# TODO, deprecate this: guess measurement points type
399-
# MeasType = Vector{Float64} # FIXME use `usrfnc` to get this information instead
399+
400400
_cf = CalcFactorNormSq(
401401
usrfnc,
402402
1,
@@ -405,17 +405,30 @@ function _createCCW(
405405
userCache,
406406
fullvariables,
407407
solvefor,
408-
manifold
408+
manifold,
409+
nothing,
409410
)
410411

411412
# get a measurement sample
412413
meas_single = sampleFactor(_cf, 1)[1]
413-
414414
elT = typeof(meas_single)
415-
416415
#TODO preallocate measurement?
417416
measurement = Vector{elT}()
418417

418+
#FIXME chicken and egg problem for getting measurement type, so creating twice.
419+
_cf = CalcFactorNormSq(
420+
usrfnc,
421+
1,
422+
_varValsAll,
423+
false,
424+
userCache,
425+
fullvariables,
426+
solvefor,
427+
manifold,
428+
measurement,
429+
)
430+
431+
419432
# partialDims are sensitive to both which solvefor variable index and whether the factor is partial
420433
partial = hasfield(T, :partial) # FIXME, use isPartial function instead
421434
partialDims = if partial

src/services/DeconvUtils.jl

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,6 @@ function approxDeconv(
7171

7272
islen1 = zDim == 1
7373

74-
# FIXME, is this still in use
75-
destVarVals = Vector{Int}()
76-
7774
for idx = 1:N
7875
# towards each particle in their own thread (not 100% ready yet, factors should be separate memory)
7976
target_smpl = makeTarget(idx)
@@ -82,7 +79,7 @@ function approxDeconv(
8279
resize!(ccw.hyporecipe.activehypo, length(hyporecipe.activehypo[2][2]))
8380
ccw.hyporecipe.activehypo[:] = hyporecipe.activehypo[2][2]
8481

85-
onehypo!, _ = _buildCalcFactorLambdaSample(ccw, idx, target_smpl, measurement)
82+
onehypo! = _buildCalcFactorLambdaSample(ccw, idx, measurement)
8683
#
8784

8885
# lambda with which to find best measurement values

src/services/EvalFactor.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ function calcVariableDistanceExpectedFractional(
8282
# also check distance to certainidx for general scale reference (workaround heuristic)
8383
for cidx in certainidx
8484
count += 1
85-
cerMeanPnt = mean(getManifold(varTypes[cidx]), ccwl.varValsAll[][cidx])
85+
cerMeanPnt = mean(getManifold(varTypes[cidx]), ccwl.varValsAll[][cidx], GeodesicInterpolation())
8686
cerMean = getCoordinates(varTypes[cidx], cerMeanPnt)
8787
dists[count] = norm(refMean[1:dims] - cerMean[1:dims])
8888
end

0 commit comments

Comments
 (0)