Skip to content

Commit

Permalink
Return next insert position from stuffcol helper
Browse files Browse the repository at this point in the history
Simplifies updating the insert position at the call site.
  • Loading branch information
mjacobse committed Apr 21, 2024
1 parent b961a7f commit 6db2712
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
11 changes: 5 additions & 6 deletions src/sparsematrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3911,9 +3911,8 @@ function vcat(X::AbstractSparseMatrixCSC...)
col_length = colptrXi[c + 1] - colptrXi[c]
ptr_Xi = colptrXi[c]

stuffcol!(rowval, nzval, ptr_res, rowvals(X[i]), nonzeros(X[i]), ptr_Xi, col_length, mX_sofar)

ptr_res += col_length
ptr_res = stuffcol!(rowval, nzval, ptr_res, rowvals(X[i]), nonzeros(X[i]), ptr_Xi,
col_length, mX_sofar)
mX_sofar += mX[i]
end
colptr[c + 1] = ptr_res
Expand All @@ -3928,6 +3927,7 @@ end
@inbounds nzval[k] = nzvalXi[ptr_Xi]
ptr_Xi += 1
end
return ptr_res + col_length
end

function hcat(X::AbstractSparseMatrixCSC...)
Expand Down Expand Up @@ -3984,9 +3984,8 @@ function Base.repeat(A::AbstractSparseMatrixCSC, m)
col_length = getcolptr(A)[c + 1] - ptr_source
for index_repetition = 0 : (m - 1)
row_offset = index_repetition * size(A, 1)
stuffcol!(rowval, nzval, ptr_res, rowvals(A), nonzeros(A), ptr_source,
col_length, row_offset)
ptr_res += col_length
ptr_res = stuffcol!(rowval, nzval, ptr_res, rowvals(A), nonzeros(A), ptr_source,
col_length, row_offset)
end
colptr[c + 1] = ptr_res
end
Expand Down
3 changes: 1 addition & 2 deletions src/sparsevector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1320,8 +1320,7 @@ function Base.repeat(v::AbstractSparseVector, m)
ptr_res = 1
for index_repetition = 0:(m-1)
row_offset = index_repetition * length(v)
stuffcol!(nzind, nzval, ptr_res, nonzeroinds(v), nonzeros(v), 1, nnz_source, row_offset)
ptr_res += nnz_source
ptr_res = stuffcol!(nzind, nzval, ptr_res, nonzeroinds(v), nonzeros(v), 1, nnz_source, row_offset)
end
@assert ptr_res == nnz_new + 1

Expand Down

0 comments on commit 6db2712

Please sign in to comment.