Skip to content

Generalize broadcasting to StaticMatrixLike#1220

Merged
mateuszbaran merged 2 commits intoJuliaArrays:masterfrom
devmotion:dw/wrapper_matrix_broadcast
Nov 17, 2023
Merged

Generalize broadcasting to StaticMatrixLike#1220
mateuszbaran merged 2 commits intoJuliaArrays:masterfrom
devmotion:dw/wrapper_matrix_broadcast

Conversation

@devmotion
Copy link
Contributor

Currently, broadcasting with StaticMatrixLike-types does not always return SMatrix results:

julia> using StaticArrays, LinearAlgebra

julia> Symmetric(@SMatrix [1 2; 3 4]) .+ 1
2×2 Matrix{Int64}:
 2  3
 3  5

julia> Symmetric(@SMatrix [1 2; 3 4]) .+ @SVector [5, 6]
2×2 Matrix{Int64}:
 6   7
 8  10

julia> Symmetric(@SMatrix [1 2; 3 4]) .+ @SMatrix [5 6; 7 8]
2×2 SizedMatrix{2, 2, Int64, 2, Matrix{Int64}} with indices SOneTo(2)×SOneTo(2):
 6   8
 9  12

The PR fixes this by generalizing definitions of BroadcastStyle, isstatic, and axes to StaticMatrixLike:

julia> using StaticArrays, LinearAlgebra

julia> Symmetric(@SMatrix [1 2; 3 4]) .+ 1
2×2 SMatrix{2, 2, Int64, 4} with indices SOneTo(2)×SOneTo(2):
 2  3
 3  5

julia> Symmetric(@SMatrix [1 2; 3 4]) .+ @SVector [5, 6]
2×2 SMatrix{2, 2, Int64, 4} with indices SOneTo(2)×SOneTo(2):
 6   7
 8  10

julia> Symmetric(@SMatrix [1 2; 3 4]) .+ @SMatrix [5 6; 7 8]
2×2 SMatrix{2, 2, Int64, 4} with indices SOneTo(2)×SOneTo(2):
 6   8
 9  12

Copy link
Collaborator

@mateuszbaran mateuszbaran left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks reasonable. Could you just bump version to 1.7.0?

@devmotion
Copy link
Contributor Author

Done 🙂

@mateuszbaran mateuszbaran merged commit d47c771 into JuliaArrays:master Nov 17, 2023
@devmotion devmotion deleted the dw/wrapper_matrix_broadcast branch November 17, 2023 09:10
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 this pull request may close these issues.

2 participants