Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix extra allocations in get_gradient!'s jacobian #300

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/plans/nonlinear_least_squares_plan.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
kellertuer marked this conversation as resolved.
Show resolved Hide resolved
)
basis_p = _maybe_get_basis(M, p, nlso.jacobian_tangent_basis)
Jval = zeros(nlso.num_components, manifold_dimension(M))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is where all the allocations come from, in my case, I give a sparse jacobian as input.

nlso.jacobian!!(M, Jval, p; basis_domain=basis_p)
kellertuer marked this conversation as resolved.
Show resolved Hide resolved
residual_values = zeros(nlso.num_components)
nlso.f(M, residual_values, p)
Expand Down
2 changes: 1 addition & 1 deletion src/solvers/LevenbergMarquardt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
kellertuer marked this conversation as resolved.
Show resolved Hide resolved
return lms
end

Expand Down