Skip to content

Commit 69deed7

Browse files
committed
move factor operational types to entities
1 parent aedd3cd commit 69deed7

File tree

3 files changed

+106
-80
lines changed

3 files changed

+106
-80
lines changed

src/ParametricUtils.jl

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -144,18 +144,7 @@ end
144144
## Parametric solve with Mahalanobis distance - CalcFactor
145145
## ================================================================================================
146146

147-
"""
148-
$TYPEDEF
149147

150-
Internal parametric extension to [`CalcFactor`](@ref) used for buffering measurement and calculating Mahalanobis distance
151-
"""
152-
struct CalcFactorMahalanobis{CF<:CalcFactor, S, N}
153-
calcfactor!::CF
154-
varOrder::Vector{Symbol}
155-
meas::NTuple{N, <:AbstractVector{Float64}}
156-
::NTuple{N, Matrix{Float64}}
157-
specialAlg::S
158-
end
159148

160149
getFactorMechanics(f::AbstractFactor) = f
161150
getFactorMechanics(f::Mixture) = f.mechanics

src/entities/FactorOperationalMemory.jl

Lines changed: 36 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ end
2424
```
2525
2626
DevNotes
27-
- See IIF Project to consolidate CCW, CF, FMD, CPT
27+
- Follow the Github project in IIF to better consolidate CCW FMD CPT CF CFM
2828
2929
Related
3030
31-
[`CommonConvWrapper`](@ref), [`FactorMetadata`](@ref), [`ConvPerThread`](@ref)
31+
[`CalcFactorMahalanobis`](@ref), [`CommonConvWrapper`](@ref), [`FactorMetadata`](@ref), [`ConvPerThread`](@ref)
3232
"""
3333
struct CalcFactor{T <: AbstractFactor, M, P <: Union{<:Tuple,Nothing}, X <: AbstractVector}
3434
# the interface compliant user object functor containing the data and logic
@@ -46,6 +46,23 @@ struct CalcFactor{T <: AbstractFactor, M, P <: Union{<:Tuple,Nothing}, X <: Abst
4646
end
4747

4848

49+
"""
50+
$TYPEDEF
51+
52+
Internal parametric extension to [`CalcFactor`](@ref) used for buffering measurement and calculating Mahalanobis distance
53+
54+
Related
55+
56+
[`CalcFactor`](@ref)
57+
"""
58+
struct CalcFactorMahalanobis{CF<:CalcFactor, S, N}
59+
calcfactor!::CF
60+
varOrder::Vector{Symbol}
61+
meas::NTuple{N, <:AbstractVector{Float64}}
62+
::NTuple{N, Matrix{Float64}}
63+
specialAlg::S
64+
end
65+
4966

5067
abstract type _AbstractThreadModel end
5168

@@ -70,7 +87,7 @@ Notes
7087
7188
DevNotes
7289
- TODO why not just a NamedTuple? Perhaps part of #467
73-
- TODO better consolidate with CCW, CPT, CalcFactor
90+
- Follow the Github project in IIF to better consolidate CCW FMD CPT CF CFM
7491
- TODO standardize -- #927, #1025, #784, #692, #640
7592
- TODO make immutable #825
7693
"""
@@ -121,30 +138,25 @@ mutable struct ConvPerThread{R,F<:FactorMetadata,P}
121138
end
122139

123140

124-
function ConvPerThread( X::AbstractVector{P},
125-
zDim::Int,
126-
factormetadata::FactorMetadata;
127-
particleidx::Int=1,
128-
activehypo= 1:length(params),
129-
p::AbstractVector{<:Integer}=collect(1:1),
130-
perturb=zeros(zDim),
131-
res=zeros(zDim),
132-
thrid_ = 0 ) where P
133-
#
134-
return ConvPerThread{typeof(res), typeof(factormetadata), Any}( thrid_,
135-
particleidx,
136-
factormetadata,
137-
Int[activehypo;],
138-
Int[p...;],
139-
perturb,
140-
X,
141-
res )
142-
end
143-
144-
145141

146142
"""
147143
$(TYPEDEF)
144+
145+
Main factor memory container used during inference operations.
146+
147+
Notes
148+
- CCW does not get serialized / persisted
149+
- At writing, the assumption is there is just one CCW per factor
150+
- Any multithreaded design needs to happens as sub-constainers inside CCW or otherwise, to carry separate memory.
151+
- Since #467, `CalcFactor` is the only type 'seen by user' during `getSample` or function residual calculations `(cf::CalcFactor{<:MyFactor})`, s.t. `MyFactor <: AbstractRelative___`
152+
- There also exists a `CalcFactorMahalanobis` for parameteric computations using as much of the same mechanics as possible.
153+
154+
DevNotes
155+
- Follow the Github project in IIF to better consolidate CCW FMD CPT CF CFM
156+
157+
Related
158+
159+
[`CalcFactor`](@ref), [`CalcFactorMahalanobis`](@ref), [`FactorMetadata`](@ref), [`ConvPerThread`](@ref)
148160
"""
149161
mutable struct CommonConvWrapper{ T<:FunctorInferenceType,
150162
H<:Union{Nothing, Distributions.Categorical},
@@ -186,50 +198,5 @@ mutable struct CommonConvWrapper{ T<:FunctorInferenceType,
186198
end
187199

188200

189-
function CommonConvWrapper( fnc::T,
190-
X::AbstractVector{P},
191-
zDim::Int,
192-
params::AbstractVector{<:AbstractVector{Q}},
193-
factormetadata::FactorMetadata;
194-
specialzDim::Bool=false,
195-
partial::Bool=false,
196-
hypotheses::H=nothing,
197-
certainhypo=nothing,
198-
activehypo= 1:length(params),
199-
nullhypo::Real=0,
200-
varidx::Int=1,
201-
measurement::Tuple=(Vector{Vector{Float64}}(),), # FIXME should not be a Matrix
202-
particleidx::Int=1,
203-
xDim::Int=size(X,1),
204-
partialDims::AbstractVector{<:Integer}=collect(1:size(X,1)), # TODO make this SVector, and name partialDims
205-
perturb=zeros(zDim),
206-
res::AbstractVector{<:Real}=zeros(zDim),
207-
threadmodel::Type{<:_AbstractThreadModel}=MultiThreaded,
208-
inflation::Real=3.0,
209-
vartypes=typeof.(getVariableType.(factormetadata.fullvariables)),
210-
gradients=nothing) where {T<:FunctorInferenceType,P,H,Q}
211-
#
212-
return CommonConvWrapper(fnc,
213-
xDim,
214-
zDim,
215-
specialzDim,
216-
partial,
217-
hypotheses,
218-
certainhypo,
219-
Float64(nullhypo),
220-
params,
221-
varidx,
222-
measurement,
223-
threadmodel,
224-
(i->ConvPerThread(X, zDim,factormetadata, particleidx=particleidx,
225-
activehypo=activehypo, p=partialDims,
226-
perturb=perturb, res=res )).(1:Threads.nthreads()),
227-
inflation,
228-
partialDims, # SVector(Int32.()...)
229-
DataType[vartypes...],
230-
gradients)
231-
end
232-
233-
234201

235202
#

src/services/CalcFactor.jl

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,74 @@ end
110110

111111

112112

113+
114+
function ConvPerThread( X::AbstractVector{P},
115+
zDim::Int,
116+
factormetadata::FactorMetadata;
117+
particleidx::Int=1,
118+
activehypo= 1:length(params),
119+
p::AbstractVector{<:Integer}=collect(1:1),
120+
perturb=zeros(zDim),
121+
res=zeros(zDim),
122+
thrid_ = 0 ) where P
123+
#
124+
return ConvPerThread{typeof(res), typeof(factormetadata), Any}( thrid_,
125+
particleidx,
126+
factormetadata,
127+
Int[activehypo;],
128+
Int[p...;],
129+
perturb,
130+
X,
131+
res )
132+
end
133+
134+
135+
136+
function CommonConvWrapper( fnc::T,
137+
X::AbstractVector{P},
138+
zDim::Int,
139+
params::AbstractVector{<:AbstractVector{Q}},
140+
factormetadata::FactorMetadata;
141+
specialzDim::Bool=false,
142+
partial::Bool=false,
143+
hypotheses::H=nothing,
144+
certainhypo=nothing,
145+
activehypo= 1:length(params),
146+
nullhypo::Real=0,
147+
varidx::Int=1,
148+
measurement::Tuple=(Vector{Vector{Float64}}(),), # FIXME should not be a Matrix
149+
particleidx::Int=1,
150+
xDim::Int=size(X,1),
151+
partialDims::AbstractVector{<:Integer}=collect(1:size(X,1)), # TODO make this SVector, and name partialDims
152+
perturb=zeros(zDim),
153+
res::AbstractVector{<:Real}=zeros(zDim),
154+
threadmodel::Type{<:_AbstractThreadModel}=MultiThreaded,
155+
inflation::Real=3.0,
156+
vartypes=typeof.(getVariableType.(factormetadata.fullvariables)),
157+
gradients=nothing) where {T<:FunctorInferenceType,P,H,Q}
158+
#
159+
return CommonConvWrapper(fnc,
160+
xDim,
161+
zDim,
162+
specialzDim,
163+
partial,
164+
hypotheses,
165+
certainhypo,
166+
Float64(nullhypo),
167+
params,
168+
varidx,
169+
measurement,
170+
threadmodel,
171+
(i->ConvPerThread(X, zDim,factormetadata, particleidx=particleidx,
172+
activehypo=activehypo, p=partialDims,
173+
perturb=perturb, res=res )).(1:Threads.nthreads()),
174+
inflation,
175+
partialDims, # SVector(Int32.()...)
176+
DataType[vartypes...],
177+
gradients)
178+
end
179+
180+
181+
182+
113183
#

0 commit comments

Comments
 (0)