Skip to content

Commit 7068b44

Browse files
committed
struct defaults for CCW
1 parent e60fe16 commit 7068b44

File tree

2 files changed

+59
-58
lines changed

2 files changed

+59
-58
lines changed

src/entities/FactorOperationalMemory.jl

Lines changed: 59 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ Related
8080
8181
[`CalcFactor`](@ref), [`CalcFactorMahalanobis`](@ref)
8282
"""
83-
struct CommonConvWrapper{
83+
Base.@kwdef struct CommonConvWrapper{
8484
T <: AbstractFactor,
8585
VT <: Tuple,
8686
NTP <: Tuple,
@@ -101,40 +101,84 @@ struct CommonConvWrapper{
101101
to each hypothesis evaluation event on user function via CalcFactor, #1321 """
102102
varValsAll::NTP
103103
""" dummy cache value to be deep copied later for each of the CalcFactor instances """
104-
dummyCache::CT
104+
dummyCache::CT = nothing
105105
# derived config parameters for this factor
106106
""" Factor manifold definition for frequent use (not the variables manifolds) """
107-
manifold::AM
107+
manifold::AM = getManifold(usrfnc!)
108108
""" Which dimensions does this factor influence. Sensitive (mutable) to both which 'solvefor index' variable and whether the factor is partial dimension """
109-
partialDims::Vector{<:Integer}
109+
partialDims::Vector{<:Integer} = collect(1:manifold_dimension(manifold))
110110
""" is this a partial constraint as defined by the existance of factor field `.partial::Tuple` """
111-
partial::Bool
111+
partial::Bool = false
112112
""" probability that this factor is wholly incorrect and should be ignored during solving """
113-
nullhypo::Float64
113+
nullhypo::Float64 = 0.0
114114
""" inflationSpread particular to this factor (by how much to dispurse the belief initial values before numerical optimization is run). Analogous to stochastic search """
115-
inflation::Float64
115+
inflation::Float64 = 3.0
116116
# multihypo specific field containers for recipe of hypotheses to compute
117117
""" multi hypothesis settings #NOTE no need for a parameter as type is known from `parseusermultihypo` """
118-
hypotheses::HP
118+
hypotheses::HP = nothing
119119
""" categorical to select which hypothesis is being considered during convolution operation """
120-
certainhypo::CH
120+
certainhypo::CH = nothing
121121
""" subsection indices to select which params should be used for this hypothesis evaluation """
122-
activehypo::Vector{Int}
122+
activehypo::Vector{Int} = collect(1:length(varValsAll))
123123
# buffers and indices to point numerical computations to specific memory locations
124124
""" user defined measurement values for each approxConv operation
125125
FIXME make type stable, JT should now be type stable if rest works.
126126
SUPER IMPORTANT, if prior=>point or relative=>tangent, see #1661
127127
can be a Vector{<:Tuple} or more direct Vector{<: pointortangenttype} """
128-
measurement::Vector{MT}
128+
measurement::Vector{MT} = Vector(Vector{Float64}())
129129
""" which index is being solved for in params? """
130-
varidx::Base.RefValue{Int}
130+
varidx::Base.RefValue{Int} = Ref(1)
131131
""" Consolidation from CPT, the actual particle being solved at this moment """
132-
particleidx::Base.RefValue{Int}
132+
particleidx::Base.RefValue{Int} = Ref(1)
133133
""" working memory to store residual for optimization routines """
134-
res::Vector{Float64}
134+
res::Vector{Float64} = zeros(manifold_dimension(manifold))
135135
""" experimental feature to embed gradient calcs with ccw """
136-
_gradients::G
136+
_gradients::G = nothing
137137
end
138138

139139

140+
function CommonConvWrapper(
141+
usrfnc::T,
142+
fullvariables, #::Tuple ::Vector{<:DFGVariable};
143+
varValsAll::Tuple,
144+
X::AbstractVector{P}; #TODO remove X completely
145+
# xDim::Int = size(X, 1),
146+
userCache::CT = nothing,
147+
manifold = getManifold(usrfnc),
148+
partialDims::AbstractVector{<:Integer} = 1:length(X),
149+
partial::Bool = false,
150+
nullhypo::Real = 0,
151+
inflation::Real = 3.0,
152+
hypotheses::H = nothing,
153+
certainhypo = nothing,
154+
activehypo = collect(1:length(varValsAll)),
155+
measurement::AbstractVector = Vector(Vector{Float64}()),
156+
varidx::Int = 1,
157+
particleidx::Int = 1,
158+
res::AbstractVector{<:Real} = zeros(manifold_dimension(manifold)), # zDim
159+
gradients = nothing,
160+
) where {T <: AbstractFactor, P, H, CT}
161+
#
162+
return CommonConvWrapper(
163+
usrfnc,
164+
tuple(fullvariables...),
165+
varValsAll,
166+
userCache,
167+
manifold,
168+
partialDims,
169+
partial,
170+
# xDim,
171+
float(nullhypo),
172+
float(inflation),
173+
hypotheses,
174+
certainhypo,
175+
activehypo,
176+
measurement,
177+
Ref(varidx),
178+
Ref(particleidx),
179+
res,
180+
gradients,
181+
)
182+
end
183+
140184
#

src/services/CalcFactor.jl

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -189,49 +189,6 @@ end
189189
## FactorOperationalMemory helper constructors
190190
## =============================================================================================
191191

192-
function CommonConvWrapper(
193-
usrfnc::T,
194-
fullvariables, #::Tuple ::Vector{<:DFGVariable};
195-
varValsAll::Tuple,
196-
X::AbstractVector{P}; #TODO remove X completely
197-
# xDim::Int = size(X, 1),
198-
userCache::CT = nothing,
199-
manifold = getManifold(usrfnc),
200-
partialDims::AbstractVector{<:Integer} = 1:length(X),
201-
partial::Bool = false,
202-
nullhypo::Real = 0,
203-
inflation::Real = 3.0,
204-
hypotheses::H = nothing,
205-
certainhypo = nothing,
206-
activehypo = collect(1:length(varValsAll)),
207-
measurement::AbstractVector = Vector(Vector{Float64}()),
208-
varidx::Int = 1,
209-
particleidx::Int = 1,
210-
res::AbstractVector{<:Real} = zeros(manifold_dimension(manifold)), # zDim
211-
gradients = nothing,
212-
) where {T <: AbstractFactor, P, H, CT}
213-
#
214-
return CommonConvWrapper(
215-
usrfnc,
216-
tuple(fullvariables...),
217-
varValsAll,
218-
userCache,
219-
manifold,
220-
partialDims,
221-
partial,
222-
# xDim,
223-
Float64(nullhypo),
224-
inflation,
225-
hypotheses,
226-
certainhypo,
227-
activehypo,
228-
measurement,
229-
Ref(varidx),
230-
Ref(particleidx),
231-
res,
232-
gradients,
233-
)
234-
end
235192

236193
# the same as legacy, getManifold(ccwl.usrfnc!)
237194
getManifold(ccwl::CommonConvWrapper) = ccwl.manifold

0 commit comments

Comments
 (0)