-
Notifications
You must be signed in to change notification settings - Fork 149
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 several broadcast issues (fixes #197, #199, #200, #242) #274
Changes from 9 commits
3a49b3a
e45d995
815860a
6c94be9
c96363a
c0be60e
5b6665f
b98baa7
8a265e8
1fb2024
9cf3d2a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,32 +45,32 @@ end | |
@testset "2x2 StaticMatrix with 1x2 StaticMatrix" begin | ||
m1 = @SMatrix [1 2; 3 4] | ||
m2 = @SMatrix [1 4] | ||
@test_broken @inferred(broadcast(+, m1, m2)) === @SMatrix [2 6; 4 8] #197 | ||
@test_broken @inferred(m1 .+ m2) === @SMatrix [2 6; 4 8] #197 | ||
@test @inferred(broadcast(+, m1, m2)) === @SMatrix [2 6; 4 8] #197 | ||
@test @inferred(m1 .+ m2) === @SMatrix [2 6; 4 8] #197 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps it makes sense to remove the issue reference from these individually, and instead describe the behaviour which is being tested in a short comment. (That comment could include the issue crossref instead.) In my opinion the source code (including comments) should be the source of truth about design decisions and the reasons for testing given behaviour: the source is a living document, but issues become abandoned as soon as they're closed. |
||
@test @inferred(m2 .+ m1) === @SMatrix [2 6; 4 8] | ||
@test_broken @inferred(m1 .* m2) === @SMatrix [1 8; 3 16] #197 | ||
@test @inferred(m1 .* m2) === @SMatrix [1 8; 3 16] #197 | ||
@test @inferred(m2 .* m1) === @SMatrix [1 8; 3 16] | ||
@test_broken @inferred(m1 ./ m2) === @SMatrix [1 1/2; 3 1] #197 | ||
@test @inferred(m1 ./ m2) === @SMatrix [1 1/2; 3 1] #197 | ||
@test @inferred(m2 ./ m1) === @SMatrix [1 2; 1/3 1] | ||
@test_broken @inferred(m1 .- m2) === @SMatrix [0 -2; 2 0] #197 | ||
@test @inferred(m1 .- m2) === @SMatrix [0 -2; 2 0] #197 | ||
@test @inferred(m2 .- m1) === @SMatrix [0 2; -2 0] | ||
@test_broken @inferred(m1 .^ m2) === @SMatrix [1 16; 1 256] #197 | ||
@test @inferred(m1 .^ m2) === @SMatrix [1 16; 3 256] #197 | ||
end | ||
|
||
@testset "1x2 StaticMatrix with StaticVector" begin | ||
m = @SMatrix [1 2] | ||
v = SVector(1, 4) | ||
@test @inferred(broadcast(+, m, v)) === @SMatrix [2 3; 5 6] | ||
@test @inferred(m .+ v) === @SMatrix [2 3; 5 6] | ||
@test_broken @inferred(v .+ m) === @SMatrix [2 3; 5 6] #197 | ||
@test @inferred(v .+ m) === @SMatrix [2 3; 5 6] #197 | ||
@test @inferred(m .* v) === @SMatrix [1 2; 4 8] | ||
@test_broken @inferred(v .* m) === @SMatrix [1 2; 4 8] #197 | ||
@test @inferred(v .* m) === @SMatrix [1 2; 4 8] #197 | ||
@test @inferred(m ./ v) === @SMatrix [1 2; 1/4 1/2] | ||
@test_broken @inferred(v ./ m) === @SMatrix [1 1/2; 4 2] #197 | ||
@test @inferred(v ./ m) === @SMatrix [1 1/2; 4 2] #197 | ||
@test @inferred(m .- v) === @SMatrix [0 1; -3 -2] | ||
@test_broken @inferred(v .- m) === @SMatrix [0 -1; 3 2] #197 | ||
@test @inferred(v .- m) === @SMatrix [0 -1; 3 2] #197 | ||
@test @inferred(m .^ v) === @SMatrix [1 2; 1 16] | ||
@test_broken @inferred(v .^ m) === @SMatrix [1 1; 4 16] #197 | ||
@test @inferred(v .^ m) === @SMatrix [1 1; 4 16] #197 | ||
end | ||
|
||
@testset "StaticVector with StaticVector" begin | ||
|
@@ -89,9 +89,9 @@ end | |
@test @inferred(v2 .^ v1) === SVector(1, 16) | ||
# test case issue #199 | ||
@test @inferred(SVector(1) .+ SVector()) === SVector() | ||
@test_broken @inferred(SVector() .+ SVector(1)) === SVector() | ||
@test @inferred(SVector() .+ SVector(1)) === SVector() | ||
# test case issue #200 | ||
@test_broken @inferred(v1 .+ v2') === @SMatrix [2 5; 3 5] | ||
@test @inferred(v1 .+ v2') === @SMatrix [2 5; 3 6] | ||
end | ||
|
||
@testset "StaticVector with Scalar" begin | ||
|
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.
IIRC calling
Inference.return_type
is considered a bit of a dirty trick by the core devs ;-) If used, it can change the behaviour of code depending on optimizations to the julia inference engine. (Is this the reason to avoid it? Perhaps there's more and someone can enlighten me?).I know we do it in another couple of places in
StaticArrays
, but I think we can avoid it here by doing something likeor some similar such trick?
The version for
_mapreducedim
further up is more tricky, because it takes an arbitraryop
in the reduction. Unlikediff
, it's not clear that the data will be numeric or that callingone(eltype(a))
makes sense in that case.