Skip to content

Commit

Permalink
sparse findXXX: cherry-pick test cases from JuliaLang#31354
Browse files Browse the repository at this point in the history
  • Loading branch information
KlausC authored and tkluck committed May 18, 2019
1 parent c45eff0 commit 54802d1
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions stdlib/SparseArrays/test/sparse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2263,16 +2263,20 @@ end
@test findprev(!iszero, x,i) == findprev(!iszero, x_sp,i)
end

y = [0 0 0 0 0;
y = [7 0 0 0 0;
1 0 1 0 0;
1 0 0 0 1;
1 7 0 7 1;
0 0 1 0 0;
1 0 1 1 0]
y_sp = sparse(y)
1 0 1 1 0.0]
y_sp = [x == 7 ? -0.0 : x for x in sparse(y)]
y = Array(y_sp)
@test isequal(y_sp[1,1], -0.0)

for i in keys(y)
@test findnext(!iszero, y,i) == findnext(!iszero, y_sp,i)
@test findprev(!iszero, y,i) == findprev(!iszero, y_sp,i)
@test findnext(iszero, y,i) == findnext(iszero, y_sp,i)
@test findprev(iszero, y,i) == findprev(iszero, y_sp,i)
end

z_sp = sparsevec(Dict(1=>1, 5=>1, 8=>0, 10=>1))
Expand All @@ -2282,6 +2286,17 @@ end
@test findnext(!iszero, z,i) == findnext(!iszero, z_sp,i)
@test findprev(!iszero, z,i) == findprev(!iszero, z_sp,i)
end

w = [ "a" ""; "" "b"]
w_sp = sparse(w)

for i in keys(w)
@test findnext(!isequal(""), w,i) == findnext(!isequal(""), w_sp,i)
@test findprev(!isequal(""), w,i) == findprev(!isequal(""), w_sp,i)
@test findnext(isequal(""), w,i) == findnext(isequal(""), w_sp,i)
@test findprev(isequal(""), w,i) == findprev(isequal(""), w_sp,i)
end

end

# #20711
Expand Down

0 comments on commit 54802d1

Please sign in to comment.