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

Fixes to adddiag #186

Merged
merged 6 commits into from
Oct 3, 2023
Merged

Fixes to adddiag #186

merged 6 commits into from
Oct 3, 2023

Conversation

olivierverdier
Copy link
Contributor

No description provided.

@codecov-commenter
Copy link

codecov-commenter commented Oct 2, 2023

Codecov Report

All modified lines are covered by tests ✅

Files Coverage Δ
src/addition.jl 50.00% <100.00%> (+4.76%) ⬆️
src/utils.jl 91.66% <100.00%> (ø)

📢 Thoughts on this report? Let us know!.

Copy link
Member

@devmotion devmotion left a comment

Choose a reason for hiding this comment

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

Can you add a test with an example that would be fixed by the PR? In its current form it's difficult to tell what the PR improves.

Generally, we would like to use _adddiag! here since _adddiag would lead to additional undesired allocations.

@olivierverdier
Copy link
Contributor Author

Yes, but _adddiag! is not implemented the way it is called (it needs a third parameter), so this line does not work (and was presumably never called nor tested?).

Here is a piece of code that shows the problem:

# PR version
my_add_1(a::PDiagMat, b::AbstractPDMat) = PDMat(PDMats._adddiag(Matrix(b), a.diag))
# alternative version
my_add_2(a::PDiagMat, b::AbstractPDMat) = PDMat(PDMats._adddiag!(Matrix(b), a.diag, 1))
# current version
my_add_3(a::PDiagMat, b::AbstractPDMat) = PDMat(PDMats._adddiag!(Matrix(b), a.diag))

a = PDiagMat([1, 2])
A = randn(2, 2)
M = PDMat(A * A')
my_add_1(a, M) # works (with _adddiag)
my_add_2(a, M) # works (with _adddiag!)
my_add_3(a, M) # fails

I guess your point is that one should use my_add_2 instead of my_add_1?

@devmotion
Copy link
Member

devmotion commented Oct 3, 2023

Yes, my point is that we should rather use something like PDMat(PDMats._adddiag!(Matrix(b), a.diag, true)).

Can you change the PR to that version and add a currently failing example to the tests?

@olivierverdier olivierverdier changed the title _adddiag! should be _adddiag Fixes to adddiag Oct 3, 2023
@devmotion
Copy link
Member

Thank you! I added an additional fix and tests in d10d1a7. I'll merge and release when tests pass.

@devmotion devmotion merged commit e97e813 into JuliaStats:master Oct 3, 2023
11 checks passed
@olivierverdier olivierverdier deleted the fix_adddiag branch October 5, 2023 13:21
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.

3 participants