From 4e7658e73f36ec1ac41e7ffe75ec951d30536052 Mon Sep 17 00:00:00 2001 From: Johannes Terblanche Date: Fri, 6 Oct 2023 15:05:03 +0200 Subject: [PATCH 1/2] Fix extra allocations in get_gradient!'s jacobian --- src/plans/nonlinear_least_squares_plan.jl | 7 +++++-- src/solvers/LevenbergMarquardt.jl | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/plans/nonlinear_least_squares_plan.jl b/src/plans/nonlinear_least_squares_plan.jl index 69ae0dfee4..130b6604dc 100644 --- a/src/plans/nonlinear_least_squares_plan.jl +++ b/src/plans/nonlinear_least_squares_plan.jl @@ -99,10 +99,13 @@ function get_gradient!( end function get_gradient!( - M::AbstractManifold, X, nlso::NonlinearLeastSquaresObjective{InplaceEvaluation}, p + M::AbstractManifold, + X, + nlso::NonlinearLeastSquaresObjective{InplaceEvaluation}, + p, + Jval = zeros(nlso.num_components, manifold_dimension(M)) ) basis_p = _maybe_get_basis(M, p, nlso.jacobian_tangent_basis) - Jval = zeros(nlso.num_components, manifold_dimension(M)) nlso.jacobian!!(M, Jval, p; basis_domain=basis_p) residual_values = zeros(nlso.num_components) nlso.f(M, residual_values, p) diff --git a/src/solvers/LevenbergMarquardt.jl b/src/solvers/LevenbergMarquardt.jl index 5a4405fa1b..324517be17 100644 --- a/src/solvers/LevenbergMarquardt.jl +++ b/src/solvers/LevenbergMarquardt.jl @@ -207,7 +207,7 @@ function initialize_solver!( lms::LevenbergMarquardtState, ) where {mT<:AbstractManifold} get_objective(dmp).f(get_manifold(dmp), lms.residual_values, lms.p) - lms.X = get_gradient(dmp, lms.p) + get_gradient!(dmp, lms.X, lms.p, lms.jacF) return lms end From c552eb335cda5701d8b577cf8ce51bf4ccf49d1a Mon Sep 17 00:00:00 2001 From: Johannes Terblanche Date: Fri, 6 Oct 2023 15:29:59 +0200 Subject: [PATCH 2/2] fix fromat --- src/plans/nonlinear_least_squares_plan.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/plans/nonlinear_least_squares_plan.jl b/src/plans/nonlinear_least_squares_plan.jl index 130b6604dc..730e4536d4 100644 --- a/src/plans/nonlinear_least_squares_plan.jl +++ b/src/plans/nonlinear_least_squares_plan.jl @@ -99,11 +99,11 @@ function get_gradient!( end function get_gradient!( - M::AbstractManifold, + M::AbstractManifold, X, nlso::NonlinearLeastSquaresObjective{InplaceEvaluation}, p, - Jval = zeros(nlso.num_components, manifold_dimension(M)) + Jval=zeros(nlso.num_components, manifold_dimension(M)), ) basis_p = _maybe_get_basis(M, p, nlso.jacobian_tangent_basis) nlso.jacobian!!(M, Jval, p; basis_domain=basis_p)