-
Notifications
You must be signed in to change notification settings - Fork 153
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
Implement vector indexing for SDiagonal with statically sized indices #926
base: master
Are you sure you want to change the base?
Conversation
Speialized Before: julia> m = SDiagonal(@SVector [11, 12, 13, 14])
4×4 Diagonal{Int64, SVector{4, Int64}} with indices SOneTo(4)×SOneTo(4):
11 ⋅ ⋅ ⋅
⋅ 12 ⋅ ⋅
⋅ ⋅ 13 ⋅
⋅ ⋅ ⋅ 14
julia> @btime [copy($m) for i = 1:100];
1.155 μs (101 allocations: 5.56 KiB) After: julia> @btime [copy($m) for i = 1:100];
809.139 ns (1 allocation: 3.25 KiB) |
Test failure on nightly seems unrelated (ambiguity in |
vector indexing for SDiagonal produces SArrays
d1eb08e
to
9dd183d
Compare
@@ -17,6 +17,10 @@ SDiagonal(a::StaticMatrix{N,N,T}) where {N,T} = Diagonal(diag(a)) | |||
size(::Type{<:SDiagonal{N}}) where {N} = (N,N) | |||
size(::Type{<:SDiagonal{N}}, d::Int) where {N} = d > 2 ? 1 : N | |||
|
|||
Base.axes(D::SDiagonal, d) = d <= 2 ? axes(D)[d] : SOneTo(1) | |||
|
|||
Base.reshape(a::SDiagonal, s::Tuple{SOneTo,Vararg{SOneTo}}) = reshape(a, homogenize_shape(s)) |
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.
This is the same as the generic fallback:
StaticArrays.jl/src/abstractarray.jl
Line 190 in 29a76ec
@inline reshape(a::AbstractArray, s::Tuple{SOneTo,Vararg{SOneTo}}) = reshape(a, homogenize_shape(s)) |
Do we really need this method?
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.
Other than this small point, the PR looks nice 👍 .
On master:
After this PR: