@@ -377,3 +377,29 @@ Base.unsafe_view(A::AbstractArray, i1::StaticIndexing, indices::StaticIndexing..
377377# the tuple indices has to have at least one element to prevent infinite
378378# recursion when viewing a zero-dimensional array (see issue #705)
379379Base. SubArray (A:: AbstractArray , indices:: Tuple{StaticIndexing, Vararg{StaticIndexing}} ) = Base. SubArray (A, map (unwrap, indices))
380+
381+ # ##########################################################
382+ # SDiagonal
383+ # ##########################################################
384+
385+ # SDiagonal uses Cartesian indexing, and the canonical indexing methods shadow getindex for Diagonal
386+ # these are needed for ambiguity resolution
387+ @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
395+ end
396+ @inline function getindex (D:: SDiagonal , i:: Int... )
397+ @boundscheck checkbounds (D, i... )
398+ @inbounds r = D[eachindex (D)[i... ]]
399+ r
400+ end
401+ # Ensure that vector indexing with static types lead to SArrays
402+ @propagate_inbounds function getindex (a:: SDiagonal , inds:: Union{Int, StaticArray{<:Tuple, Int}, SOneTo, Colon} ...)
403+ ar = reshape (a, Val (length (inds)))
404+ _getindex (ar, index_sizes (Size (ar), inds... ), inds)
405+ end
0 commit comments