-
Notifications
You must be signed in to change notification settings - Fork 148
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 new broadcast API #348
Conversation
This still needs some work. The
Before:
After:
|
Codecov Report
@@ Coverage Diff @@
## master #348 +/- ##
==========================================
- Coverage 93.36% 93.29% -0.07%
==========================================
Files 37 37
Lines 2713 2715 +2
==========================================
Hits 2533 2533
- Misses 180 182 +2
Continue to review full report at Codecov.
|
Aha. The problem was that specialising
|
src/broadcast.jl
Outdated
BroadcastStyle(::Type{<:StaticArray{D, T, N}}) where {D, T, N} = StaticArrayStyle{N}() | ||
|
||
# Fix Precedence: Make StaticArray - Array -> Array | ||
BroadcastStyle(::StaticArrayStyle{M}, ::Broadcast.VectorStyle) where {N,M} = Broadcast.Unknown() |
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.
N
is undefined.
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.
Thanks Andy!
src/broadcast.jl
Outdated
BroadcastStyle(::StaticArrayStyle{M}, ::Broadcast.VectorStyle) where {N,M} = Broadcast.Unknown() | ||
BroadcastStyle(::StaticArrayStyle{M}, ::Broadcast.MatrixStyle) where {N,M} = Broadcast.Unknown() | ||
|
||
# Add a broadcast method that calls the old @generated routine |
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.
"old" isn't really necessary here
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 quite good, thanks for tackling this!
src/broadcast.jl
Outdated
|
||
# Fix Precedence: Make StaticArray - Array -> Array | ||
BroadcastStyle(::StaticArrayStyle{M}, ::Broadcast.VectorStyle) where M = Broadcast.Unknown() | ||
BroadcastStyle(::StaticArrayStyle{M}, ::Broadcast.MatrixStyle) where M = Broadcast.Unknown() |
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.
VectorStyle
and MatrixStyle
are unfortunate (and hopefully temporary) objects because we don't trust that sparse broadcasting generalizes correctly beyond Array
(see JuliaLang/julia#23939 (comment)). However, this suggests we'll have to support them throughout julia 1.x. 😢
Long-term the one we want to implement would be with DefaultArrayStyle
. Instead of returning Unknown
, it might be best to do something like this (untested):
BroadcastStyle(::StaticArrayStyle{M}, ::Broadcast.DefaultArrayStyle{N}) where {M,N} =
DefaultArrayStyle(Broadcast._max(Val(M), Val(N))
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.
Hey Tim, thanks for reviewing! Your designs are a pleasure to work with.
So you suggest including this rule, in addition to the VectorStyle
and MatrixStyle
ones, to take over once the latter are removed, yes? Done.
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.
Right. Also the DefaultArrayStyle
is necessary even now for dimensions higher than 2.
Thanks for the kind words about the API. I think it's also fair to say that unfortunately they don't help StaticArrays that much; they're more oriented around improving the API for mutable arrays. But at least it's documented, and hopefully that's worth something.
Really grateful to you for tackling this!
Please forgive the supernoob question: what is that failed check from coveralls? Is it just because I need to add some tests? (I'm not sure if this is waiting for me to do something...) |
Note that there have been additional changes to Re: coveralls: a slight decrease in code coverage is to be expected. Code coverage is determined on Julia 0.6, so the 0.7 code doesn't get run. It doesn't matter (check is not required to pass before merging). |
Actually, here's a PR against your branch that implements the change: https://github.com/pablosanjose/StaticArrays.jl/pull/1. |
And probably more changes coming...JuliaLang/julia#25377 |
Adapt to new broadcast! implementation in Base.
Sorry, I haven't got around to this in a while. Is this good to go? |
It is as far as I'm concerned... (At least until JuliaLang/julia#25377 rains hellfire on us! :-P) |
I just tried this again in the latest Julia master, and I think there are still
Not sure if this happened some weeks ago. I'll try to look into it if I can find the time. |
FYI @pablosanjose I've been working on a branch which deals with all the v0.7 carnage and have incorporated these changes there (thanks!). However every day I nearly get the tests passing and then the next day something else breaks. (This time it's |
You have all my support and empathy. StaticArrays is a central tool for many of us. Keep at it! |
Attempt to fix #347
(Please review carefully, as I'm still quite new at this.)
I implemented a
StaticArrayStyle{N} <: AbtractArrayStyle{N}
to plug into the newbroadcast
API introduced in julialang/#23939, together with two specialised indirections forbroadcast
andbroadcast!
that call the old@generated _broadcast
and@generated _broadcast!
routines. The latter does still seem to be a bit faster and allocate a little less than the Basebroadcast!
fallback. However, the Base fallback also works.I see tight@code_native
output, similar or identical to the one before julialang/#23939. Timings and allocations also seem identical, although I didn't do exhaustive testing.[EDIT: not always][EDIT2: fixed now, hopefully]Caveat
The package tests now work again, except for those involving broadcast between
Scalar(...)
and normalArray
s. I'm afraid I need a bit of help with this one. As an exampleScalar(3) .* [1,2,3]
fails with the same error asScalar(3) * 2
, aBoundsError
. This is the case both before and after julialang/#23939, but for some reasonScalar(3) .* [1,2,3]
did work with the old broadcast API, and returnedArray{Int}[2, 4, 6]
. What is the expected behavior for this? What shouldScalar(3) * 2
give? How shouldScalar(3) .* [1,2,3]
be fixed with the new broadcast API?[EDIT: fixed Scalar broadcast. I needed to properly define the correct broadcast promotions using binary methods for
BroadcastStyle
]