Skip to content

Commit 6191e29

Browse files
authored
Merge pull request #1334 from JuliaRobotics/21Q3/enh/calcpertrela
better organize factor ops memory as entities
2 parents 9650893 + 76a1fd8 commit 6191e29

20 files changed

+1019
-924
lines changed

src/ApproxConv.jl

Lines changed: 0 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -55,106 +55,6 @@ end
5555

5656

5757

58-
"""
59-
$(SIGNATURES)
60-
61-
Prepare a common functor computation object `prepareCommonConvWrapper{T}` containing
62-
the user factor functor along with additional variables and information using during
63-
approximate convolution computations.
64-
65-
DevNotes
66-
- TODO consolidate with others, see https://github.com/JuliaRobotics/IncrementalInference.jl/projects/6
67-
"""
68-
function prepareCommonConvWrapper!( F_::Type{<:AbstractRelative},
69-
ccwl::CommonConvWrapper{F},
70-
Xi::AbstractVector{<:DFGVariable},
71-
solvefor::Symbol,
72-
N::Int;
73-
needFreshMeasurements::Bool=true,
74-
solveKey::Symbol=:default ) where {F <: AbstractFactor}
75-
#
76-
77-
# FIXME, order of fmd ccwl cf are a little weird and should be revised.
78-
pttypes = getVariableType.(Xi) .|> getPointType
79-
PointType = 0 < length(pttypes) ? pttypes[1] : Vector{Float64}
80-
81-
#FIXME, see #1321
82-
vecPtsArr = Vector{Vector{Any}}()
83-
84-
#TODO some better consolidate is needed
85-
ccwl.vartypes = typeof.(getVariableType.(Xi))
86-
87-
# FIXME maxlen should parrot N (barring multi-/nullhypo issues)
88-
maxlen, sfidx, mani = prepareparamsarray!(vecPtsArr, Xi, solvefor, N, solveKey=solveKey)
89-
90-
# FIXME ON FIRE, what happens if this is a partial dimension factor? See #1246
91-
ccwl.xDim = getDimension(getVariableType(Xi[sfidx]))
92-
# ccwl.xDim = length(vecPtsArr[sfidx][1])
93-
# TODO should be selecting for the correct multihypothesis mode
94-
95-
# setup the partial or complete decision variable dimensions for this ccwl object
96-
# NOTE perhaps deconv has changed the decision variable list, so placed here during consolidation phase
97-
# TODO, should this not be part of `prepareCommonConvWrapper` -- only here do we look for .partial
98-
_setCCWDecisionDimsConv!(ccwl)
99-
100-
# SHOULD WE SLICE ARR DOWN BY PARTIAL DIMS HERE (OR LATER)?
101-
ccwl.params = vecPtsArr # map( ar->view(ar, ccwl.partialDims, :), vecPtsArr)
102-
103-
# get factor metadata -- TODO, populate, also see #784
104-
fmd = FactorMetadata(Xi, getLabel.(Xi), ccwl.params, solvefor, nothing)
105-
106-
# TODO consolidate with ccwl??
107-
# FIXME do not divert Mixture for sampling
108-
# cf = _buildCalcFactorMixture(ccwl, fmd, 1, ccwl.measurement, ccwl.params) # TODO perhaps 0 is safer
109-
cf = CalcFactor( ccwl.usrfnc!, fmd, 0, length(ccwl.measurement), ccwl.measurement, ccwl.params)
110-
111-
# get variable node data
112-
vnds = Xi
113-
114-
# option to disable fresh samples
115-
if needFreshMeasurements
116-
# TODO refactor
117-
ccwl.measurement = sampleFactor(cf, maxlen)
118-
# sampleFactor!(ccwl, maxlen, fmd, vnds)
119-
end
120-
121-
122-
ccwl.zDim = calcZDim(CalcFactor(ccwl))
123-
# if ccwl.specialzDim
124-
# ccwl.zDim = ccwl.usrfnc!.zDim[sfidx]
125-
# else
126-
# end
127-
ccwl.varidx = sfidx
128-
129-
# set each CPT
130-
for thrid in 1:Threads.nthreads()
131-
cpt_ = ccwl.cpt[thrid]
132-
cpt_.X = ccwl.params[sfidx]
133-
134-
# used in ccw functor for AbstractRelativeMinimize
135-
# TODO JT - Confirm it should be updated here. Testing in prepgenericconvolution
136-
resize!(cpt_.res, ccwl.zDim)
137-
fill!(cpt_.res, 0.0)
138-
end
139-
140-
# calculate new gradients perhaps
141-
# J = ccwl.gradients(measurement..., pts...)
142-
143-
return sfidx, maxlen, mani
144-
end
145-
146-
147-
function prepareCommonConvWrapper!( ccwl::Union{CommonConvWrapper{F},
148-
CommonConvWrapper{Mixture{N_,F,S,T}}},
149-
Xi::AbstractVector{<:DFGVariable},
150-
solvefor::Symbol,
151-
N::Int;
152-
kw... ) where {N_,F<:AbstractRelative,S,T}
153-
#
154-
prepareCommonConvWrapper!(F, ccwl, Xi, solvefor, N; kw...)
155-
end
156-
157-
15858
"""
15959
$SIGNATURES
16060
@@ -331,29 +231,7 @@ end
331231
# approxConvOnElements!(ccwl, allelements[count])
332232

333233

334-
"""
335-
$SIGNATURES
336-
Internal method to set which dimensions should be used as the decision variables for later numerical optimization.
337-
"""
338-
function _setCCWDecisionDimsConv!(ccwl::Union{CommonConvWrapper{F},
339-
CommonConvWrapper{Mixture{N_,F,S,T}}} ) where {N_,F<:Union{AbstractManifoldMinimize, AbstractRelativeMinimize, AbstractRelativeRoots, AbstractPrior},S,T}
340-
#
341-
# return nothing
342234

343-
p = if ccwl.partial
344-
Int32[ccwl.usrfnc!.partial...]
345-
else
346-
Int32[1:ccwl.xDim...]
347-
end
348-
349-
ccwl.partialDims = (p)
350-
# NOTE should only be done in the constructor
351-
for thrid in 1:Threads.nthreads()
352-
length(ccwl.cpt[thrid].p) != length(p) ? resize!(ccwl.cpt[thrid].p, length(p)) : nothing
353-
ccwl.cpt[thrid].p .= p # SVector... , see ccw.partialDims
354-
end
355-
nothing
356-
end
357235

358236
"""
359237
$(SIGNATURES)

