-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Fix #17970 (output of map over BitArrays) #18198
Conversation
Also, can anyone check that there are not performance regressions (once tests pass)? |
1d79105
to
3959f77
Compare
I think this is too inference-dependent; our current rule is that the result can only depend on inference for empty arrays. I would prefer the simple and predictable behavior of only returning a BitArray for the set of boolean functions listed in the code (~, !, &, |, etc.) |
3959f77
to
12c5b38
Compare
EDIT: It turns out that the fall-back |
12c5b38
to
7e86c19
Compare
@nanosoldier |
Ah yes, that's a good solution. |
Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. cc @jrevels |
LGTM - hooray, |
AFAICS, I also believe that the performance regressions are unrelated. And I think you're right, it doesn't seem like there are benchmarks for mapping over As for the specialization, that might help a bit in some cases, but I'm not sure. |
@JeffBezanson Is there any consideration of using inference when the result type is concrete as an optimization and falling back to use the values otherwise (or that is problematic in any way)? |
Type inference is supposed to handle that automatically. |
@yuyichao I should have been more precise, I was particularly referring to doing it here https://github.com/JuliaLang/julia/blob/master/base/array.jl#L312. We currently have function _collect(c, itr, ::EltypeUnknown, isz::Union{HasLength,HasShape})
st = start(itr)
if done(itr,st)
return _similar_for(c, _default_eltype(typeof(itr)), itr, isz)
end
v1, st = next(itr, st)
collect_to_with_first!(_similar_for(c, typeof(v1), itr, isz), v1, itr, st)
end but this could be improved a bit like this function _collect(c, itr, ::EltypeUnknown, isz::Union{HasLength,HasShape})
et = _default_eltype(typeof(itr))
isleaftype(et) && return copy!(_similar_for(c, et, itr, isz), itr)
st = start(itr)
if done(itr,st)
return _similar_for(c, et, itr, isz)
end
v1, st = next(itr, st)
collect_to_with_first!(_similar_for(c, typeof(v1), itr, isz), v1, itr, st)
end |
Yes and I'm under the impression that the type inference should handle the first case just fine if the callback is inferrable. Is that not the case? |
Well, it is handled as it should. What I should have probably had to say was that |
We can certainly tweak the implementation at many points if benchmarking different cases suggests that there's a good reason to do so. I don't see a reason we have to special case the leaf inferred type to get the same performance though. |
It should be possible to make |
I see, good to know. Sorry for the noise, then. EDIT: The reason I brought it up the first time was because I was under the impression that it was not the case for some example I was testing. But after benchmarking it properly I see it works a you point out. |
Should this one be backported? |
IIUC, this does not change behavior for anything that works in master (or 0.5), but enables something that used to work in 0.4 (and really should work). So backporting sounds like a good idea. |
7e86c19
to
0faf311
Compare
0faf311
to
a6fec5b
Compare
Bump. This should be good to go as well as back-portable. |
With this patch the output of mapping over
BitArray
s is properly decided based on the return type of the function (ifBool
the return type will be aBitArray
and anArray
of the appropriate type otherwise).@martinholters Can you take a look?
Cc: @JeffBezanson