Skip to content

Commit

Permalink
fixed last index
Browse files Browse the repository at this point in the history
  • Loading branch information
matbesancon committed Jul 22, 2023
1 parent 5136cc0 commit 4dd4a6a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/sparsevector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ function _partialview_end_indices(x::SparseVectorPartialView)
first_idx = findfirst(>=(x.indices[1][begin]), nzinds)
last_idx = findlast(<=(x.indices[1][end]), nzinds)
# empty view
if first_idx === nothing
if first_idx === nothing || last_idx === nothing
last_idx = length(nzinds)
first_idx = last_idx+1
end
Expand Down
2 changes: 1 addition & 1 deletion test/sparsevector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ spv_x2 = SparseVector(8, [1, 2, 6, 7], [3.25, 4.0, -5.5, -6.0])
(SparseVector(5, [1], [1.0]), SparseVector(5, [2], [3.0])),
(SparseVector(5, [3], [2.0]), SparseVector(5, [4], [3.0])),
]
@testset "View operations $((xa, xb)), op $op" for (xa, xb) in test_vectors, op in (-, +)
@testset "View operations $((collect(xa), collect(xb))), op $op" for (xa, xb) in test_vectors, op in (-, +)
r1 = op(@view(xa[1:end]), @view(xb[1:end]))
@test r1 == op(xa, xb)
@test r1 isa SparseVector
Expand Down

0 comments on commit 4dd4a6a

Please sign in to comment.