diff --git a/base/linalg/uniformscaling.jl b/base/linalg/uniformscaling.jl index 8ee5ec14ae758b..fb34984681b176 100644 --- a/base/linalg/uniformscaling.jl +++ b/base/linalg/uniformscaling.jl @@ -56,7 +56,7 @@ getindex(J::UniformScaling, i::Integer,j::Integer) = ifelse(i==j,J.λ,zero(J.λ) function getindex(x::UniformScaling{T}, n::AbstractRange{<:Integer}, m::AbstractRange{<:Integer}) where T if length(n) == length(m) && step(n) == step(m) k = first(n) - first(m) - if length(n) - abs(k) > 0 + if k % step(n) == 0 && length(n) - abs(k) > 0 v = fill(x.λ, length(n) - abs(k)) return spdiagm(k => v) else diff --git a/test/linalg/uniformscaling.jl b/test/linalg/uniformscaling.jl index 410ec991a250a9..c8ebec4bd8c8d1 100644 --- a/test/linalg/uniformscaling.jl +++ b/test/linalg/uniformscaling.jl @@ -24,6 +24,7 @@ end @test I[1,2] == 0 @test I[1:2,1:2] == eye(2,2)[1:2,1:2] @test I[1:2:3,1:2:3] == eye(3,3)[1:2:3,1:2:3] + @test I[1:2:8,2:2:9] == eye(10,10)[1:2:8,2:2:9] @test I[1:2,2:3] == eye(3,3)[1:2,2:3] @test I[2:3,1:2] == eye(3,3)[2:3,1:2] @test I[2:-1:1,1:2] == eye(2,2)[2:-1:1,1:2]