|
55 | 55 |
|
56 | 56 |
|
57 | 57 |
|
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 | | - |
158 | 58 | """ |
159 | 59 | $SIGNATURES |
160 | 60 |
|
|
331 | 231 | # approxConvOnElements!(ccwl, allelements[count]) |
332 | 232 |
|
333 | 233 |
|
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 |
342 | 234 |
|
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 |
357 | 235 |
|
358 | 236 | """ |
359 | 237 | $(SIGNATURES) |
|
0 commit comments