This came up in a Slack discussion about adding lag
and lead
functions, which are similar to circshift
. In many cases, allocating a vector to store the result of circshift
is a waste, as a lazy view would be sufficient and as efficient. Looking at uses of circshift
on GitHub shows several examples where the result is discarded immediately.
It would make sense to have Iterators.circshift
, returning a custom AbstractArray
object which would redirect getindex
calls to the parent after shifting the index. circshift!(dest, src, shift)
would be replaced with copy!(dest, Iterators.circshift(src, shift))
.
Do we need it in Base at all? Seems like there are no uses, only definitions, which suggest to me that it would make a good stdlib package.
Probably, but what package? Something were we'd also put lag
and lead
?
Initially, it could just be stdlib/CircularShifts
or something. Could later be rolled into a more general package for utility views into arrays.
We could try to find a slightly more general name from the start to avoid renaming it if possible. lag
and lead
are not "circular" for example. LazyArrays? ArrayTools?
For me this seem to belong to a module that groups: Array slicing, Array reshaping, Array transpose. Its not super necessary that circshift
sits in base. But discoverability is IMHO pretty important.
Slicing, reshaping and transpose are really basic features, I'm not sure we want to move them to stdlib...
If we're talking about slicing JuliennedArrays.jl
does slicing much faster than mapslices in Base and also is much more flexible.
JuliennedArrays
is the best-named package.
be still my heart
We can probably punt on this for 1.0.
That's clearly not a big issue, but if we want to deprecate the functions something will have to be done before 1.0 (either a deprecation or moving them to stdlib).
This can be a vestigial API at some point in the future when a lovely, complete lazy package exists.
Implemented in the ShiftedArrays package, together with lag
and lead
. The two new AbstractArray types are ShiftedArray
(meaning: you get missing
if you are out of bounds) for lag
and lead
and CircShiftedArray
(meaning, you restart from the other extreme) for circshift
.
I guess the question now is what do we want the relationship between this Base function and the ShiftedArrays package to be? Should we consider deprecating it entirely and pointing people at the package instead? Or should we retain this as a way of doing eager array shifting?
Most helpful comment
Implemented in the ShiftedArrays package, together with
lag
andlead
. The two new AbstractArray types areShiftedArray
(meaning: you getmissing
if you are out of bounds) forlag
andlead
andCircShiftedArray
(meaning, you restart from the other extreme) forcircshift
.