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

Correct Cholesky factor to have positive diagonal #17

Merged
merged 1 commit into from
Nov 20, 2024

Conversation

THargreaves
Copy link
Contributor

A small tweak to fix #16.

Happy to make changes if requested.

Copy link
Member

@zsoerenm zsoerenm left a comment

Choose a reason for hiding this comment

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

Thank you for this lovely input.
I have some comments, what do you think?

src/srkf.jl Outdated
Comment on lines 24 to 34
function correct_cholesky_sign!(R)
R .= sign.(diag(R)) .* R
end
Copy link
Member

@zsoerenm zsoerenm Nov 6, 2024

Choose a reason for hiding this comment

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

This still allocates.
I asked for help with this and the Julia community got crazy again ;)
See https://discourse.julialang.org/t/why-does-a-sign-view-a-diagind-a-a-allocate/122332
So my suggestion is:

Suggested change
function correct_cholesky_sign!(R)
R .= sign.(diag(R)) .* R
end
function correct_cholesky_sign!(R)
for i in axes(R,1)
if R[i,i] < 0
R[i, :] = -R[i, :]
end
end
return R
end

src/srkf.jl Outdated
"""
correct_cholesky_sign(R)

Return a modify the Cholesky factor `R` with positive diagonals.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Return a modify the Cholesky factor `R` with positive diagonals.
The upper triangle R of the QR decomposition doesn't necessarily have positive
elements on the diagonal elements. However, when used in the context of
a Cholesky decomposition the diagonal elements need to be positive. Hence,
the function corrects the sign of the diagonal elements when necessary.

@zsoerenm zsoerenm merged commit 86231fc into JuliaGNSS:master Nov 20, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Forcing positive diagonals when performing QR decomposition for SRKF
2 participants