src/CalcFactor.jl

Lines changed: 0 additions & 140 deletions
This file was deleted.

src/Deprecated.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ end
2525
## Deprecate code below before v0.27
2626
##==============================================================================
2727

28-
@deprecate calcPerturbationFromVariable( fgc::FactorGradientsCached!, fromVar::Int, infoPerCoord::AbstractVector;tol::Real=0.02*fgc._h ) calcPerturbationFromVariable(fgc, [fromVar => infoPerCoord;], tol=tol )
29-
3028
@deprecate findRelatedFromPotential(w...;kw...) (calcProposalBelief(w...;kw...),)
3129

3230
# function generateNullhypoEntropy( val::AbstractMatrix{<:Real},
@@ -135,6 +133,8 @@ end
135133
## Deprecate code below before v0.26
136134
##==============================================================================
137135

136+
@deprecate calcPerturbationFromVariable( fgc::FactorGradientsCached!, fromVar::Int, infoPerCoord::AbstractVector;tol::Real=0.02*fgc._h ) calcPerturbationFromVariable(fgc, [fromVar => infoPerCoord;], tol=tol )
137+
138138
function getVal(vA::Vector{<:DFGVariable}, solveKey::Symbol=:default)
139139
@error "getVal(::Vector{DFGVariable}) is obsolete, use getVal.(DFGVariable) instead."
140140
# len = length(vA)

0 commit comments

Comments
 (0)