-
Notifications
You must be signed in to change notification settings - Fork 66
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
Use 0-size tidyverse recycling rules consistently #416
Conversation
Hmm I also think this should be an error, which would imply that you can't vctrs::vec_size_common(1:2, numeric())
#> [1] 0 |
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.
I think we should first reach a conclusion in the principles issues, before making any changes to vctrs.
This PR also needs to make broadcasting and recycling rules consistent by changing the common size code in size.c
.
Changed to
Removed them
Added the table png to the docs page |
@lionel- good to go for a final review when you have time! (I don't know why the travis build isn't completing, it passed) |
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.
Looks good!
Thanks @DavisVaughan! |
Closes #299
These changes to
vec_size2()
andshape_broadcast()
enforce correct tidyverse recycling rules when comparing length-0 dimensions (those laid out in tidyverse/design#13 (comment)).Specifically, the common length of
0
and2
is now an error.The common length of
0
and1
is0
, as it was before.When broadcasting to a shape, the dimensions you are broadcasting to must be exactly the same, unless the dimension you are broadcasting from is
1
, in which case that can be broadcast to anything. All but the last of these examples produce the same result as before this PR, but I present them as a group to make the argument (the last one previously allowed you to broadcast from2
down to0
)I think the only thing you might have a question about is the fact that this means you can't broadcast from 2 down to 0. You can currently do this with
vec_recycle()
.It also occurred to me while thinking about this that there are really two types of recycling rules. One set for determining a common length. And one set for determining if you can actually recycle from length X to length Y. The result of the first set of rules is guaranteed to be an allowed length in the second set of rules. The current impl of
vec_recycle()
implies that the second set of rules might be more flexible though, allowing that you can recycle from2
down to0
, where the first set of rules would have never generated0
as the common length of2
and something else.