-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Implement inplace circshift
#16032
Comments
(See also the discussion at the end of #9822.) |
@Musmo, the circshift you're referring to is based on a chase-the-cycles approach. The Knuth algorithm (based on two reversal passes) is far better for arbitrary shifts. |
For example, here is a working 1d function circshift!(a::AbstractVector, shift::Integer)
n = length(a)
s = mod(shift, n)
s == 0 && return a
reverse!(a, 1, s)
reverse!(a, s+1, n)
reverse!(a)
end The only thing I'm not sure of is how to generalize this to arbitrary dimensions without writing out a bunch of explicit loops for 2d, 3d, etcetera arrays. @timholy, is this something that your cartesian iterators could handle? (Also, it would be nice to fuse the reversal loops in higher dimensions so that only 2 passes, not 2k passes, are required for shifting a k-dimensional array along all k dimensions simultaneously. But maybe in practice people usually shift only along a 1 or 2 dimensions at a time?) |
@timholy, is it worth keeping this open for a truly in-place |
I'm fine with that, if others want that. We don't have a truly in-place So feel free to reopen if you are interested. |
Since we're consolidating |
It looks like
|
We have
circshift
but no inplace version, which would be very useful. There is a rough implementation in the lbm3d threads test.The text was updated successfully, but these errors were encountered: