Skip to content

Conversation

@ajinkya-k
Copy link
Contributor

@ajinkya-k ajinkya-k commented Nov 29, 2024

(fixes #1128) the current implementation of rank(::QRPivoted) is slow and inefficient because of repeated calls to A.R each of which triggers memory allocation. this PR fixes that by using A.factors instead which does not cause memory allocations. The proposed implementation is orders of magnitude faster and avoids unnecessary memory allocations altogether.

@ajinkya-k
Copy link
Contributor Author

@stevengj made the changes you suggested. Thanks!

@ajinkya-k
Copy link
Contributor Author

resolved all the suggestions

@ajinkya-k
Copy link
Contributor Author

I had a general question: is it okay to squash commits and (force) push to my branch? That will reduce the number of commits in this PR and remove all references to the SVD.jl files that I accidentally included (and removed in a later commit) ?

@jishnub
Copy link
Member

jishnub commented Nov 30, 2024

Yes, it's fine, especially if it makes the PR easier to review

@stevengj
Copy link
Member

It doesn't hurt to squash, but it shouldn't be necessary — if we use the "squash and merge" button, then the PR will be squashed before merging anyway.

@ajinkya-k
Copy link
Contributor Author

Thanks! @stevengj so it should be fine if there are multiple commits?

@ajinkya-k
Copy link
Contributor Author

Based on a suggestion in another PR, I simplified the eps call in the default argument for rtol to the following: eps(real(float(eltype(A.Q))))

@ajinkya-k
Copy link
Contributor Author

also changed eltype(A.Q) to eltype(A) since the former suffices

@jishnub
Copy link
Member

jishnub commented Dec 1, 2024

I would encourage including a minimal and self-contained description in the commit message, so that it's easier to follow the git log.

@ajinkya-k
Copy link
Contributor Author

What else needs to be done to merge this PR?

@ajinkya-k
Copy link
Contributor Author

I would encourage including a minimal and self-contained description in the commit message, so that it's easier to follow the git log.

I tried to be descriptive but some of the changes were truly minor. I'll do better in the future. It's also one reason I wanted to squash commits, but since @stevengj mentioned that we can just "squash and merge" the PR I didn't do it.

@jishnub
Copy link
Member

jishnub commented Dec 1, 2024

Sorry I meant in the PR description, as that will become the commit description when the PR is squashed and merged. Currently it just says that this fixes an issue, but a bit more detail would help in understanding exactly what the PR contributes.

@jishnub
Copy link
Member

jishnub commented Dec 2, 2024

Other than the comment on the PR description, this looks good to me

@ajinkya-k
Copy link
Contributor Author

@jishnub thanks! I updated the PR description

@jishnub
Copy link
Member

jishnub commented Dec 2, 2024

Is this method being tested already? Otherwise we might want to add a test

@ajinkya-k
Copy link
Contributor Author

ajinkya-k commented Dec 2, 2024

It is being tested here:

@testset "issue #53214" begin

do we need/want to change the test set name?

@jishnub
Copy link
Member

jishnub commented Dec 2, 2024

Ok, no this is fine. I think we can go ahead and merge this.

@jishnub jishnub merged commit f13f940 into JuliaLang:master Dec 2, 2024
2 checks passed
@jishnub
Copy link
Member

jishnub commented Dec 2, 2024

Thanks for the PR!

end

function rank(A::QRPivoted; atol::Real=0, rtol::Real=min(size(A)...) * eps(real(float(one(eltype(A.Q))))) * iszero(atol))
function rank(A::QRPivoted; atol::Real=0, rtol::Real=min(size(A)...) * eps(real(float(eltype(A)))) * iszero(atol))
Copy link
Member

@stevengj stevengj Dec 2, 2024

Choose a reason for hiding this comment

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

Note that one(eltype(A)) would be better here, in principle, in order to handle the case of dimensionful matrices — the rtol should always be dimensionless, and one strips any units.

(I'm not sure if we support dimensionful matrices yet in QRPivoted — I'm guessing we don't — but it's nice to think about the possibility of unitful numbers when implementing algorithms.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, I made that change based on a comment in #1127 . Before making the change I compared eps(eltype(A)) and eps(one(eltype(A))) and verified they give the same answer. I can submit another PR to put back the one in there. Also I dont think I understand what you mean by dimensionful here. Can you point me to a resource to read?

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.

rank(::QRPivoted) is very inefficient

3 participants