Skip to content
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

broadcast between SMatrix{M,N} and SMatrix{M,1} (or SMatrix{1,N}) doesn't work #242

Closed
wsshin opened this issue Jul 8, 2017 · 2 comments · Fixed by #274
Closed

broadcast between SMatrix{M,N} and SMatrix{M,1} (or SMatrix{1,N}) doesn't work #242

wsshin opened this issue Jul 8, 2017 · 2 comments · Fixed by #274

Comments

@wsshin
Copy link
Contributor

wsshin commented Jul 8, 2017

Broadcasting an operator over a matrix (SMatrix{M,N}) and a column-like (SMatrix{M,1}) or row-like (SMatrix{1,N}) matrix doesn't work and generates a DimensionMismatch error is generated. (Seems to be related to #199.)

julia> VERSION
v"0.6.1-pre.0"

julia> SA = @SMatrix [1 2; 3 4]
2×2 StaticArrays.SArray{Tuple{2,2},Int64,2,4}:
 1  2
 3  4

julia> SC = @SMatrix [2;4]
2×1 StaticArrays.SArray{Tuple{2,1},Int64,2,2}:
 2
 4

julia> SR = @SMatrix [2 4]
1×2 StaticArrays.SArray{Tuple{1,2},Int64,2,2}:
 2  4

julia> broadcast(+, SA, SC)
ERROR: DimensionMismatch("Tried to broadcast on inputs sized Tuple{Int64,Int64}[(2, 2), (2, 1)]")
Stacktrace:
 [1] _broadcast(...) at /Users/wsshin/.julia/v0.6/StaticArrays/src/broadcast.jl:52
 [2] broadcast(::Function, ::StaticArrays.SArray{Tuple{2,2},Int64,2,4}, ::StaticArrays.SArray{Tuple{2,1},Int64,2,2}) at /Users/wsshin/.julia/v0.6/StaticArrays/src/broadcast.jl:8

julia> broadcast(+, SA, SR)
ERROR: DimensionMismatch("Tried to broadcast on inputs sized Tuple{Int64,Int64}[(2, 2), (1, 2)]")
Stacktrace:
 [1] _broadcast(...) at /Users/wsshin/.julia/v0.6/StaticArrays/src/broadcast.jl:52
 [2] broadcast(::Function, ::StaticArrays.SArray{Tuple{2,2},Int64,2,4}, ::StaticArrays.SArray{Tuple{1,2},Int64,2,2}) at /Users/wsshin/.julia/v0.6/StaticArrays/src/broadcast.jl:8

Is this difficult to fix?

If an actual vector is used instead of a column-like matrix, broadcasting works. Therefore, currently I am working around this as follows:

julia> broadcast(+, SA, SC[:,1])
2×2 StaticArrays.SArray{Tuple{2,2},Int64,2,4}:
 3  4
 7  8

julia> broadcast(+, SA', SR[1,:])'
2×2 StaticArrays.SArray{Tuple{2,2},Int64,2,4}:
 3  6
 5  8
@andyferris
Copy link
Member

We definitely need to fix this...

c42f added a commit that referenced this issue Aug 11, 2017
Fix several broadcast issues (fixes #197, #199, #200, #242)
@wsshin
Copy link
Contributor Author

wsshin commented Aug 11, 2017

Closed via #274.

@wsshin wsshin closed this as completed Aug 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants