-
Notifications
You must be signed in to change notification settings - Fork 6
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
Towards fixing splatting properly #52
Conversation
I had a similar problem in Yota.jl when I needed |
I like this idea. How about the following: for each argument which is getting splatted, we proceed in two steps:
The first step can be specialised, depending on the type. For example, if the type is already a This approach has the limitation that the conversion to a edit: we could call the conversion function |
Yes, |
I see your point -- the problem is that not every iterable naturally supports a x = Iterators.takewhile(>(0), [0.1, 0.1, 0.1, -0.1, 0.1, 0.1, 0.1, 0.1]) You can definitely splat julia> tuple(x...)
(0.1, 0.1, 0.1) so it's within the scope of what we're interested in, but Does this seem reasonable, or am I missing something? |
Ah, right, I didn't take into account that we will need to iterate over collection multiple times. So yes, your solution looks like the best option. |
Cool. I'll work on that today. |
Codecov ReportAttention:
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## main #52 +/- ##
========================================
- Coverage 1.27% 0.74% -0.53%
========================================
Files 8 7 -1
Lines 707 670 -37
========================================
- Hits 9 5 -4
+ Misses 698 665 -33 ☔ View full report in Codecov by Sentry. |
@dfdx I've implemented the proposal -- I think we're good to go if you're happy |
Perfect, thank you! |
It turns out that while #48 didn't break any of the tests in Umlaut, it did break some examples of splatting in code that I'm testing on. This lead me to dig around a little, and construct the additional test cases for Umlaut that I've added in this PR.
Notably:
getfield
-- this is most things other thanTuple
andNamedTuple
.getindex
works, which is a greater array of things thangetfield
getindex
defined on them. I've created one of these by adding a test involving azip
, for whichgetindex
doesn't work.I'm not entirely sure what the right answer is here. I would really rather not revert to the
getindex
implementation ofunsplat!
, because it puts a (potentially) non-primitive on the tape, and doesn't handle all of the cases.One option is to, in the general case, insert a
Core._apply_iterate(itr, tuple, x...)
onto the tape, which will output aTuple
-- we could then employ the current strategy on thatTuple
(getfield
calls etc). This is a little bit annoying, but it at least has the property that it should handle every case. Downstream consumers of the tapes produced byUmlaut
could then handle whichever range of options they prefer. We could then add special handlers forTuple
s,Vector
s`, etc.What are your thoughts @dfdx ?