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

In-place circshift!(arr, shifts) #54868

Closed
jariji opened this issue Jun 20, 2024 · 2 comments
Closed

In-place circshift!(arr, shifts) #54868

jariji opened this issue Jun 20, 2024 · 2 comments
Labels
arrays [a, r, r, a, y, s] docs This change adds or pertains to documentation duplicate Indicates similar issues or pull requests

Comments

@jariji
Copy link
Contributor

jariji commented Jun 20, 2024

The 3-arg form circshift!(dest, src, shifts) has the aliasing warning, but I commonly want to rotate in place. Can Base have in-place circshift!(arr, shifts)?

@nsajko nsajko added arrays [a, r, r, a, y, s] feature Indicates new feature / enhancement requests labels Jun 20, 2024
@jariji
Copy link
Contributor Author

jariji commented Feb 25, 2025

Turns out this method is already implemented, just not documented. Any reason not to document it?

julia/base/abstractarray.jl

Lines 3671 to 3681 in 58399e2

function circshift!(a::AbstractVector, shift::Integer)
n = length(a)
n == 0 && return a
shift = mod(shift, n)
shift == 0 && return a
l = lastindex(a)
reverse!(a, firstindex(a), l-shift)
reverse!(a, l-shift+1, lastindex(a))
reverse!(a)
return a
end

@nsajko nsajko added docs This change adds or pertains to documentation and removed feature Indicates new feature / enhancement requests labels Feb 25, 2025
@barucden
Copy link
Contributor

I think this issue is a duplicate of #46016 after all.

@nsajko nsajko added the duplicate Indicates similar issues or pull requests label Feb 25, 2025
@nsajko nsajko closed this as completed Feb 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrays [a, r, r, a, y, s] docs This change adds or pertains to documentation duplicate Indicates similar issues or pull requests
Projects
None yet
Development

No branches or pull requests

3 participants