Skip to content

Commit

Permalink
Correctly handle non-integer steps
Browse files Browse the repository at this point in the history
  • Loading branch information
Evey Dee committed Oct 30, 2017
1 parent 8f9af9c commit 7517026
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion base/linalg/uniformscaling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions test/linalg/uniformscaling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 7517026

Please sign in to comment.