Skip to content

Commit 9dd183d

Browse files
committed
invoke instead of duplicating getindex
1 parent 6f5c862 commit 9dd183d

File tree

2 files changed

+2
-11
lines changed

2 files changed

+2
-11
lines changed

src/SDiagonal.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ SDiagonal(a::StaticMatrix{N,N,T}) where {N,T} = Diagonal(diag(a))
1717
size(::Type{<:SDiagonal{N}}) where {N} = (N,N)
1818
size(::Type{<:SDiagonal{N}}, d::Int) where {N} = d > 2 ? 1 : N
1919

20-
Base.axes(D::SDiagonal) = (ax = axes(diag(D), 1); (ax, ax))
2120
Base.axes(D::SDiagonal, d) = d <= 2 ? axes(D)[d] : SOneTo(1)
2221

2322
Base.reshape(a::SDiagonal, s::Tuple{SOneTo,Vararg{SOneTo}}) = reshape(a, homogenize_shape(s))

src/indexing.jl

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -385,18 +385,10 @@ Base.SubArray(A::AbstractArray, indices::Tuple{StaticIndexing, Vararg{StaticInde
385385
# SDiagonal uses Cartesian indexing, and the canonical indexing methods shadow getindex for Diagonal
386386
# these are needed for ambiguity resolution
387387
@inline function getindex(D::SDiagonal, i::Int, j::Int)
388-
@boundscheck checkbounds(D, i, j)
389-
if i == j
390-
@inbounds r = diag(D)[i]
391-
else
392-
r = LinearAlgebra.diagzero(D, i, j)
393-
end
394-
r
388+
invoke(getindex, Tuple{Diagonal, Int, Int}, D, i, j)
395389
end
396390
@inline function getindex(D::SDiagonal, i::Int...)
397-
@boundscheck checkbounds(D, i...)
398-
@inbounds r = D[eachindex(D)[i...]]
399-
r
391+
invoke(getindex, Tuple{Diagonal, Vararg{Int}}, D, i...)
400392
end
401393
# Ensure that vector indexing with static types lead to SArrays
402394
@propagate_inbounds function getindex(a::SDiagonal, inds::Union{Int, StaticArray{<:Tuple, Int}, SOneTo, Colon}...)

0 commit comments

Comments
 (0)