Skip to content

Commit db62ae4

Browse files
committed
Fix sparse findprev()/findnext() for sub2ind deprecation
This is needed in response to JuliaLang#24715.
1 parent a33abbe commit db62ae4

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

base/sparse/sparsematrix.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,36 +1319,36 @@ function _sparse_findnextnz(m::SparseMatrixCSC, i::Integer)
13191319
if i > length(m)
13201320
return zero(indtype(m))
13211321
end
1322-
row, col = ind2sub(m, i)
1322+
row, col = Tuple(CartesianIndices(m)[i])
13231323
lo, hi = m.colptr[col], m.colptr[col+1]
13241324
n = searchsortedfirst(m.rowval, row, lo, hi-1, Base.Order.Forward)
13251325
if lo <= n <= hi-1
1326-
return sub2ind(m, m.rowval[n], col)
1326+
return LinearIndices(m)[m.rowval[n], col]
13271327
end
13281328
nextcol = findnext(c->(c>hi), m.colptr, col+1)
13291329
if iszero(nextcol)
13301330
return zero(indtype(m))
13311331
end
13321332
nextlo = m.colptr[nextcol-1]
1333-
return sub2ind(m, m.rowval[nextlo], nextcol-1)
1333+
return LinearIndices(m)[m.rowval[nextlo], nextcol-1]
13341334
end
13351335

13361336
function _sparse_findprevnz(m::SparseMatrixCSC, i::Integer)
13371337
if iszero(i)
13381338
return zero(indtype(m))
13391339
end
1340-
row, col = ind2sub(m, i)
1340+
row, col = Tuple(CartesianIndices(m)[i])
13411341
lo, hi = m.colptr[col], m.colptr[col+1]
13421342
n = searchsortedlast(m.rowval, row, lo, hi-1, Base.Order.Forward)
13431343
if lo <= n <= hi-1
1344-
return sub2ind(m, m.rowval[n], col)
1344+
return LinearIndices(m)[m.rowval[n], col]
13451345
end
13461346
prevcol = findprev(c->(c<lo), m.colptr, col-1)
13471347
if iszero(prevcol)
13481348
return zero(indtype(m))
13491349
end
13501350
prevhi = m.colptr[prevcol+1]
1351-
return sub2ind(m, m.rowval[prevhi-1], prevcol)
1351+
return LinearIndices(m)[m.rowval[prevhi-1], prevcol]
13521352
end
13531353

13541354
import Base.Random.GLOBAL_RNG

0 commit comments

Comments
 (0)