Skip to content

Commit

Permalink
early exit before actual work is done
Browse files Browse the repository at this point in the history
  • Loading branch information
dkarrasch committed Jan 6, 2022
1 parent 628d515 commit 2f3d1ea
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions stdlib/SparseArrays/src/sparsematrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2890,9 +2890,16 @@ function setindex!(A::AbstractSparseMatrixCSC{Tv,Ti}, V::AbstractVecOrMat, Ix::U
Base.setindex_shape_check(V, length(I), length(J))
B = _to_same_csc(A, V, I, J)

m, n = size(A)
if (!isempty(I) && (I[1] < 1 || I[end] > m)) || (!isempty(J) && (J[1] < 1 || J[end] > n))
throw(BoundsError(A, (I, J)))
end
if isempty(I) || isempty(J)
return A
end

issortedI = issorted(I)
issortedJ = issorted(J)

if !issortedI && !issortedJ
pI = sortperm(I); @inbounds I = I[pI]
pJ = sortperm(J); @inbounds J = J[pJ]
Expand All @@ -2905,20 +2912,6 @@ function setindex!(A::AbstractSparseMatrixCSC{Tv,Ti}, V::AbstractVecOrMat, Ix::U
B = B[:, pJ]
end

m, n = size(A)
mB, nB = size(B)

if (!isempty(I) && (I[1] < 1 || I[end] > m)) || (!isempty(J) && (J[1] < 1 || J[end] > n))
throw(BoundsError(A, (I, J)))
end

if isempty(I) || isempty(J)
return A
end

nI = length(I)
nJ = length(J)

colptrA = getcolptr(A); rowvalA = rowvals(A); nzvalA = nonzeros(A)
colptrB = getcolptr(B); rowvalB = rowvals(B); nzvalB = nonzeros(B)

Expand All @@ -2932,7 +2925,6 @@ function setindex!(A::AbstractSparseMatrixCSC{Tv,Ti}, V::AbstractVecOrMat, Ix::U
resize!(nzvalA, nnzS)

colB = 1
asgn_col = J[colB]

I_asgn = falses(m)
fill!(view(I_asgn, I), true)
Expand Down

0 comments on commit 2f3d1ea

Please sign in to comment.