Skip to content

Commit 71a8f37

Browse files
authored
Merge pull request #1728 from JuliaRobotics/23Q3/refac/paramfiles
better organize src files
2 parents 1061dbb + 6c75ee9 commit 71a8f37

18 files changed

+154
-133
lines changed

src/Deprecated.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,17 @@ end
124124
## Deprecate code below before v0.35
125125
##==============================================================================
126126

127+
# should probably deprecate the abstract type approach?
128+
abstract type _AbstractThreadModel end
129+
130+
"""
131+
$(TYPEDEF)
132+
"""
133+
struct SingleThreaded <: _AbstractThreadModel end
134+
# """
135+
# $(TYPEDEF)
136+
# """
137+
# struct MultiThreaded <: _AbstractThreadModel end
127138

128139

129140
function _solveLambdaNumeric(

src/IncrementalInference.jl

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ using Logging
6060
using PrecompileTools
6161

6262
# bringing in BSD 3-clause ccolamd
63-
include("ccolamd.jl")
63+
include("services/ccolamd.jl")
6464
using SuiteSparse.CHOLMOD: SuiteSparse_long # For CCOLAMD constraints.
6565
using .Ccolamd
6666

@@ -120,23 +120,29 @@ include("ExportAPI.jl")
120120
# FIXME, move up to DFG
121121
# abstract type AbstractManifoldMinimize <: AbstractRelative end
122122

123-
#
124-
include("ManifoldsExtentions.jl")
123+
124+
125125
# regular
126126
include("entities/SolverParams.jl")
127127

128128
include("entities/HypoRecipe.jl")
129+
include("entities/CalcFactor.jl")
129130
include("entities/FactorOperationalMemory.jl")
130131

131132
include("Factors/GenericMarginal.jl")
132133
# Special belief types for sampling as a distribution
133134
include("entities/AliasScalarSampling.jl")
134135
include("entities/OptionalDensities.jl")
135136
include("entities/BeliefTypes.jl")
137+
138+
#
139+
include("manifolds/services/ManifoldsExtentions.jl")
140+
include("manifolds/services/ManifoldSampling.jl")
141+
136142
include("entities/FactorGradients.jl")
137143

138144
# Statistics helpers on manifolds
139-
include("VariableStatistics.jl")
145+
include("services/VariableStatistics.jl")
140146

141147
# factors needed for belief propagation on the tree
142148
include("Factors/MsgPrior.jl")
@@ -201,44 +207,44 @@ include("services/ExplicitDiscreteMarginalizations.jl")
201207
include("services/EvalFactor.jl")
202208
include("services/ApproxConv.jl")
203209

204-
# FIXME CONSOLIDATE
205-
include("ConsolidateParametricRelatives.jl")
206210

207211
include("services/GraphProductOperations.jl")
208212
include("services/SolveTree.jl")
209213
include("services/TetherUtils.jl")
210214
include("services/TreeDebugTools.jl")
211215
include("CliqueStateMachine/services/CliqStateMachineUtils.jl")
212216

217+
# FIXME CONSOLIDATE
218+
include("parametric/services/ConsolidateParametricRelatives.jl")
213219
#EXPERIMENTAL parametric
214-
include("ParametricCSMFunctions.jl")
215-
include("ParametricUtils.jl")
216-
include("ParametricManoptDev.jl")
220+
include("parametric/services/ParametricCSMFunctions.jl")
221+
include("parametric/services/ParametricUtils.jl")
222+
include("parametric/services/ParametricOptim.jl")
223+
include("parametric/services/ParametricManoptDev.jl")
217224
include("services/MaxMixture.jl")
218225

219226
#X-stroke
220227
include("CliqueStateMachine/services/CliqueStateMachine.jl")
221228

222-
include("CanonicalGraphExamples.jl")
229+
include("services/CanonicalGraphExamples.jl")
223230

224231
include("services/AdditionalUtils.jl")
225-
include("SolverAPI.jl")
232+
include("services/SolverAPI.jl")
226233

227234
# Symbolic tree analysis files.
228-
include("AnalysisTools.jl")
235+
include("services/AnalysisTools.jl")
229236

230-
include("ManifoldSampling.jl")
231237

232238
# deprecation legacy support
233239
include("Deprecated.jl")
234240

235241
exportimg(pl) = error("Please do `using Gadfly` to allow image export.")
236242
function __init__()
237243
@require InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240" include(
238-
"RequireInteractiveUtils.jl",
244+
"services/RequireInteractiveUtils.jl",
239245
)
240246
@require Gadfly = "c91e804a-d5a3-530f-b6f0-dfbca275c004" include(
241-
"EmbeddedPlottingUtils.jl",
247+
"services/EmbeddedPlottingUtils.jl",
242248
)
243249
@require DifferentialEquations = "0c46a032-eb83-5123-abaf-570d42b7fbaa" include(
244250
"ODE/DERelative.jl",

src/entities/CalcFactor.jl

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
2+
abstract type AbstractMaxMixtureSolver end
3+
4+
5+
"""
6+
$TYPEDEF
7+
8+
User factor interface method for computing the residual values of factors.
9+
10+
Notes
11+
- Also see #467 on API consolidation
12+
13+
```julia
14+
function (cf::CalcFactor{<:LinearRelative})(res::AbstractVector{<:Real}, z, xi, xj)
15+
cf.variablelist
16+
cf.cache
17+
# generic on-manifold residual function
18+
return distance(z, distance(xj, xi))
19+
end
20+
```
21+
22+
DevNotes
23+
- Follow the Github project in IIF to better consolidate CCW FMD CPT CF CFM
24+
25+
Related
26+
27+
[`CalcFactorMahalanobis`](@ref), [`CommonConvWrapper`](@ref)
28+
"""
29+
struct CalcFactor{
30+
FT <: AbstractFactor,
31+
X,
32+
C,
33+
VT <: Tuple,
34+
M <: AbstractManifold
35+
}
36+
""" the interface compliant user object functor containing the data and logic """
37+
factor::FT
38+
""" what is the sample (particle) id for which the residual is being calculated """
39+
_sampleIdx::Int
40+
""" legacy support for variable values old functor residual functions.
41+
TBD, this is still being used by DERelative factors. """
42+
_legacyParams::X
43+
""" allow threading for either sampling or residual calculations (workaround for thread yield issue) """
44+
_allowThreads::Bool
45+
""" user cache of arbitrary type, overload the [`preambleCache`](@ref) function. NOT YET THREADSAFE """
46+
cache::C
47+
48+
## TODO Consolidation WIP with FactorMetadata
49+
# full list of variables connected to the factor
50+
# TODO make sure this list is of the active hypo only
51+
fullvariables::VT # Vector{<:DFGVariable} # FIXME change to tuple for better type stability
52+
# which index is being solved for?
53+
solvefor::Int
54+
manifold::M
55+
end
56+
57+
58+
59+
"""
60+
$TYPEDEF
61+
62+
Internal parametric extension to [`CalcFactor`](@ref) used for buffering measurement and calculating Mahalanobis distance
63+
64+
Related
65+
66+
[`CalcFactor`](@ref)
67+
"""
68+
struct CalcFactorMahalanobis{N, D, L, S <: Union{Nothing, AbstractMaxMixtureSolver}}
69+
faclbl::Symbol
70+
calcfactor!::CalcFactor
71+
varOrder::Vector{Symbol}
72+
meas::NTuple{N, <:AbstractArray}
73+
::NTuple{N, SMatrix{D, D, Float64, L}}
74+
specialAlg::S
75+
end
76+
77+
78+
79+
80+
struct CalcFactorManopt{
81+
D,
82+
L,
83+
FT <: AbstractFactor,
84+
M <: AbstractManifold,
85+
MEAS <: AbstractArray,
86+
}
87+
faclbl::Symbol
88+
calcfactor!::CalcFactor{FT, Nothing, Nothing, Tuple{}, M}
89+
varOrder::Vector{Symbol}
90+
varOrderIdxs::Vector{Int}
91+
meas::MEAS
92+
::SMatrix{D, D, Float64, L}
93+
sqrt_iΣ::SMatrix{D, D, Float64, L}
94+
end
95+
96+

src/entities/FactorOperationalMemory.jl

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,4 @@
11

2-
"""
3-
$TYPEDEF
4-
5-
User factor interface method for computing the residual values of factors.
6-
7-
Notes
8-
- Also see #467 on API consolidation
9-
10-
```julia
11-
function (cf::CalcFactor{<:LinearRelative})(res::AbstractVector{<:Real}, z, xi, xj)
12-
cf.variablelist
13-
cf.cache
14-
# generic on-manifold residual function
15-
return distance(z, distance(xj, xi))
16-
end
17-
```
18-
19-
DevNotes
20-
- Follow the Github project in IIF to better consolidate CCW FMD CPT CF CFM
21-
22-
Related
23-
24-
[`CalcFactorMahalanobis`](@ref), [`CommonConvWrapper`](@ref)
25-
"""
26-
struct CalcFactor{
27-
FT <: AbstractFactor,
28-
X,
29-
C,
30-
VT <: Tuple,
31-
M <: AbstractManifold
32-
}
33-
""" the interface compliant user object functor containing the data and logic """
34-
factor::FT
35-
""" what is the sample (particle) id for which the residual is being calculated """
36-
_sampleIdx::Int
37-
""" legacy support for variable values old functor residual functions.
38-
TBD, this is still being used by DERelative factors. """
39-
_legacyParams::X
40-
""" allow threading for either sampling or residual calculations (workaround for thread yield issue) """
41-
_allowThreads::Bool
42-
""" user cache of arbitrary type, overload the [`preambleCache`](@ref) function. NOT YET THREADSAFE """
43-
cache::C
44-
45-
## TODO Consolidation WIP with FactorMetadata
46-
# full list of variables connected to the factor
47-
# TODO make sure this list is of the active hypo only
48-
fullvariables::VT # Vector{<:DFGVariable} # FIXME change to tuple for better type stability
49-
# which index is being solved for?
50-
solvefor::Int
51-
manifold::M
52-
end
53-
54-
# should probably deprecate the abstract type approach?
55-
abstract type _AbstractThreadModel end
56-
57-
"""
58-
$(TYPEDEF)
59-
"""
60-
struct SingleThreaded <: _AbstractThreadModel end
61-
"""
62-
$(TYPEDEF)
63-
"""
64-
struct MultiThreaded <: _AbstractThreadModel end
65-
662

673

684
"""
File renamed without changes.

src/ManifoldsExtentions.jl renamed to src/manifolds/services/ManifoldsExtentions.jl

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,6 @@ function Optim.project_tangent!(M::ManifoldWrapper, g, x)
2323
return g
2424
end
2525

26-
# experimental
27-
function optimizeManifold_FD(
28-
M::AbstractManifold,
29-
cost::Function,
30-
x0::AbstractArray;
31-
algorithm = Optim.ConjugateGradient(; manifold=ManifoldWrapper(M))
32-
)
33-
# finitediff setup
34-
r_backend = ManifoldDiff.TangentDiffBackend(
35-
ManifoldDiff.FiniteDifferencesBackend()
36-
)
37-
38-
## finitediff gradient (non-manual)
39-
function costgrad_FD!(X,p)
40-
X .= ManifoldDiff.gradient(M, cost, p, r_backend)
41-
X
42-
end
43-
44-
Optim.optimize(cost, costgrad_FD!, x0, algorithm)
45-
end
46-
4726

4827
## ================================================================================================
4928
## AbstractPowerManifold with N as field to avoid excessive compiling time.

src/ParametricManoptDev.jl renamed to src/parametric/services/ParametricManoptDev.jl

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,7 @@ using SparseArrays
99

1010
##
1111

12-
struct CalcFactorManopt{
13-
D,
14-
L,
15-
FT <: AbstractFactor,
16-
M <: AbstractManifold,
17-
MEAS <: AbstractArray,
18-
}
19-
faclbl::Symbol
20-
calcfactor!::CalcFactor{FT, Nothing, Nothing, Tuple{}, M}
21-
varOrder::Vector{Symbol}
22-
varOrderIdxs::Vector{Int}
23-
meas::MEAS
24-
::SMatrix{D, D, Float64, L}
25-
sqrt_iΣ::SMatrix{D, D, Float64, L}
26-
end
12+
2713

2814
function CalcFactorManopt(fct::DFGFactor, varIntLabel)
2915
fac_func = getFactorType(fct)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
# experimental
3+
function optimizeManifold_FD(
4+
M::AbstractManifold,
5+
cost::Function,
6+
x0::AbstractArray;
7+
algorithm = Optim.ConjugateGradient(; manifold=ManifoldWrapper(M))
8+
)
9+
# finitediff setup
10+
r_backend = ManifoldDiff.TangentDiffBackend(
11+
ManifoldDiff.FiniteDifferencesBackend()
12+
)
13+
14+
## finitediff gradient (non-manual)
15+
function costgrad_FD!(X,p)
16+
X .= ManifoldDiff.gradient(M, cost, p, r_backend)
17+
X
18+
end
19+
20+
Optim.optimize(cost, costgrad_FD!, x0, algorithm)
21+
end

0 commit comments

Comments
 (0)