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

Overload Base.literal_pow for AbstractQ #54010

Merged
merged 3 commits into from Apr 13, 2024
Merged

Conversation

dkarrasch
Copy link
Member

Fixes #53989.

There's a decision to be made here. What do we want Q^-1 to return? Q'::AbstractQ or Q'*I::Matrix? On Julia v1.9 and older, Q^p returned the matrix representation for any p except p=-1, where it returned inv(Q) which was defined to be Q'. I have returned to this behavior after finding out.

@dkarrasch dkarrasch added domain:linear algebra Linear algebra backport 1.10 Change should be backported to the 1.10 release backport 1.11 Change should be backported to release-1.11 labels Apr 9, 2024
@KristofferC KristofferC mentioned this pull request Apr 11, 2024
25 tasks
@dkarrasch
Copy link
Member Author

I changed things to the matrix approach: so only Q^(+/-1) are lazy, all other powers use power_by_squaring. @dlfivefifty Could you please take a quick look?

Comment on lines +22 to +23
@inline Base.literal_pow(::typeof(^), Q::AbstractQ, ::Val{1}) = Q
@inline Base.literal_pow(::typeof(^), Q::AbstractQ, ::Val{-1}) = inv(Q)
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

Suggested change
@inline Base.literal_pow(::typeof(^), Q::AbstractQ, ::Val{1}) = Q
@inline Base.literal_pow(::typeof(^), Q::AbstractQ, ::Val{-1}) = inv(Q)

Is there a reason for these? The fallback should work just fine here, no?

@mbauman
Copy link
Sponsor Member

mbauman commented Apr 12, 2024

Ah, ok, I see. This is fallout from #46196, where we lost the AbstractArray ^ method.

@mbauman mbauman added regression 1.10 Regression in the 1.10 release and removed regression 1.10 Regression in the 1.10 release labels Apr 12, 2024
@dkarrasch
Copy link
Member Author

Hihi, technically, one could make Q^p::AbstractQPower <: AbstractQ and lazy, similar to Q^1 and Q^-1. 😄 If Q is not a matrix, why should Q^p be? For instance, we loose the size flexibility of the right-most copy of Q in Q*Q*...*Q.

@dlfivefifty
Copy link
Contributor

Q^2 should be equal to Q*Q. Since the latter works so should the former.

@dkarrasch
Copy link
Member Author

Ok, then I think this is ready to go, isn't it?

@dlfivefifty dlfivefifty self-requested a review April 13, 2024 19:44
@dlfivefifty
Copy link
Contributor

Looks fine to me! Thanks!

@dkarrasch dkarrasch merged commit b9aeafa into master Apr 13, 2024
9 checks passed
@dkarrasch dkarrasch deleted the dk/abstractq_literalpow branch April 13, 2024 20:07
KristofferC pushed a commit that referenced this pull request Apr 17, 2024
@KristofferC KristofferC mentioned this pull request Apr 17, 2024
57 tasks
KristofferC pushed a commit that referenced this pull request May 8, 2024
@KristofferC KristofferC mentioned this pull request May 8, 2024
17 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 1.10 Change should be backported to the 1.10 release backport 1.11 Change should be backported to release-1.11 domain:linear algebra Linear algebra
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AbstractQ literal_pow (Q^2) missing
3 participants