-
Notifications
You must be signed in to change notification settings - Fork 10
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
Add ShiftedArrays.diff
for differences between elements in a vector
#51
base: master
Are you sure you want to change the base?
Conversation
I agree we really need this, but it's not specific to ShiftedArrays at all since it returns a plain |
Filed an issue here |
I also think it's a bit odd that this should live here. IMO, the idea behind Returning an eager result whose value differs from |
Ah yeah so you mean it would make sense to have |
If it's performant to have the object be lazy, and if it takes advantage of the same infrastructure as @piever do you want to experiment with making this be lazy? Or should I modify the PR to make it return something which looks like what |
I think it'd make sense for it to return a lazy object, as for instance diff(v, n = 1; default) = Broadcast.broadcasted(-, v, lag(v, n; default)) My main concern was that |
Okay, I see your point about consistency with Base. Sorry for missing it earlier. If possible can you show your support in the linked issue? Would be good to coalesce these two discussions into one. |
@@ -4,6 +4,7 @@ import Base: checkbounds, getindex, setindex!, parent, size | |||
export ShiftedArray, ShiftedVector, shifts, default | |||
export CircShiftedArray, CircShiftedVector | |||
export lag, lead | |||
# ShiftedArrays.diff unexported due to collision |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it should not be exported - no need to comment I think
Base.diff
does not return a vector of the same size as the original. I find this very frustrating, as I express in #41.This PR adds
ShiftedArrays.diff
as a function to get the difference between elements, but pre-pendsmissing
at the first element.I understand that
ShiftedArrays.diff
is more characters thanx .- lag(x)
, but it's more declarative.