Skip to content

Commit ebc4c85

Browse files
committed
Only inplace solve_RLM
1 parent 180d89d commit ebc4c85

File tree

1 file changed

+9
-45
lines changed

1 file changed

+9
-45
lines changed

src/ParametricManoptDev.jl

Lines changed: 9 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -185,52 +185,16 @@ function solve_RLM(
185185
fro_p = first.(getVal.(frontal_vars, solveKey = :parametric))
186186
sep_p::Vector{eltype(fro_p)} = first.(getVal.(fg, separators, solveKey = :parametric))
187187

188+
#cost and jacobian functions
189+
# cost function f: M->ℝᵈ for Riemannian Levenberg-Marquardt
190+
costF! = CostF_RLM!(calcfacs, fro_p, sep_p)
191+
# jacobian of function for Riemannian Levenberg-Marquardt
192+
jacF! = JacF_RLM!(MM, costF!)
193+
194+
num_components = length(jacF!.res)
188195

189-
if false
190-
# non-in-place version updated bolow to in-place
191-
fullp::Vector{eltype(fro_p)} = [fro_p; sep_p]
192-
# cost function f: M->ℝᵈ for Riemannian Levenberg-Marquardt
193-
function costF_RLM(M::AbstractManifold, p::Vector{T}) where T
194-
fullp[1:length(p)] .= p
195-
return Vector(mapreduce(f -> f(fullp), vcat, calcfacs))
196-
end
197-
198-
# jacobian of function for Riemannian Levenberg-Marquardt
199-
function jacF_RLM(
200-
M::AbstractManifold,
201-
p;
202-
basis_domain::AbstractBasis = DefaultOrthogonalBasis(),
203-
)
204-
X0 = zeros(manifold_dimension(M))
205-
J = FiniteDiff.finite_difference_jacobian(
206-
x -> costF_RLM(M, exp(M, p, get_vector(M, p, x, basis_domain))),
207-
X0,
208-
)
209-
# J = ForwardDiff.jacobian(
210-
# x -> costF_RLM(M, exp(M, p, get_vector(M, p, x, basis_domain))),
211-
# X0,
212-
# )
213-
return J
214-
end
215-
216-
# 0.296639 seconds (2.46 M allocations: 164.722 MiB, 12.83% gc time)
217-
p0 = deepcopy(fro_p)
218-
lm_r = LevenbergMarquardt(MM, costF_RLM, jacF_RLM, p0)
219-
220-
# 81.185117 seconds (647.20 M allocations: 41.680 GiB, 8.61% gc time)
221-
else
222-
# 74.420872 seconds (567.70 M allocations: 34.698 GiB, 8.30% gc time, 0.66% compilation time)
223-
#cost and jacobian functions
224-
# cost function f: M->ℝᵈ for Riemannian Levenberg-Marquardt
225-
costF! = CostF_RLM!(calcfacs, fro_p, sep_p)
226-
# jacobian of function for Riemannian Levenberg-Marquardt
227-
jacF! = JacF_RLM!(MM, costF!)
228-
229-
num_components = length(jacF!.res)
230-
231-
p0 = deepcopy(fro_p)
232-
lm_r = LevenbergMarquardt(MM, costF!, jacF!, p0, num_components; evaluation=InplaceEvaluation())
233-
end
196+
p0 = deepcopy(fro_p)
197+
lm_r = LevenbergMarquardt(MM, costF!, jacF!, p0, num_components; evaluation=InplaceEvaluation())
234198

235199
return vartypeslist, lm_r
236200
end

0 commit comments

Comments
 (0)