diff --git a/stdlib/SparseArrays/src/higherorderfns.jl b/stdlib/SparseArrays/src/higherorderfns.jl index 10def3e59aa1a..5d1043c6c73ba 100644 --- a/stdlib/SparseArrays/src/higherorderfns.jl +++ b/stdlib/SparseArrays/src/higherorderfns.jl @@ -9,7 +9,7 @@ import Base: map, map!, broadcast, copy, copyto! using Base: front, tail, to_shape using ..SparseArrays: SparseVector, SparseMatrixCSC, AbstractSparseVector, AbstractSparseMatrix, AbstractSparseArray, indtype, nnz, nzrange, - SparseVectorUnion, AdjOrTransSparseVectorUnion, nonzeroinds, nonzeros, rowvals, getcolptr + SparseVectorUnion, AdjOrTransSparseVectorUnion, nonzeroinds, nonzeros, rowvals, colptrs using Base.Broadcast: BroadcastStyle, Broadcasted, flatten using LinearAlgebra @@ -119,13 +119,13 @@ const SpBroadcasted2{Style<:SPVM,Axes,F,Args<:Tuple{SparseVecOrMat,SparseVecOrMa @inline colrange(A::SparseMatrixCSC, j) = nzrange(A, j) @inline colstartind(A::SparseVector, j) = one(indtype(A)) @inline colboundind(A::SparseVector, j) = convert(indtype(A), length(nonzeroinds(A)) + 1) -@inline colstartind(A::SparseMatrixCSC, j) = getcolptr(A)[j] -@inline colboundind(A::SparseMatrixCSC, j) = getcolptr(A)[j + 1] +@inline colstartind(A::SparseMatrixCSC, j) = colptrs(A)[j] +@inline colboundind(A::SparseMatrixCSC, j) = colptrs(A)[j + 1] @inline storedinds(A::SparseVector) = nonzeroinds(A) @inline storedinds(A::SparseMatrixCSC) = rowvals(A) @inline storedvals(A::SparseVecOrMat) = nonzeros(A) @inline setcolptr!(A::SparseVector, j, val) = val -@inline setcolptr!(A::SparseMatrixCSC, j, val) = getcolptr(A)[j] = val +@inline setcolptr!(A::SparseMatrixCSC, j, val) = colptrs(A)[j] = val function trimstorage!(A::SparseVecOrMat, maxstored) resize!(storedinds(A), maxstored) resize!(storedvals(A), maxstored) @@ -286,7 +286,7 @@ end function _densestructure!(A::SparseMatrixCSC) nnzA = size(A, 1) * size(A, 2) expandstorage!(A, nnzA) - copyto!(getcolptr(A), 1:size(A, 1):(nnzA + 1)) + copyto!(colptrs(A), 1:size(A, 1):(nnzA + 1)) for k in _densecoloffsets(A) copyto!(rowvals(A), k + 1, 1:size(A, 1)) end @@ -812,7 +812,7 @@ function _broadcast_notzeropres!(f::Tf, fillvalue, C::SparseVecOrMat, A::SparseV return C end _finishempty!(C::SparseVector) = C -_finishempty!(C::SparseMatrixCSC) = (fill!(getcolptr(C), 1); C) +_finishempty!(C::SparseMatrixCSC) = (fill!(colptrs(C), 1); C) # special case - vector outer product _copy(f::typeof(*), x::SparseVectorUnion, y::AdjOrTransSparseVectorUnion) = _outer(x, y) diff --git a/stdlib/SparseArrays/src/linalg.jl b/stdlib/SparseArrays/src/linalg.jl index ea79fa2e3421c..34ce442599679 100644 --- a/stdlib/SparseArrays/src/linalg.jl +++ b/stdlib/SparseArrays/src/linalg.jl @@ -43,7 +43,7 @@ function mul!(C::StridedVecOrMat, A::SparseMatrixCSC, B::Union{StridedVector,Adj for k = 1:size(C, 2) @inbounds for col = 1:size(A, 2) αxj = B[col,k] * α - for j = getcolptr(A)[col]:(getcolptr(A)[col + 1] - 1) + for j = colptrs(A)[col]:(colptrs(A)[col + 1] - 1) C[rv[j], k] += nzv[j]*αxj end end @@ -68,7 +68,7 @@ function mul!(C::StridedVecOrMat, adjA::Adjoint{<:Any,<:SparseMatrixCSC}, B::Uni for k = 1:size(C, 2) @inbounds for col = 1:size(A, 2) tmp = zero(eltype(C)) - for j = getcolptr(A)[col]:(getcolptr(A)[col + 1] - 1) + for j = colptrs(A)[col]:(colptrs(A)[col + 1] - 1) tmp += adjoint(nzv[j])*B[rv[j],k] end C[col,k] += tmp * α @@ -94,7 +94,7 @@ function mul!(C::StridedVecOrMat, transA::Transpose{<:Any,<:SparseMatrixCSC}, B: for k = 1:size(C, 2) @inbounds for col = 1:size(A, 2) tmp = zero(eltype(C)) - for j = getcolptr(A)[col]:(getcolptr(A)[col + 1] - 1) + for j = colptrs(A)[col]:(colptrs(A)[col + 1] - 1) tmp += transpose(nzv[j])*B[rv[j],k] end C[col,k] += tmp * α @@ -126,7 +126,7 @@ function mul!(C::StridedVecOrMat, X::AdjOrTransStridedMatrix, A::SparseMatrixCSC if β != 1 β != 0 ? rmul!(C, β) : fill!(C, zero(eltype(C))) end - @inbounds for multivec_row=1:mX, col = 1:size(A, 2), k=getcolptr(A)[col]:(getcolptr(A)[col+1]-1) + @inbounds for multivec_row=1:mX, col = 1:size(A, 2), k=colptrs(A)[col]:(colptrs(A)[col+1]-1) C[multivec_row, col] += α * X[multivec_row, rv[k]] * nzv[k] # perhaps suboptimal position of α? end C @@ -145,7 +145,7 @@ function mul!(C::StridedVecOrMat, X::AdjOrTransStridedMatrix, adjA::Adjoint{<:An if β != 1 β != 0 ? rmul!(C, β) : fill!(C, zero(eltype(C))) end - @inbounds for col = 1:size(A, 2), k=getcolptr(A)[col]:(getcolptr(A)[col+1]-1), multivec_col=1:mX + @inbounds for col = 1:size(A, 2), k=colptrs(A)[col]:(colptrs(A)[col+1]-1), multivec_col=1:mX C[multivec_col, rv[k]] += α * X[multivec_col, col] * adjoint(nzv[k]) # perhaps suboptimal position of α? end C @@ -164,7 +164,7 @@ function mul!(C::StridedVecOrMat, X::AdjOrTransStridedMatrix, transA::Transpose{ if β != 1 β != 0 ? rmul!(C, β) : fill!(C, zero(eltype(C))) end - @inbounds for col = 1:size(A, 2), k=getcolptr(A)[col]:(getcolptr(A)[col+1]-1), multivec_col=1:mX + @inbounds for col = 1:size(A, 2), k=colptrs(A)[col]:(colptrs(A)[col+1]-1), multivec_col=1:mX C[multivec_col, rv[k]] += α * X[multivec_col, col] * transpose(nzv[k]) # perhaps suboptimal position of α? end C @@ -296,8 +296,8 @@ function dot(A::SparseMatrixCSC{T1,S1},B::SparseMatrixCSC{T2,S2}) where {T1,T2,S size(B) == (m,n) || throw(DimensionMismatch("matrices must have the same dimensions")) r = dot(zero(T1), zero(T2)) @inbounds for j = 1:n - ia = getcolptr(A)[j]; ia_nxt = getcolptr(A)[j+1] - ib = getcolptr(B)[j]; ib_nxt = getcolptr(B)[j+1] + ia = colptrs(A)[j]; ia_nxt = colptrs(A)[j+1] + ib = colptrs(B)[j]; ib_nxt = colptrs(B)[j+1] if ia < ia_nxt && ib < ib_nxt ra = rowvals(A)[ia]; rb = rowvals(B)[ib] while true @@ -376,7 +376,7 @@ function _lmul!(U::UpperTriangularPlain, B::StridedVecOrMat) nrowB, ncolB = size(B, 1), size(B, 2) aa = getnzval(A) ja = getrowval(A) - ia = getcolptr(A) + ia = colptrs(A) joff = 0 for k = 1:ncolB @@ -417,7 +417,7 @@ function _lmul!(L::LowerTriangularPlain, B::StridedVecOrMat) nrowB, ncolB = size(B, 1), size(B, 2) aa = getnzval(A) ja = getrowval(A) - ia = getcolptr(A) + ia = colptrs(A) joff = 0 for k = 1:ncolB @@ -459,7 +459,7 @@ function _lmul!(U::UpperTriangularWrapped, B::StridedVecOrMat) nrowB, ncolB = size(B, 1), size(B, 2) aa = getnzval(A) ja = getrowval(A) - ia = getcolptr(A) + ia = colptrs(A) Z = zero(eltype(A)) joff = 0 @@ -499,7 +499,7 @@ function _lmul!(L::LowerTriangularWrapped, B::StridedVecOrMat) nrowB, ncolB = size(B, 1), size(B, 2) aa = getnzval(A) ja = getrowval(A) - ia = getcolptr(A) + ia = colptrs(A) Z = zero(eltype(A)) joff = 0 @@ -549,7 +549,7 @@ function _ldiv!(L::LowerTriangularPlain, B::StridedVecOrMat) nrowB, ncolB = size(B, 1), size(B, 2) aa = getnzval(A) ja = getrowval(A) - ia = getcolptr(A) + ia = colptrs(A) joff = 0 for k = 1:ncolB @@ -591,7 +591,7 @@ function _ldiv!(U::UpperTriangularPlain, B::StridedVecOrMat) nrowB, ncolB = size(B, 1), size(B, 2) aa = getnzval(A) ja = getrowval(A) - ia = getcolptr(A) + ia = colptrs(A) joff = 0 for k = 1:ncolB @@ -634,7 +634,7 @@ function _ldiv!(L::LowerTriangularWrapped, B::StridedVecOrMat) nrowB, ncolB = size(B, 1), size(B, 2) aa = getnzval(A) ja = getrowval(A) - ia = getcolptr(A) + ia = colptrs(A) joff = 0 for k = 1:ncolB @@ -680,7 +680,7 @@ function _ldiv!(U::UpperTriangularWrapped, B::StridedVecOrMat) nrowB, ncolB = size(B, 1), size(B, 2) aa = getnzval(A) ja = getrowval(A) - ia = getcolptr(A) + ia = colptrs(A) joff = 0 for k = 1:ncolB @@ -817,7 +817,7 @@ function ldiv!(D::Diagonal{T}, A::SparseMatrixCSC{T}) where {T} for i=1:length(b) iszero(b[i]) && throw(SingularException(i)) end - @inbounds for col = 1:size(A, 2), p = getcolptr(A)[col]:(getcolptr(A)[col + 1] - 1) + @inbounds for col = 1:size(A, 2), p = colptrs(A)[col]:(colptrs(A)[col + 1] - 1) nonz[p] = b[Arowval[p]] \ nonz[p] end A @@ -837,7 +837,7 @@ function triu(S::SparseMatrixCSC{Tv,Ti}, k::Integer=0) where {Tv,Ti} colptr[col] = 1 end for col = max(k+1,1) : n - for c1 = getcolptr(S)[col] : getcolptr(S)[col+1]-1 + for c1 = colptrs(S)[col] : colptrs(S)[col+1]-1 rowvals(S)[c1] > col - k && break nnz += 1 end @@ -847,8 +847,8 @@ function triu(S::SparseMatrixCSC{Tv,Ti}, k::Integer=0) where {Tv,Ti} nzval = Vector{Tv}(undef, nnz) A = SparseMatrixCSC(m, n, colptr, rowval, nzval) for col = max(k+1,1) : n - c1 = getcolptr(S)[col] - for c2 = getcolptr(A)[col] : getcolptr(A)[col+1]-1 + c1 = colptrs(S)[col] + for c2 = colptrs(A)[col] : colptrs(A)[col+1]-1 rowvals(A)[c2] = rowvals(S)[c1] nonzeros(A)[c2] = nonzeros(S)[c1] c1 += 1 @@ -863,8 +863,8 @@ function tril(S::SparseMatrixCSC{Tv,Ti}, k::Integer=0) where {Tv,Ti} nnz = 0 colptr[1] = 1 for col = 1 : min(n, m+k) - l1 = getcolptr(S)[col+1]-1 - for c1 = 0 : (l1 - getcolptr(S)[col]) + l1 = colptrs(S)[col+1]-1 + for c1 = 0 : (l1 - colptrs(S)[col]) rowvals(S)[l1 - c1] < col - k && break nnz += 1 end @@ -877,9 +877,9 @@ function tril(S::SparseMatrixCSC{Tv,Ti}, k::Integer=0) where {Tv,Ti} nzval = Vector{Tv}(undef, nnz) A = SparseMatrixCSC(m, n, colptr, rowval, nzval) for col = 1 : min(n, m+k) - c1 = getcolptr(S)[col+1]-1 - l2 = getcolptr(A)[col+1]-1 - for c2 = 0 : l2 - getcolptr(A)[col] + c1 = colptrs(S)[col+1]-1 + l2 = colptrs(A)[col+1]-1 + for c2 = 0 : l2 - colptrs(A)[col] rowvals(A)[l2 - c2] = rowvals(S)[c1] nonzeros(A)[l2 - c2] = nonzeros(S)[c1] c1 -= 1 @@ -902,7 +902,7 @@ function sparse_diff1(S::SparseMatrixCSC{Tv,Ti}) where {Tv,Ti} for col = 1 : n last_row = 0 last_val = 0 - for k = getcolptr(S)[col] : getcolptr(S)[col+1]-1 + for k = colptrs(S)[col] : colptrs(S)[col+1]-1 row = rowvals(S)[k] val = nonzeros(S)[k] if row > 1 @@ -939,7 +939,7 @@ function sparse_diff2(a::SparseMatrixCSC{Tv,Ti}) where {Tv,Ti} z = zero(Tv) - colptr_a = getcolptr(a) + colptr_a = colptrs(a) rowval_a = rowvals(a) nzval_a = nonzeros(a) @@ -1045,7 +1045,7 @@ function opnorm(A::SparseMatrixCSC, p::Real=2) nA::Tsum = 0 for j=1:n colSum::Tsum = 0 - for i = getcolptr(A)[j]:getcolptr(A)[j+1]-1 + for i = colptrs(A)[j]:colptrs(A)[j+1]-1 colSum += abs(nonzeros(A)[i]) end nA = max(nA, colSum) @@ -1261,12 +1261,12 @@ function kron(A::SparseMatrixCSC{T1,S1}, B::SparseMatrixCSC{T2,S2}) where {T1,S1 colptrC[1] = 1 col = 1 @inbounds for j = 1:nA - startA = getcolptr(A)[j] - stopA = getcolptr(A)[j+1] - 1 + startA = colptrs(A)[j] + stopA = colptrs(A)[j+1] - 1 lA = stopA - startA + 1 for i = 1:nB - startB = getcolptr(B)[i] - stopB = getcolptr(B)[i+1] - 1 + startB = colptrs(B)[i] + stopB = colptrs(B)[i+1] - 1 lB = stopB - startB + 1 ptr_range = (1:lB) .+ (colptrC[col]-1) colptrC[col+1] = colptrC[col] + lA*lB @@ -1324,9 +1324,9 @@ inv(A::SparseMatrixCSC) = error("The inverse of a sparse matrix can often be den # Copy colptr and rowval from one sparse matrix to another function copyinds!(C::SparseMatrixCSC, A::SparseMatrixCSC) - if getcolptr(C) !== getcolptr(A) - resize!(getcolptr(C), length(getcolptr(A))) - copyto!(getcolptr(C), getcolptr(A)) + if colptrs(C) !== colptrs(A) + resize!(colptrs(C), length(colptrs(A))) + copyto!(colptrs(C), colptrs(A)) end if rowvals(C) !== rowvals(A) resize!(rowvals(C), length(rowvals(A))) @@ -1343,7 +1343,7 @@ function mul!(C::SparseMatrixCSC, A::SparseMatrixCSC, D::Diagonal{T, <:Vector}) Cnzval = nonzeros(C) Anzval = nonzeros(A) resize!(Cnzval, length(Anzval)) - for col = 1:n, p = getcolptr(A)[col]:(getcolptr(A)[col+1]-1) + for col = 1:n, p = colptrs(A)[col]:(colptrs(A)[col+1]-1) @inbounds Cnzval[p] = Anzval[p] * b[col] end C @@ -1358,7 +1358,7 @@ function mul!(C::SparseMatrixCSC, D::Diagonal{T, <:Vector}, A::SparseMatrixCSC) Anzval = nonzeros(A) Arowval = rowvals(A) resize!(Cnzval, length(Anzval)) - for col = 1:n, p = getcolptr(A)[col]:(getcolptr(A)[col+1]-1) + for col = 1:n, p = colptrs(A)[col]:(colptrs(A)[col+1]-1) @inbounds Cnzval[p] = b[Arowval[p]] * Anzval[p] end C @@ -1394,7 +1394,7 @@ function rmul!(A::SparseMatrixCSC, D::Diagonal) m, n = size(A) (n == size(D, 1)) || throw(DimensionMismatch()) Anzval = nonzeros(A) - @inbounds for col = 1:n, p = getcolptr(A)[col]:(getcolptr(A)[col + 1] - 1) + @inbounds for col = 1:n, p = colptrs(A)[col]:(colptrs(A)[col + 1] - 1) Anzval[p] = Anzval[p] * D.diag[col] end return A @@ -1405,7 +1405,7 @@ function lmul!(D::Diagonal, A::SparseMatrixCSC) (m == size(D, 2)) || throw(DimensionMismatch()) Anzval = nonzeros(A) Arowval = rowvals(A) - @inbounds for col = 1:n, p = getcolptr(A)[col]:(getcolptr(A)[col + 1] - 1) + @inbounds for col = 1:n, p = colptrs(A)[col]:(colptrs(A)[col + 1] - 1) Anzval[p] = D.diag[Arowval[p]] * Anzval[p] end return A diff --git a/stdlib/SparseArrays/src/sparsematrix.jl b/stdlib/SparseArrays/src/sparsematrix.jl index 5c225285045b3..ecc09b2ad4eed 100644 --- a/stdlib/SparseArrays/src/sparsematrix.jl +++ b/stdlib/SparseArrays/src/sparsematrix.jl @@ -75,16 +75,16 @@ size(S::SparseMatrixCSC) = (getfield(S, :m), getfield(S, :n)) # Define an alias for views of a SparseMatrixCSC which include all rows and a unit range of the columns. # Also define a union of SparseMatrixCSC and this view since many methods can be defined efficiently for -# this union by extracting the fields via the get function: getcolptr, getrowval, and getnzval. The key -# insight is that getcolptr on a SparseMatrixCSCView returns an offset view of the colptr of the +# this union by extracting the fields via the get function: colptrs, getrowval, and getnzval. The key +# insight is that colptrs on a SparseMatrixCSCView returns an offset view of the colptr of the # underlying SparseMatrixCSC const SparseMatrixCSCView{Tv,Ti} = SubArray{Tv,2,SparseMatrixCSC{Tv,Ti}, Tuple{Base.Slice{Base.OneTo{Int}},I}} where {I<:AbstractUnitRange} const SparseMatrixCSCUnion{Tv,Ti} = Union{SparseMatrixCSC{Tv,Ti}, SparseMatrixCSCView{Tv,Ti}} -getcolptr(S::SparseMatrixCSC) = getfield(S, :colptr) -getcolptr(S::SparseMatrixCSCView) = view(getcolptr(parent(S)), first(axes(S, 2)):(last(axes(S, 2)) + 1)) +colptrs(S::SparseMatrixCSC) = getfield(S, :colptr) +colptrs(S::SparseMatrixCSCView) = view(colptrs(parent(S)), first(axes(S, 2)):(last(axes(S, 2)) + 1)) getrowval(S::SparseMatrixCSC) = rowvals(S) getrowval(S::SparseMatrixCSCView) = rowvals(parent(S)) getnzval( S::SparseMatrixCSC) = nonzeros(S) @@ -108,7 +108,7 @@ julia> nnz(A) 3 ``` """ -nnz(S::SparseMatrixCSC) = Int(getcolptr(S)[size(S, 2) + 1] - 1) +nnz(S::SparseMatrixCSC) = Int(colptrs(S)[size(S, 2) + 1] - 1) nnz(S::ReshapedArray{T,1,<:SparseMatrixCSC}) where T = nnz(parent(S)) count(pred, S::SparseMatrixCSC) = count(pred, nzvalview(S)) + pred(zero(eltype(S)))*(prod(size(S)) - nnz(S)) @@ -184,7 +184,7 @@ column. In conjunction with [`nonzeros`](@ref) and end end """ -nzrange(S::SparseMatrixCSC, col::Integer) = getcolptr(S)[col]:(getcolptr(S)[col+1]-1) +nzrange(S::SparseMatrixCSC, col::Integer) = colptrs(S)[col]:(colptrs(S)[col+1]-1) nzrange(S::SparseMatrixCSCView, col::Integer) = nzrange(S.parent, S.indices[2][col]) function Base.show(io::IO, ::MIME"text/plain", S::SparseMatrixCSC) @@ -213,10 +213,10 @@ function Base.show(io::IOContext, S::SparseMatrixCSC) end function _get_cols(from, to) - idx = eltype(getcolptr(S))[] - c = searchsortedlast(getcolptr(S), from) + idx = eltype(colptrs(S))[] + c = searchsortedlast(colptrs(S), from) for i = from:to - while i == getcolptr(S)[c+1] + while i == colptrs(S)[c+1] c +=1 end push!(idx, c) @@ -287,24 +287,24 @@ function copy(ra::ReshapedArray{<:Any,2,<:SparseMatrixCSC}) a = parent(ra) mA,nA = size(a) numnz = nnz(a) - colptr = similar(getcolptr(a), nS+1) + colptr = similar(colptrs(a), nS+1) rowval = similar(rowvals(a)) nzval = copy(nonzeros(a)) - sparse_compute_reshaped_colptr_and_rowval(colptr, rowval, mS, nS, getcolptr(a), rowvals(a), mA, nA) + sparse_compute_reshaped_colptr_and_rowval(colptr, rowval, mS, nS, colptrs(a), rowvals(a), mA, nA) return SparseMatrixCSC(mS, nS, colptr, rowval, nzval) end ## Alias detection and prevention using Base: dataids, unaliascopy -Base.dataids(S::SparseMatrixCSC) = (dataids(getcolptr(S))..., dataids(rowvals(S))..., dataids(nonzeros(S))...) -Base.unaliascopy(S::SparseMatrixCSC) = typeof(S)(size(S, 1), size(S, 2), unaliascopy(getcolptr(S)), unaliascopy(rowvals(S)), unaliascopy(nonzeros(S))) +Base.dataids(S::SparseMatrixCSC) = (dataids(colptrs(S))..., dataids(rowvals(S))..., dataids(nonzeros(S))...) +Base.unaliascopy(S::SparseMatrixCSC) = typeof(S)(size(S, 1), size(S, 2), unaliascopy(colptrs(S)), unaliascopy(rowvals(S)), unaliascopy(nonzeros(S))) ## Constructors copy(S::SparseMatrixCSC) = - SparseMatrixCSC(size(S, 1), size(S, 2), copy(getcolptr(S)), copy(rowvals(S)), copy(nonzeros(S))) + SparseMatrixCSC(size(S, 1), size(S, 2), copy(colptrs(S)), copy(rowvals(S)), copy(nonzeros(S))) function copyto!(A::SparseMatrixCSC, B::SparseMatrixCSC) # If the two matrices have the same length then all the @@ -314,11 +314,11 @@ function copyto!(A::SparseMatrixCSC, B::SparseMatrixCSC) resize!(rowvals(A), length(rowvals(B))) if size(A) == size(B) # Simple case: we can simply copy the internal fields of B to A. - copyto!(getcolptr(A), getcolptr(B)) + copyto!(colptrs(A), colptrs(B)) copyto!(rowvals(A), rowvals(B)) else # This is like a "reshape B into A". - sparse_compute_reshaped_colptr_and_rowval(getcolptr(A), rowvals(A), size(A, 1), size(A, 2), getcolptr(B), rowvals(B), size(B, 1), size(B, 2)) + sparse_compute_reshaped_colptr_and_rowval(colptrs(A), rowvals(A), size(A, 1), size(A, 2), colptrs(B), rowvals(B), size(B, 1), size(B, 2)) end else length(A) >= length(B) || throw(BoundsError()) @@ -328,8 +328,8 @@ function copyto!(A::SparseMatrixCSC, B::SparseMatrixCSC) # Up to which col, row, and ptr in rowval/nzval will A be overwritten? lastmodcolA = div(lB - 1, size(A, 1)) + 1 lastmodrowA = mod(lB - 1, size(A, 1)) + 1 - lastmodptrA = getcolptr(A)[lastmodcolA] - while lastmodptrA < getcolptr(A)[lastmodcolA+1] && rowvals(A)[lastmodptrA] <= lastmodrowA + lastmodptrA = colptrs(A)[lastmodcolA] + while lastmodptrA < colptrs(A)[lastmodcolA+1] && rowvals(A)[lastmodptrA] <= lastmodrowA lastmodptrA += 1 end lastmodptrA -= 1 @@ -345,10 +345,10 @@ function copyto!(A::SparseMatrixCSC, B::SparseMatrixCSC) copyto!(nonzeros(A), nnzB+1, nonzeros(A), lastmodptrA+1, nnzA-lastmodptrA) end # Adjust colptr accordingly. - @inbounds for i in 2:length(getcolptr(A)) - getcolptr(A)[i] += nnzB - lastmodptrA + @inbounds for i in 2:length(colptrs(A)) + colptrs(A)[i] += nnzB - lastmodptrA end - sparse_compute_reshaped_colptr_and_rowval(getcolptr(A), rowvals(A), size(A, 1), lastmodcolA-1, getcolptr(B), rowvals(B), size(B, 1), size(B, 2)) + sparse_compute_reshaped_colptr_and_rowval(colptrs(A), rowvals(A), size(A, 1), lastmodcolA-1, colptrs(B), rowvals(B), size(B, 1), size(B, 2)) end copyto!(nonzeros(A), nonzeros(B)) return A @@ -358,7 +358,7 @@ end # # parent method for similar that preserves stored-entry structure (for when new and old dims match) function _sparsesimilar(S::SparseMatrixCSC, ::Type{TvNew}, ::Type{TiNew}) where {TvNew,TiNew} - newcolptr = copyto!(similar(getcolptr(S), TiNew), getcolptr(S)) + newcolptr = copyto!(similar(colptrs(S), TiNew), colptrs(S)) newrowval = copyto!(similar(rowvals(S), TiNew), rowvals(S)) return SparseMatrixCSC(size(S, 1), size(S, 2), newcolptr, newrowval, similar(nonzeros(S), TvNew)) end @@ -394,10 +394,10 @@ similar(S::SparseMatrixCSC, ::Type{TvNew}, ::Type{TiNew}, m::Integer, n::Integer SparseMatrixCSC(S::SparseMatrixCSC) = copy(S) AbstractMatrix{Tv}(A::SparseMatrixCSC) where {Tv} = SparseMatrixCSC{Tv}(A) SparseMatrixCSC{Tv}(S::SparseMatrixCSC{Tv}) where {Tv} = copy(S) -SparseMatrixCSC{Tv}(S::SparseMatrixCSC) where {Tv} = SparseMatrixCSC{Tv,eltype(getcolptr(S))}(S) +SparseMatrixCSC{Tv}(S::SparseMatrixCSC) where {Tv} = SparseMatrixCSC{Tv,eltype(colptrs(S))}(S) SparseMatrixCSC{Tv,Ti}(S::SparseMatrixCSC{Tv,Ti}) where {Tv,Ti} = copy(S) function SparseMatrixCSC{Tv,Ti}(S::SparseMatrixCSC) where {Tv,Ti} - eltypeTicolptr = convert(Vector{Ti}, getcolptr(S)) + eltypeTicolptr = convert(Vector{Ti}, colptrs(S)) eltypeTirowval = convert(Vector{Ti}, rowvals(S)) eltypeTvnzval = convert(Vector{Tv}, nonzeros(S)) return SparseMatrixCSC(size(S, 1), size(S, 2), eltypeTicolptr, eltypeTirowval, eltypeTvnzval) @@ -560,8 +560,8 @@ Array(S::SparseMatrixCSC) = Matrix(S) convert(T::Type{<:SparseMatrixCSC}, m::AbstractMatrix) = m isa T ? m : T(m) -float(S::SparseMatrixCSC) = SparseMatrixCSC(size(S, 1), size(S, 2), copy(getcolptr(S)), copy(rowvals(S)), float.(nonzeros(S))) -complex(S::SparseMatrixCSC) = SparseMatrixCSC(size(S, 1), size(S, 2), copy(getcolptr(S)), copy(rowvals(S)), complex(copy(nonzeros(S)))) +float(S::SparseMatrixCSC) = SparseMatrixCSC(size(S, 1), size(S, 2), copy(colptrs(S)), copy(rowvals(S)), float.(nonzeros(S))) +complex(S::SparseMatrixCSC) = SparseMatrixCSC(size(S, 1), size(S, 2), copy(colptrs(S)), copy(rowvals(S)), complex(copy(nonzeros(S)))) """ sparse(A) @@ -885,28 +885,28 @@ function halfperm!(X::SparseMatrixCSC{Tv,Ti}, A::SparseMatrixCSC{Tv,Ti}, end """ Helper method for `halfperm!`. Computes `transpose(A[:,q])`'s column pointers, storing them -shifted one position forward in `getcolptr(X)`; `_distributevals_halfperm!` fixes this shift. +shifted one position forward in `colptrs(X)`; `_distributevals_halfperm!` fixes this shift. """ function _computecolptrs_halfperm!(X::SparseMatrixCSC{Tv,Ti}, A::SparseMatrixCSC{Tv,Ti}) where {Tv,Ti} - # Compute `transpose(A[:,q])`'s column counts. Store shifted forward one position in getcolptr(X). - fill!(getcolptr(X), 0) + # Compute `transpose(A[:,q])`'s column counts. Store shifted forward one position in colptrs(X). + fill!(colptrs(X), 0) @inbounds for k in 1:nnz(A) - getcolptr(X)[rowvals(A)[k] + 1] += 1 + colptrs(X)[rowvals(A)[k] + 1] += 1 end - # Compute `transpose(A[:,q])`'s column pointers. Store shifted forward one position in getcolptr(X). - getcolptr(X)[1] = 1 + # Compute `transpose(A[:,q])`'s column pointers. Store shifted forward one position in colptrs(X). + colptrs(X)[1] = 1 countsum = 1 @inbounds for k in 2:(size(A, 1) + 1) - overwritten = getcolptr(X)[k] - getcolptr(X)[k] = countsum + overwritten = colptrs(X)[k] + colptrs(X)[k] = countsum countsum += overwritten end end """ Helper method for `halfperm!`. With `transpose(A[:,q])`'s column pointers shifted one -position forward in `getcolptr(X)`, computes `map(f, transpose(A[:,q]))` by appropriately +position forward in `colptrs(X)`, computes `map(f, transpose(A[:,q]))` by appropriately distributing `rowvals(A)` and `f`-transformed `nonzeros(A)` into `rowvals(X)` and `nonzeros(X)` -respectively. Simultaneously fixes the one-position-forward shift in `getcolptr(X)`. +respectively. Simultaneously fixes the one-position-forward shift in `colptrs(X)`. """ @noinline function _distributevals_halfperm!(X::SparseMatrixCSC{Tv,Ti}, A::SparseMatrixCSC{Tv,Ti}, q::AbstractVector{<:Integer}, f::Function) where {Tv,Ti} @@ -914,10 +914,10 @@ respectively. Simultaneously fixes the one-position-forward shift in `getcolptr( Aj = q[Xi] for Ak in nzrange(A, Aj) Ai = rowvals(A)[Ak] - Xk = getcolptr(X)[Ai + 1] + Xk = colptrs(X)[Ai + 1] rowvals(X)[Xk] = Xi nonzeros(X)[Xk] = f(nonzeros(A)[Ak]) - getcolptr(X)[Ai + 1] += 1 + colptrs(X)[Ai + 1] += 1 end end return # kill potential type instability @@ -988,7 +988,7 @@ function unchecked_noalias_permute!(X::SparseMatrixCSC{Tv,Ti}, A::SparseMatrixCSC{Tv,Ti}, p::AbstractVector{<:Integer}, q::AbstractVector{<:Integer}, C::SparseMatrixCSC{Tv,Ti}) where {Tv,Ti} halfperm!(C, A, q) - _computecolptrs_permute!(X, A, q, getcolptr(X)) + _computecolptrs_permute!(X, A, q, colptrs(X)) _distributevals_halfperm!(X, C, p, identity) return X end @@ -1014,7 +1014,7 @@ function unchecked_aliasing_permute!(A::SparseMatrixCSC{Tv,Ti}, end """ Helper method for `unchecked_noalias_permute!` and `unchecked_aliasing_permute!`. -Computes `PAQ`'s column pointers, storing them shifted one position forward in `getcolptr(X)`; +Computes `PAQ`'s column pointers, storing them shifted one position forward in `colptrs(X)`; `_distributevals_halfperm!` fixes this shift. Saves some work relative to `_computecolptrs_halfperm!` as described in `uncheckednoalias_permute!`'s documentation. """ @@ -1022,14 +1022,14 @@ function _computecolptrs_permute!(X::SparseMatrixCSC{Tv,Ti}, A::SparseMatrixCSC{Tv,Ti}, q::AbstractVector{<:Integer}, workcolptr::Vector{Ti}) where {Tv,Ti} # Compute `A[p,q]`'s column counts. Store shifted forward one position in workcolptr. @inbounds for k in 1:size(A, 2) - workcolptr[k+1] = getcolptr(A)[q[k] + 1] - getcolptr(A)[q[k]] + workcolptr[k+1] = colptrs(A)[q[k] + 1] - colptrs(A)[q[k]] end - # Compute `A[p,q]`'s column pointers. Store shifted forward one position in getcolptr(X). - getcolptr(X)[1] = 1 + # Compute `A[p,q]`'s column pointers. Store shifted forward one position in colptrs(X). + colptrs(X)[1] = 1 countsum = 1 @inbounds for k in 2:(size(X, 2) + 1) overwritten = workcolptr[k] - getcolptr(X)[k] = countsum + colptrs(X)[k] = countsum countsum += overwritten end end @@ -1169,7 +1169,7 @@ function permute!(X::SparseMatrixCSC{Tv,Ti}, A::SparseMatrixCSC{Tv,Ti}, ones(Ti, size(A, 1) + 1), Vector{Ti}(undef, nnz(A)), Vector{Tv}(undef, nnz(A))) - _checkargs_permutationsvalid_permute!(p, getcolptr(C), q, getcolptr(X)) + _checkargs_permutationsvalid_permute!(p, colptrs(C), q, colptrs(X)) unchecked_noalias_permute!(X, A, p, q, C) end function permute!(X::SparseMatrixCSC{Tv,Ti}, A::SparseMatrixCSC{Tv,Ti}, @@ -1178,7 +1178,7 @@ function permute!(X::SparseMatrixCSC{Tv,Ti}, A::SparseMatrixCSC{Tv,Ti}, _checkargs_sourcecompatdest_permute!(A, X) _checkargs_sourcecompatperms_permute!(A, p, q) _checkargs_sourcecompatworkmat_permute!(A, C) - _checkargs_permutationsvalid_permute!(p, getcolptr(C), q, getcolptr(X)) + _checkargs_permutationsvalid_permute!(p, colptrs(C), q, colptrs(X)) unchecked_noalias_permute!(X, A, p, q, C) end function permute!(A::SparseMatrixCSC{Tv,Ti}, p::AbstractVector{<:Integer}, @@ -1189,7 +1189,7 @@ function permute!(A::SparseMatrixCSC{Tv,Ti}, p::AbstractVector{<:Integer}, Vector{Ti}(undef, nnz(A)), Vector{Tv}(undef, nnz(A))) workcolptr = Vector{Ti}(undef, size(A, 2) + 1) - _checkargs_permutationsvalid_permute!(p, getcolptr(C), q, workcolptr) + _checkargs_permutationsvalid_permute!(p, colptrs(C), q, workcolptr) unchecked_aliasing_permute!(A, p, q, C, workcolptr) end function permute!(A::SparseMatrixCSC{Tv,Ti}, p::AbstractVector{<:Integer}, @@ -1197,7 +1197,7 @@ function permute!(A::SparseMatrixCSC{Tv,Ti}, p::AbstractVector{<:Integer}, _checkargs_sourcecompatperms_permute!(A, p, q) _checkargs_sourcecompatworkmat_permute!(A, C) workcolptr = Vector{Ti}(undef, size(A, 2) + 1) - _checkargs_permutationsvalid_permute!(p, getcolptr(C), q, workcolptr) + _checkargs_permutationsvalid_permute!(p, colptrs(C), q, workcolptr) unchecked_aliasing_permute!(A, p, q, C, workcolptr) end function permute!(A::SparseMatrixCSC{Tv,Ti}, p::AbstractVector{<:Integer}, @@ -1206,7 +1206,7 @@ function permute!(A::SparseMatrixCSC{Tv,Ti}, p::AbstractVector{<:Integer}, _checkargs_sourcecompatperms_permute!(A, p, q) _checkargs_sourcecompatworkmat_permute!(A, C) _checkargs_sourcecompatworkcolptr_permute!(A, workcolptr) - _checkargs_permutationsvalid_permute!(p, getcolptr(C), q, workcolptr) + _checkargs_permutationsvalid_permute!(p, colptrs(C), q, workcolptr) unchecked_aliasing_permute!(A, p, q, C, workcolptr) end """ @@ -1263,7 +1263,7 @@ function permute(A::SparseMatrixCSC{Tv,Ti}, p::AbstractVector{<:Integer}, ones(Ti, size(A, 1) + 1), Vector{Ti}(undef, nnz(A)), Vector{Tv}(undef, nnz(A))) - _checkargs_permutationsvalid_permute!(p, getcolptr(C), q, getcolptr(X)) + _checkargs_permutationsvalid_permute!(p, colptrs(C), q, colptrs(X)) unchecked_noalias_permute!(X, A, p, q, C) end @@ -1299,7 +1299,7 @@ julia> SparseArrays.fkeep!(A, (i, j, v) -> isodd(v)) """ function fkeep!(A::SparseMatrixCSC, f, trim::Bool = true) An = size(A, 2) - Acolptr = getcolptr(A) + Acolptr = colptrs(A) Arowval = rowvals(A) Anzval = nonzeros(A) @@ -1402,7 +1402,7 @@ function findall(p::Function, S::SparseMatrixCSC) inds = Vector{CartesianIndex{2}}(undef, numnz) count = 0 - @inbounds for col = 1 : size(S, 2), k = getcolptr(S)[col] : (getcolptr(S)[col+1]-1) + @inbounds for col = 1 : size(S, 2), k = colptrs(S)[col] : (colptrs(S)[col+1]-1) if p(nonzeros(S)[k]) count += 1 inds[count] = CartesianIndex(rowvals(S)[k], col) @@ -1423,7 +1423,7 @@ function findnz(S::SparseMatrixCSC{Tv,Ti}) where {Tv,Ti} V = Vector{Tv}(undef, numnz) count = 1 - @inbounds for col = 1 : size(S, 2), k = getcolptr(S)[col] : (getcolptr(S)[col+1]-1) + @inbounds for col = 1 : size(S, 2), k = colptrs(S)[col] : (colptrs(S)[col+1]-1) I[count] = rowvals(S)[k] J[count] = col V[count] = nonzeros(S)[k] @@ -1437,14 +1437,14 @@ function _sparse_findnextnz(m::SparseMatrixCSC, ij::CartesianIndex{2}) row, col = Tuple(ij) col > size(m, 2) && return nothing - lo, hi = getcolptr(m)[col], getcolptr(m)[col+1] + lo, hi = colptrs(m)[col], colptrs(m)[col+1] n = searchsortedfirst(rowvals(m), row, lo, hi-1, Base.Order.Forward) if lo <= n <= hi-1 return CartesianIndex(rowvals(m)[n], col) end - nextcol = searchsortedfirst(getcolptr(m), hi + 1, col + 1, length(getcolptr(m)), Base.Order.Forward) - nextcol > length(getcolptr(m)) && return nothing - nextlo = getcolptr(m)[nextcol-1] + nextcol = searchsortedfirst(colptrs(m), hi + 1, col + 1, length(colptrs(m)), Base.Order.Forward) + nextcol > length(colptrs(m)) && return nothing + nextlo = colptrs(m)[nextcol-1] return CartesianIndex(rowvals(m)[nextlo], nextcol - 1) end @@ -1452,14 +1452,14 @@ function _sparse_findprevnz(m::SparseMatrixCSC, ij::CartesianIndex{2}) row, col = Tuple(ij) iszero(col) && return nothing - lo, hi = getcolptr(m)[col], getcolptr(m)[col+1] + lo, hi = colptrs(m)[col], colptrs(m)[col+1] n = searchsortedlast(rowvals(m), row, lo, hi-1, Base.Order.Forward) if lo <= n <= hi-1 return CartesianIndex(rowvals(m)[n], col) end - prevcol = searchsortedlast(getcolptr(m), lo - 1, 1, col - 1, Base.Order.Forward) + prevcol = searchsortedlast(colptrs(m), lo - 1, 1, col - 1, Base.Order.Forward) prevcol < 1 && return nothing - prevhi = getcolptr(m)[prevcol+1] + prevhi = colptrs(m)[prevcol+1] return CartesianIndex(rowvals(m)[prevhi-1], prevcol) end @@ -1611,8 +1611,8 @@ Base.iszero(A::SparseMatrixCSC) = iszero(nzvalview(A)) function Base.isone(A::SparseMatrixCSC) m, n = size(A) - m == n && getcolptr(A)[n+1] >= n+1 || return false - for j in 1:n, k in getcolptr(A)[j]:(getcolptr(A)[j+1] - 1) + m == n && colptrs(A)[n+1] >= n+1 || return false + for j in 1:n, k in colptrs(A)[j]:(colptrs(A)[j+1] - 1) i, x = rowvals(A)[k], nonzeros(A)[k] ifelse(i == j, isone(x), iszero(x)) || return false end @@ -1630,14 +1630,14 @@ end function (-)(A::SparseMatrixCSC) nzval = similar(nonzeros(A)) map!(-, view(nzval, 1:nnz(A)), nzvalview(A)) - return SparseMatrixCSC(size(A, 1), size(A, 2), copy(getcolptr(A)), copy(rowvals(A)), nzval) + return SparseMatrixCSC(size(A, 1), size(A, 2), copy(colptrs(A)), copy(rowvals(A)), nzval) end # the rest of real, conj, imag are handled correctly via AbstractArray methods function conj(A::SparseMatrixCSC{<:Complex}) nzval = similar(nonzeros(A)) map!(conj, view(nzval, 1:nnz(A)), nzvalview(A)) - return SparseMatrixCSC(size(A, 1), size(A, 2), copy(getcolptr(A)), copy(rowvals(A)), nzval) + return SparseMatrixCSC(size(A, 1), size(A, 2), copy(colptrs(A)), copy(rowvals(A)), nzval) end imag(A::SparseMatrixCSC{Tv,Ti}) where {Tv<:Real,Ti} = spzeros(Tv, Ti, size(A, 1), size(A, 2)) @@ -1751,7 +1751,7 @@ end # General mapreducedim function _mapreducerows!(f, op, R::AbstractArray, A::SparseMatrixCSC{T}) where T require_one_based_indexing(A, R) - colptr = getcolptr(A) + colptr = colptrs(A) rowval = rowvals(A) nzval = nonzeros(A) m, n = size(A) @@ -1767,7 +1767,7 @@ end function _mapreducecols!(f, op, R::AbstractArray, A::SparseMatrixCSC{Tv,Ti}) where {Tv,Ti} require_one_based_indexing(A, R) - colptr = getcolptr(A) + colptr = colptrs(A) rowval = rowvals(A) nzval = nonzeros(A) m, n = size(A) @@ -1812,7 +1812,7 @@ function Base._mapreducedim!(f, op, R::AbstractArray, A::SparseMatrixCSC{T}) whe end end else - colptr = getcolptr(A) + colptr = colptrs(A) rowval = rowvals(A) zeroval = f(zero(T)) @inbounds for col = 1:n @@ -1848,7 +1848,7 @@ function _mapreducecols!(f, op::typeof(+), R::AbstractArray, A::SparseMatrixCSC{ end end else - colptr = getcolptr(A) + colptr = colptrs(A) rowval = rowvals(A) zeroval = f(zero(Tv)) if isequal(zeroval, zero(Tv)) @@ -1880,7 +1880,7 @@ end # find first zero value in sparse matrix - return linear index in full matrix # non-structural zeros are identified by x == 0 in line with the sparse constructors. function _findz(A::SparseMatrixCSC{Tv,Ti}, rows=1:size(A, 1), cols=1:size(A, 2)) where {Tv,Ti} - colptr = getcolptr(A); rowval = rowvals(A); nzval = nonzeros(A) + colptr = colptrs(A); rowval = rowvals(A); nzval = nonzeros(A) zval = 0 row = 0 rowmin = rows[1]; rowmax = rows[end] @@ -1917,7 +1917,7 @@ function _findr(op, A, region, Tv) end end - colptr = getcolptr(A); rowval = rowvals(A); nzval = nonzeros(A); m = size(A, 1); n = size(A, 2) + colptr = colptrs(A); rowval = rowvals(A); nzval = nonzeros(A); m = size(A, 1); n = size(A, 2) zval = zero(Tv) szA = size(A) @@ -1997,8 +1997,8 @@ getindex(A::SparseMatrixCSC, I::Tuple{Integer,Integer}) = getindex(A, I[1], I[2] function getindex(A::SparseMatrixCSC{T}, i0::Integer, i1::Integer) where T if !(1 <= i0 <= size(A, 1) && 1 <= i1 <= size(A, 2)); throw(BoundsError()); end - r1 = Int(getcolptr(A)[i1]) - r2 = Int(getcolptr(A)[i1+1]-1) + r1 = Int(colptrs(A)[i1]) + r2 = Int(colptrs(A)[i1+1]-1) (r1 > r2) && return zero(T) r1 = searchsortedfirst(rowvals(A), i0, r1, r2, Forward) ((r1 > r2) || (rowvals(A)[r1] != i0)) ? zero(T) : nonzeros(A)[r1] @@ -2015,7 +2015,7 @@ function getindex_cols(A::SparseMatrixCSC{Tv,Ti}, J::AbstractVector) where {Tv,T (m, n) = size(A) nJ = length(J) - colptrA = getcolptr(A); rowvalA = rowvals(A); nzvalA = nonzeros(A) + colptrA = colptrs(A); rowvalA = rowvals(A); nzvalA = nonzeros(A) colptrS = Vector{Ti}(undef, nJ+1) colptrS[1] = 1 @@ -2058,7 +2058,7 @@ function getindex(A::SparseMatrixCSC{Tv,Ti}, I::AbstractRange, J::AbstractVector nI = length(I) nI == 0 || (minimum(I) >= 1 && maximum(I) <= m) || throw(BoundsError()) nJ = length(J) - colptrA = getcolptr(A); rowvalA = rowvals(A); nzvalA = nonzeros(A) + colptrA = colptrs(A); rowvalA = rowvals(A); nzvalA = nonzeros(A) colptrS = Vector{Ti}(undef, nJ+1) colptrS[1] = 1 nnzS = 0 @@ -2120,7 +2120,7 @@ function getindex_I_sorted_bsearch_A(A::SparseMatrixCSC{Tv,Ti}, I::AbstractVecto nI = length(I) nJ = length(J) - colptrA = getcolptr(A); rowvalA = rowvals(A); nzvalA = nonzeros(A) + colptrA = colptrs(A); rowvalA = rowvals(A); nzvalA = nonzeros(A) colptrS = Vector{Ti}(undef, nJ+1) colptrS[1] = 1 @@ -2180,7 +2180,7 @@ function getindex_I_sorted_linear(A::SparseMatrixCSC{Tv,Ti}, I::AbstractVector, nI = length(I) nJ = length(J) - colptrA = getcolptr(A); rowvalA = rowvals(A); nzvalA = nonzeros(A) + colptrA = colptrs(A); rowvalA = rowvals(A); nzvalA = nonzeros(A) colptrS = Vector{Ti}(undef, nJ+1) colptrS[1] = 1 cacheI = zeros(Int, size(A, 1)) @@ -2240,7 +2240,7 @@ function getindex_I_sorted_bsearch_I(A::SparseMatrixCSC{Tv,Ti}, I::AbstractVecto nI = length(I) nJ = length(J) - colptrA = getcolptr(A); rowvalA = rowvals(A); nzvalA = nonzeros(A) + colptrA = colptrs(A); rowvalA = rowvals(A); nzvalA = nonzeros(A) colptrS = Vector{Ti}(undef, nJ+1) colptrS[1] = 1 @@ -2307,7 +2307,7 @@ end function permute_rows!(S::SparseMatrixCSC{Tv,Ti}, pI::Vector{Int}) where {Tv,Ti} (m, n) = size(S) - colptrS = getcolptr(S); rowvalS = rowvals(S); nzvalS = nonzeros(S) + colptrS = colptrs(S); rowvalS = rowvals(S); nzvalS = nonzeros(S) # preallocate temporary sort space nr = min(nnz(S), m) @@ -2388,7 +2388,7 @@ function getindex(A::SparseMatrixCSC{Tv,Ti}, I::AbstractArray) where {Tv,Ti} require_one_based_indexing(A, I) szA = size(A) nA = szA[1]*szA[2] - colptrA = getcolptr(A) + colptrA = colptrs(A) rowvalA = rowvals(A) nzvalA = nonzeros(A) @@ -2450,8 +2450,8 @@ function _setindex_scalar!(A::SparseMatrixCSC{Tv,Ti}, _v, _i::Integer, _j::Integ if !((1 <= i <= size(A, 1)) & (1 <= j <= size(A, 2))) throw(BoundsError(A, (i,j))) end - coljfirstk = Int(getcolptr(A)[j]) - coljlastk = Int(getcolptr(A)[j+1] - 1) + coljfirstk = Int(colptrs(A)[j]) + coljlastk = Int(colptrs(A)[j+1] - 1) searchk = searchsortedfirst(rowvals(A), i, coljfirstk, coljlastk, Base.Order.Forward) if searchk <= coljlastk && rowvals(A)[searchk] == i # Column j contains entry A[i,j]. Update and return @@ -2461,7 +2461,7 @@ function _setindex_scalar!(A::SparseMatrixCSC{Tv,Ti}, _v, _i::Integer, _j::Integ # Column j does not contain entry A[i,j]. If v is nonzero, insert entry A[i,j] = v # and return. If to the contrary v is zero, then simply return. if !iszero(v) - nz = getcolptr(A)[size(A, 2)+1] + nz = colptrs(A)[size(A, 2)+1] # throw exception before state is partially modified !isbitstype(Ti) || nz < typemax(Ti) || throw(ArgumentError("nnz(A) going to exceed typemax(Ti) = $(typemax(Ti))")) @@ -2470,7 +2470,7 @@ function _setindex_scalar!(A::SparseMatrixCSC{Tv,Ti}, _v, _i::Integer, _j::Integ _insert!(rowvals(A), searchk, i, nz) _insert!(nonzeros(A), searchk, v, nz) @simd for m in (j + 1):(size(A, 2) + 1) - @inbounds getcolptr(A)[m] += Ti(1) + @inbounds colptrs(A)[m] += Ti(1) end end return A @@ -2512,8 +2512,8 @@ function _spsetz_setindex!(A::SparseMatrixCSC, require_one_based_indexing(A, I, J) lengthI = length(I) for j in J - coljAfirstk = getcolptr(A)[j] - coljAlastk = getcolptr(A)[j+1] - 1 + coljAfirstk = colptrs(A)[j] + coljAlastk = colptrs(A)[j+1] - 1 coljAfirstk > coljAlastk && continue kA = coljAfirstk kI = 1 @@ -2560,7 +2560,7 @@ function _spsetnz_setindex!(A::SparseMatrixCSC{Tv}, x::Tv, @inbounds for col in 1:n rrange = nzrange(A, col) if nadd > 0 - getcolptr(A)[col] = getcolptr(A)[col] + nadd + colptrs(A)[col] = colptrs(A)[col] + nadd end if col in J @@ -2644,7 +2644,7 @@ function _spsetnz_setindex!(A::SparseMatrixCSC{Tv}, x::Tv, end if nadd > 0 - getcolptr(A)[n+1] = rowidx + colptrs(A)[n+1] = rowidx deleteat!(rowvalA, rowidx:nnzA) deleteat!(nzvalA, rowidx:nnzA) end @@ -2693,12 +2693,12 @@ function setindex!(A::SparseMatrixCSC{Tv,Ti}, V::AbstractVecOrMat, Ix::Union{Int nI = length(I) nJ = length(J) - colptrA = getcolptr(A); rowvalA = rowvals(A); nzvalA = nonzeros(A) - colptrB = getcolptr(B); rowvalB = rowvals(B); nzvalB = nonzeros(B) + colptrA = colptrs(A); rowvalA = rowvals(A); nzvalA = nonzeros(A) + colptrB = colptrs(B); rowvalB = rowvals(B); nzvalB = nonzeros(B) nnzS = nnz(A) + nnz(B) - colptrS = copy(getcolptr(A)) + colptrS = copy(colptrs(A)) rowvalS = copy(rowvals(A)) nzvalS = copy(nonzeros(A)) @@ -2798,7 +2798,7 @@ function setindex!(A::SparseMatrixCSC, x::AbstractArray, I::AbstractMatrix{Bool} n = sum(I) (n == 0) && (return A) - colptrA = getcolptr(A); rowvalA = rowvals(A); nzvalA = nonzeros(A) + colptrA = colptrs(A); rowvalA = rowvals(A); nzvalA = nonzeros(A) colptrB = colptrA; rowvalB = rowvalA; nzvalB = nzvalA nadd = 0 bidx = xidx = 1 @@ -2900,7 +2900,7 @@ function setindex!(A::SparseMatrixCSC, x::AbstractArray, Ix::AbstractVector{<:In n = length(I) (n == 0) && (return A) - colptrA = getcolptr(A); rowvalA = rowvals(A); nzvalA = nonzeros(A); szA = size(A) + colptrA = colptrs(A); rowvalA = rowvals(A); nzvalA = nonzeros(A); szA = size(A) colptrB = colptrA; rowvalB = rowvalA; nzvalB = nzvalA nadd = 0 bidx = aidx = 1 @@ -3025,15 +3025,15 @@ function dropstored!(A::SparseMatrixCSC, i::Integer, j::Integer) if !((1 <= i <= size(A, 1)) & (1 <= j <= size(A, 2))) throw(BoundsError(A, (i,j))) end - coljfirstk = Int(getcolptr(A)[j]) - coljlastk = Int(getcolptr(A)[j+1] - 1) + coljfirstk = Int(colptrs(A)[j]) + coljlastk = Int(colptrs(A)[j+1] - 1) searchk = searchsortedfirst(rowvals(A), i, coljfirstk, coljlastk, Base.Order.Forward) if searchk <= coljlastk && rowvals(A)[searchk] == i # Entry A[i,j] is stored. Drop and return. deleteat!(rowvals(A), searchk) deleteat!(nonzeros(A), searchk) @simd for m in (j+1):(size(A, 2) + 1) - @inbounds getcolptr(A)[m] -= 1 + @inbounds colptrs(A)[m] -= 1 end end return A @@ -3088,7 +3088,7 @@ function dropstored!(A::SparseMatrixCSC, @inbounds for col in 1:n rrange = nzrange(A, col) if ndel > 0 - getcolptr(A)[col] = getcolptr(A)[col] - ndel + colptrs(A)[col] = colptrs(A)[col] - ndel end if isempty(rrange) || !(col in J) @@ -3118,7 +3118,7 @@ function dropstored!(A::SparseMatrixCSC, end if ndel > 0 - getcolptr(A)[n+1] = rowidx + colptrs(A)[n+1] = rowidx deleteat!(rowvalA, rowidx:nnzA) deleteat!(nzvalA, rowidx:nnzA) end @@ -3163,7 +3163,7 @@ function vcat(X::SparseMatrixCSC...) mX_sofar = 0 ptr_res = colptr[c] for i = 1 : num - colptrXi = getcolptr(X[i]) + colptrXi = colptrs(X[i]) col_length = (colptrXi[c + 1] - 1) - colptrXi[c] ptr_Xi = colptrXi[c] @@ -3180,7 +3180,7 @@ end @inline function stuffcol!(Xi::SparseMatrixCSC, colptr, rowval, nzval, ptr_res, ptr_Xi, col_length, mX_sofar) - colptrXi = getcolptr(Xi) + colptrXi = colptrs(Xi) rowvalXi = rowvals(Xi) nzvalXi = nonzeros(Xi) @@ -3214,7 +3214,7 @@ function hcat(X::SparseMatrixCSC...) nX_sofar = 0 @inbounds for i = 1 : num XI = X[i] - colptr[(1 : nX[i] + 1) .+ nX_sofar] = getcolptr(XI) .+ nnz_sofar + colptr[(1 : nX[i] + 1) .+ nX_sofar] = colptrs(XI) .+ nnz_sofar if nnzX[i] == length(rowvals(XI)) rowval[(1 : nnzX[i]) .+ nnz_sofar] = rowvals(XI) nzval[(1 : nnzX[i]) .+ nnz_sofar] = nonzeros(XI) @@ -3265,7 +3265,7 @@ function blockdiag(X::SparseMatrixCSC...) nX_sofar = 0 mX_sofar = 0 for i = 1 : num - colptr[(1 : nX[i] + 1) .+ nX_sofar] = getcolptr(X[i]) .+ nnz_sofar + colptr[(1 : nX[i] + 1) .+ nX_sofar] = colptrs(X[i]) .+ nnz_sofar rowval[(1 : nnzX[i]) .+ nnz_sofar] = rowvals(X[i]) .+ mX_sofar nzval[(1 : nnzX[i]) .+ nnz_sofar] = nonzeros(X[i]) nnz_sofar += nnzX[i] @@ -3286,10 +3286,10 @@ function is_hermsym(A::SparseMatrixCSC, check::Function) m, n = size(A) if m != n; return false; end - colptr = getcolptr(A) + colptr = colptrs(A) rowval = rowvals(A) nzval = nonzeros(A) - tracker = copy(getcolptr(A)) + tracker = copy(colptrs(A)) for col = 1:size(A, 2) # `tracker` is updated such that, for symmetric matrices, # the loop below starts from an element at or below the @@ -3359,7 +3359,7 @@ end function istriu(A::SparseMatrixCSC) m, n = size(A) - colptr = getcolptr(A) + colptr = colptrs(A) rowval = rowvals(A) nzval = nonzeros(A) @@ -3379,7 +3379,7 @@ end function istril(A::SparseMatrixCSC) m, n = size(A) - colptr = getcolptr(A) + colptr = colptrs(A) rowval = rowvals(A) nzval = nonzeros(A) @@ -3482,8 +3482,8 @@ function diag(A::SparseMatrixCSC{Tv,Ti}, d::Integer=0) where {Tv,Ti} val = Vector{Tv}() for i in 1:l r += 1; c += 1 - r1 = Int(getcolptr(A)[c]) - r2 = Int(getcolptr(A)[c+1]-1) + r1 = Int(colptrs(A)[c]) + r2 = Int(colptrs(A)[c+1]-1) r1 > r2 && continue r1 = searchsortedfirst(rowvals(A), r, r1, r2, Forward) ((r1 > r2) || (rowvals(A)[r1] != r)) && continue @@ -3516,7 +3516,7 @@ function sortSparseMatrixCSC!(A::SparseMatrixCSC{Tv,Ti}; sortindices::Symbol = : end m, n = size(A) - colptr = getcolptr(A); rowval = rowvals(A); nzval = nonzeros(A) + colptr = colptrs(A); rowval = rowvals(A); nzval = nonzeros(A) index = zeros(Ti, m) row = zeros(Ti, m) @@ -3621,19 +3621,19 @@ function circshift!(O::SparseMatrixCSC, X::SparseMatrixCSC, (r,c)::Base.DimsInte copy!(O, X) else ##### readjust output - resize!(getcolptr(O), size(X, 2) + 1) + resize!(colptrs(O), size(X, 2) + 1) resize!(rowvals(O), nnz) resize!(nonzeros(O), nnz) - getcolptr(O)[size(X, 2) + 1] = nnz + 1 + colptrs(O)[size(X, 2) + 1] = nnz + 1 # exchange left and right blocks - nleft = getcolptr(X)[size(X, 2) - c + 1] - 1 + nleft = colptrs(X)[size(X, 2) - c + 1] - 1 nright = nnz - nleft @inbounds for i=c+1:size(X, 2) - getcolptr(O)[i] = getcolptr(X)[i-c] + nright + colptrs(O)[i] = colptrs(X)[i-c] + nright end @inbounds for i=1:c - getcolptr(O)[i] = getcolptr(X)[size(X, 2) - c + i] - nleft + colptrs(O)[i] = colptrs(X)[size(X, 2) - c + i] - nleft end # rotate rowval and nzval by the right number of elements circshift!(rowvals(O), rowvals(X), (nright,)) @@ -3643,7 +3643,7 @@ function circshift!(O::SparseMatrixCSC, X::SparseMatrixCSC, (r,c)::Base.DimsInte r = mod(r, size(X, 1)) iszero(r) && return O @inbounds for i=1:size(O, 2) - subvector_shifter!(rowvals(O), nonzeros(O), getcolptr(O)[i], getcolptr(O)[i+1]-1, size(O, 1), r) + subvector_shifter!(rowvals(O), nonzeros(O), colptrs(O)[i], colptrs(O)[i+1]-1, size(O, 1), r) end return O end diff --git a/stdlib/SparseArrays/src/sparsevector.jl b/stdlib/SparseArrays/src/sparsevector.jl index 10f14ed338545..d22709fff400c 100644 --- a/stdlib/SparseArrays/src/sparsevector.jl +++ b/stdlib/SparseArrays/src/sparsevector.jl @@ -476,10 +476,10 @@ function copyto!(A::SparseVector, B::SparseMatrixCSC) ptr = 1 @assert length(nonzeroinds(A)) >= length(rowvals(B)) - maximum(getcolptr(B))-1 <= length(rowvals(B)) || throw(BoundsError()) - @inbounds for col=1:length(getcolptr(B))-1 + maximum(colptrs(B))-1 <= length(rowvals(B)) || throw(BoundsError()) + @inbounds for col=1:length(colptrs(B))-1 offsetA = (col - 1) * size(B, 1) - while ptr <= getcolptr(B)[col+1]-1 + while ptr <= colptrs(B)[col+1]-1 nonzeroinds(A)[ptr] = rowvals(B)[ptr] + offsetA ptr += 1 end @@ -524,16 +524,16 @@ sprandn(r::AbstractRNG, ::Type{T}, n::Integer, p::AbstractFloat) where T = spran # Column slices function getindex(x::SparseMatrixCSC, ::Colon, j::Integer) checkbounds(x, :, j) - r1 = convert(Int, getcolptr(x)[j]) - r2 = convert(Int, getcolptr(x)[j+1]) - 1 + r1 = convert(Int, colptrs(x)[j]) + r2 = convert(Int, colptrs(x)[j+1]) - 1 SparseVector(size(x, 1), rowvals(x)[r1:r2], nonzeros(x)[r1:r2]) end function getindex(x::SparseMatrixCSC, I::AbstractUnitRange, j::Integer) checkbounds(x, I, j) # Get the selected column - c1 = convert(Int, getcolptr(x)[j]) - c2 = convert(Int, getcolptr(x)[j+1]) - 1 + c1 = convert(Int, colptrs(x)[j]) + c2 = convert(Int, colptrs(x)[j+1]) - 1 # Restrict to the selected rows r1 = searchsortedfirst(rowvals(x), first(I), c1, c2, Forward) r2 = searchsortedlast(rowvals(x), last(I), c1, c2, Forward) @@ -552,7 +552,7 @@ function Base.getindex(A::SparseMatrixCSC{Tv,Ti}, i::Integer, J::AbstractVector) require_one_based_indexing(A, J) checkbounds(A, i, J) nJ = length(J) - colptrA = getcolptr(A); rowvalA = rowvals(A); nzvalA = nonzeros(A) + colptrA = colptrs(A); rowvalA = rowvals(A); nzvalA = nonzeros(A) nzinds = Vector{Ti}() nzvals = Vector{Tv}() @@ -588,7 +588,7 @@ function _logical_index(A::SparseMatrixCSC{Tv}, I::AbstractArray{Bool}) where Tv n = sum(I) nnzB = min(n, nnz(A)) - colptrA = getcolptr(A); rowvalA = rowvals(A); nzvalA = nonzeros(A) + colptrA = colptrs(A); rowvalA = rowvals(A); nzvalA = nonzeros(A) rowvalB = Vector{Int}(undef, nnzB) nzvalB = Vector{Tv}(undef, nnzB) c = 1 @@ -629,7 +629,7 @@ function getindex(A::SparseMatrixCSC{Tv}, I::AbstractUnitRange) where Tv checkbounds(A, I) szA = size(A) nA = szA[1]*szA[2] - colptrA = getcolptr(A) + colptrA = colptrs(A) rowvalA = rowvals(A) nzvalA = nonzeros(A) @@ -665,7 +665,7 @@ function getindex(A::SparseMatrixCSC{Tv,Ti}, I::AbstractVector) where {Tv,Ti} require_one_based_indexing(A, I) szA = size(A) nA = szA[1]*szA[2] - colptrA = getcolptr(A) + colptrA = colptrs(A) rowvalA = rowvals(A) nzvalA = nonzeros(A) @@ -1654,7 +1654,7 @@ function mul!(y::AbstractVector, A::SparseMatrixCSC, x::AbstractSparseVector, α xnzind = nonzeroinds(x) xnzval = nonzeros(x) - Acolptr = getcolptr(A) + Acolptr = colptrs(A) Arowval = rowvals(A) Anzval = nonzeros(A) @@ -1699,7 +1699,7 @@ function _At_or_Ac_mul_B!(tfun::Function, xnzind = nonzeroinds(x) xnzval = nonzeros(x) - Acolptr = getcolptr(A) + Acolptr = colptrs(A) Arowval = rowvals(A) Anzval = nonzeros(A) mx = length(xnzind) @@ -1738,7 +1738,7 @@ function _At_or_Ac_mul_B(tfun::Function, A::SparseMatrixCSC{TvA,TiA}, x::Abstrac xnzind = nonzeroinds(x) xnzval = nonzeros(x) - Acolptr = getcolptr(A) + Acolptr = colptrs(A) Arowval = rowvals(A) Anzval = nonzeros(A) mx = length(xnzind) @@ -2009,10 +2009,10 @@ end function _fillnonzero!(arr::SparseMatrixCSC{Tv, Ti}, val) where {Tv,Ti} m, n = size(arr) - resize!(getcolptr(arr), n+1) + resize!(colptrs(arr), n+1) resize!(rowvals(arr), m*n) resize!(nonzeros(arr), m*n) - copyto!(getcolptr(arr), 1:m:n*m+1) + copyto!(colptrs(arr), 1:m:n*m+1) fill!(nonzeros(arr), val) index = 1 @inbounds for _ in 1:n diff --git a/stdlib/SparseArrays/test/sparse.jl b/stdlib/SparseArrays/test/sparse.jl index 97acfd7b6ccfa..edf0b2017225e 100644 --- a/stdlib/SparseArrays/test/sparse.jl +++ b/stdlib/SparseArrays/test/sparse.jl @@ -4,7 +4,7 @@ module SparseTests using Test using SparseArrays -using SparseArrays: getcolptr, nonzeroinds +using SparseArrays: colptrs, nonzeroinds using LinearAlgebra using Base.Printf: @printf using Random @@ -495,7 +495,7 @@ end @test A == B @test pointer(nonzeros(A)) != pointer(nonzeros(B)) @test pointer(rowvals(A)) != pointer(rowvals(B)) - @test pointer(getcolptr(A)) != pointer(getcolptr(B)) + @test pointer(colptrs(A)) != pointer(colptrs(B)) # Test size(A) != size(B), but length(A) == length(B) B = sprand(25, 1, 0.2) copyto!(A, B) @@ -566,7 +566,7 @@ end @test_throws ArgumentError permute!(X, A, p, q, (D = copy(C); resize!(nonzeros(D), nnz(A) - 1); D)) end @testset "common error checking of permute[!] methods / source-workcolptr compat" begin - @test_throws DimensionMismatch permute!(A, p, q, C, Vector{eltype(rowvals(A))}(undef, length(getcolptr(A)) - 1)) + @test_throws DimensionMismatch permute!(A, p, q, C, Vector{eltype(rowvals(A))}(undef, length(colptrs(A)) - 1)) end @testset "common error checking of permute[!] methods / permutation validity" begin @test_throws ArgumentError permute!(A, (r = copy(p); r[2] = r[1]; r), q) @@ -596,7 +596,7 @@ end @test permute!(similar(A), A, p, q, similar(At)) == fullPAQ @test permute!(copy(A), p, q) == fullPAQ @test permute!(copy(A), p, q, similar(At)) == fullPAQ - @test permute!(copy(A), p, q, similar(At), similar(getcolptr(A))) == fullPAQ + @test permute!(copy(A), p, q, similar(At), similar(colptrs(A))) == fullPAQ end end end @@ -1556,7 +1556,7 @@ end local A = guardseed(1234321) do triu(sprand(10, 10, 0.2)) end - @test getcolptr(SparseArrays.droptol!(A, 0.01)) == [1, 2, 2, 3, 4, 5, 5, 6, 8, 10, 13] + @test colptrs(SparseArrays.droptol!(A, 0.01)) == [1, 2, 2, 3, 4, 5, 5, 6, 8, 10, 13] @test isequal(SparseArrays.droptol!(sparse([1], [1], [1]), 1), SparseMatrixCSC(1, 1, Int[1, 1], Int[], Int[])) end @@ -1597,7 +1597,7 @@ end # original lone dropzeros test local A = sparse([1 2 3; 4 5 6; 7 8 9]) nonzeros(A)[2] = nonzeros(A)[6] = nonzeros(A)[7] = 0 - @test getcolptr(dropzeros!(A)) == [1, 3, 5, 7] + @test colptrs(dropzeros!(A)) == [1, 3, 5, 7] # test for issue #5169, modified for new behavior following #15242/#14798 @test nnz(sparse([1, 1], [1, 2], [0.0, -0.0])) == 2 @test nnz(dropzeros!(sparse([1, 1], [1, 2], [0.0, -0.0]))) == 0 @@ -1661,9 +1661,9 @@ end @testset "expandptr" begin local A = sparse(1.0I, 5, 5) - @test SparseArrays.expandptr(getcolptr(A)) == 1:5 + @test SparseArrays.expandptr(colptrs(A)) == 1:5 A[1,2] = 1 - @test SparseArrays.expandptr(getcolptr(A)) == [1; 2; 2; 3; 4; 5] + @test SparseArrays.expandptr(colptrs(A)) == [1; 2; 2; 3; 4; 5] @test_throws ArgumentError SparseArrays.expandptr([2; 3]) end @@ -2105,15 +2105,15 @@ end x = sparse(rand(3,3)) SparseArrays.dropstored!(x, 1, 1) @test x[1, 1] == 0.0 - @test getcolptr(x) == [1, 3, 6, 9] + @test colptrs(x) == [1, 3, 6, 9] SparseArrays.dropstored!(x, 2, 1) - @test getcolptr(x) == [1, 2, 5, 8] + @test colptrs(x) == [1, 2, 5, 8] @test x[2, 1] == 0.0 SparseArrays.dropstored!(x, 2, 2) - @test getcolptr(x) == [1, 2, 4, 7] + @test colptrs(x) == [1, 2, 4, 7] @test x[2, 2] == 0.0 SparseArrays.dropstored!(x, 2, 3) - @test getcolptr(x) == [1, 2, 4, 6] + @test colptrs(x) == [1, 2, 4, 6] @test x[2, 3] == 0.0 end @@ -2233,53 +2233,53 @@ end simA = similar(A) @test typeof(simA) == typeof(A) @test size(simA) == size(A) - @test getcolptr(simA) == getcolptr(A) + @test colptrs(simA) == colptrs(A) @test rowvals(simA) == rowvals(A) @test length(nonzeros(simA)) == length(nonzeros(A)) # test similar with entry type specification (preserves stored-entry structure) simA = similar(A, Float32) - @test typeof(simA) == SparseMatrixCSC{Float32,eltype(getcolptr(A))} + @test typeof(simA) == SparseMatrixCSC{Float32,eltype(colptrs(A))} @test size(simA) == size(A) - @test getcolptr(simA) == getcolptr(A) + @test colptrs(simA) == colptrs(A) @test rowvals(simA) == rowvals(A) @test length(nonzeros(simA)) == length(nonzeros(A)) # test similar with entry and index type specification (preserves stored-entry structure) simA = similar(A, Float32, Int8) @test typeof(simA) == SparseMatrixCSC{Float32,Int8} @test size(simA) == size(A) - @test getcolptr(simA) == getcolptr(A) + @test colptrs(simA) == colptrs(A) @test rowvals(simA) == rowvals(A) @test length(nonzeros(simA)) == length(nonzeros(A)) # test similar with Dims{2} specification (preserves storage space only, not stored-entry structure) simA = similar(A, (6,6)) @test typeof(simA) == typeof(A) @test size(simA) == (6,6) - @test getcolptr(simA) == fill(1, 6+1) + @test colptrs(simA) == fill(1, 6+1) @test length(rowvals(simA)) == length(rowvals(A)) @test length(nonzeros(simA)) == length(nonzeros(A)) # test similar with entry type and Dims{2} specification (preserves storage space only) simA = similar(A, Float32, (6,6)) - @test typeof(simA) == SparseMatrixCSC{Float32,eltype(getcolptr(A))} + @test typeof(simA) == SparseMatrixCSC{Float32,eltype(colptrs(A))} @test size(simA) == (6,6) - @test getcolptr(simA) == fill(1, 6+1) + @test colptrs(simA) == fill(1, 6+1) @test length(rowvals(simA)) == length(rowvals(A)) @test length(nonzeros(simA)) == length(nonzeros(A)) # test similar with entry type, index type, and Dims{2} specification (preserves storage space only) simA = similar(A, Float32, Int8, (6,6)) @test typeof(simA) == SparseMatrixCSC{Float32, Int8} @test size(simA) == (6,6) - @test getcolptr(simA) == fill(1, 6+1) + @test colptrs(simA) == fill(1, 6+1) @test length(rowvals(simA)) == length(rowvals(A)) @test length(nonzeros(simA)) == length(nonzeros(A)) # test similar with Dims{1} specification (preserves nothing) simA = similar(A, (6,)) - @test typeof(simA) == SparseVector{eltype(nonzeros(A)),eltype(getcolptr(A))} + @test typeof(simA) == SparseVector{eltype(nonzeros(A)),eltype(colptrs(A))} @test size(simA) == (6,) @test length(nonzeroinds(simA)) == 0 @test length(nonzeros(simA)) == 0 # test similar with entry type and Dims{1} specification (preserves nothing) simA = similar(A, Float32, (6,)) - @test typeof(simA) == SparseVector{Float32,eltype(getcolptr(A))} + @test typeof(simA) == SparseVector{Float32,eltype(colptrs(A))} @test size(simA) == (6,) @test length(nonzeroinds(simA)) == 0 @test length(nonzeros(simA)) == 0 diff --git a/stdlib/SparseArrays/test/sparsevector.jl b/stdlib/SparseArrays/test/sparsevector.jl index 0437e3304293a..6528ee15b5b4e 100644 --- a/stdlib/SparseArrays/test/sparsevector.jl +++ b/stdlib/SparseArrays/test/sparsevector.jl @@ -4,7 +4,7 @@ module SparseVectorTests using Test using SparseArrays -using SparseArrays: nonzeroinds, getcolptr +using SparseArrays: nonzeroinds, colptrs using LinearAlgebra using Random include("forbidproperties.jl") @@ -1008,8 +1008,8 @@ end sprmat = sprand(m, m, 0.2) sparsefloatmat = I + sprmat/(2m) - sparsecomplexmat = I + SparseMatrixCSC(m, m, getcolptr(sprmat), rowvals(sprmat), complex.(nonzeros(sprmat), nonzeros(sprmat))/(4m)) - sparseintmat = 10m*I + SparseMatrixCSC(m, m, getcolptr(sprmat), rowvals(sprmat), round.(Int, nonzeros(sprmat)*10)) + sparsecomplexmat = I + SparseMatrixCSC(m, m, colptrs(sprmat), rowvals(sprmat), complex.(nonzeros(sprmat), nonzeros(sprmat))/(4m)) + sparseintmat = 10m*I + SparseMatrixCSC(m, m, colptrs(sprmat), rowvals(sprmat), round.(Int, nonzeros(sprmat)*10)) denseintmat = I*10m + rand(1:m, m, m) densefloatmat = I + randn(m, m)/(2m) @@ -1302,21 +1302,21 @@ end simA = similar(A, (6,6)) @test typeof(simA) == SparseMatrixCSC{eltype(nonzeros(A)),eltype(nonzeroinds(A))} @test size(simA) == (6,6) - @test getcolptr(simA) == fill(1, 6+1) + @test colptrs(simA) == fill(1, 6+1) @test length(rowvals(simA)) == length(nonzeroinds(A)) @test length(nonzeros(simA)) == length(nonzeros(A)) # test similar with entry type and Dims{2} specification (preserves storage space only) simA = similar(A, Float32, (6,6)) @test typeof(simA) == SparseMatrixCSC{Float32,eltype(nonzeroinds(A))} @test size(simA) == (6,6) - @test getcolptr(simA) == fill(1, 6+1) + @test colptrs(simA) == fill(1, 6+1) @test length(rowvals(simA)) == length(nonzeroinds(A)) @test length(nonzeros(simA)) == length(nonzeros(A)) # test similar with entry type, index type, and Dims{2} specification (preserves storage space only) simA = similar(A, Float32, Int8, (6,6)) @test typeof(simA) == SparseMatrixCSC{Float32, Int8} @test size(simA) == (6,6) - @test getcolptr(simA) == fill(1, 6+1) + @test colptrs(simA) == fill(1, 6+1) @test length(rowvals(simA)) == length(nonzeroinds(A)) @test length(nonzeros(simA)) == length(nonzeros(A)) end diff --git a/stdlib/Statistics/src/Statistics.jl b/stdlib/Statistics/src/Statistics.jl index 3281376e31d2d..2d8874e1156d3 100644 --- a/stdlib/Statistics/src/Statistics.jl +++ b/stdlib/Statistics/src/Statistics.jl @@ -8,7 +8,7 @@ Standard library module for basic statistics functionality. module Statistics using LinearAlgebra, SparseArrays -using SparseArrays: getcolptr +using SparseArrays: colptrs using Base: has_offset_axes, require_one_based_indexing @@ -1004,7 +1004,7 @@ function centralize_sumabs2!(R::AbstractArray{S}, A::SparseMatrixCSC{Tv,Ti}, mea isempty(R) || fill!(R, zero(S)) isempty(A) && return R - colptr = getcolptr(A) + colptr = colptrs(A) rowval = rowvals(A) nzval = nonzeros(A) m = size(A, 1) diff --git a/stdlib/SuiteSparse/src/cholmod.jl b/stdlib/SuiteSparse/src/cholmod.jl index 20c24e7c7e2d1..19f3fc45ed90e 100644 --- a/stdlib/SuiteSparse/src/cholmod.jl +++ b/stdlib/SuiteSparse/src/cholmod.jl @@ -20,7 +20,7 @@ import LinearAlgebra: (\), issuccess, issymmetric, ldlt, ldlt!, logdet using SparseArrays -using SparseArrays: getcolptr +using SparseArrays: colptrs import Libdl export @@ -864,8 +864,8 @@ end function Sparse{Tv}(A::SparseMatrixCSC, stype::Integer) where Tv<:VTypes ## Check length of input. This should never fail but see #20024 - if length(getcolptr(A)) <= size(A, 2) - throw(ArgumentError("length of colptr must be at least size(A,2) + 1 = $(size(A, 2) + 1) but was $(length(getcolptr(A)))")) + if length(colptrs(A)) <= size(A, 2) + throw(ArgumentError("length of colptr must be at least size(A,2) + 1 = $(size(A, 2) + 1) but was $(length(colptrs(A)))")) end if nnz(A) > length(rowvals(A)) throw(ArgumentError("length of rowval is $(length(rowvals(A))) but value of colptr requires length to be at least $(nnz(A))")) @@ -877,7 +877,7 @@ function Sparse{Tv}(A::SparseMatrixCSC, stype::Integer) where Tv<:VTypes o = allocate_sparse(size(A, 1), size(A, 2), nnz(A), true, true, stype, Tv) s = unsafe_load(pointer(o)) for i = 1:(size(A, 2) + 1) - unsafe_store!(s.p, getcolptr(A)[i] - 1, i) + unsafe_store!(s.p, colptrs(A)[i] - 1, i) end for i = 1:nnz(A) unsafe_store!(s.i, rowvals(A)[i] - 1, i) @@ -887,7 +887,7 @@ function Sparse{Tv}(A::SparseMatrixCSC, stype::Integer) where Tv<:VTypes # BLAS/LAPACK these are not ignored by CHOLMOD. If even tiny imaginary parts are # present CHOLMOD will fail with a non-positive definite/zero pivot error. for j = 1:size(A, 2) - for ip = getcolptr(A)[j]:getcolptr(A)[j + 1] - 1 + for ip = colptrs(A)[j]:colptrs(A)[j + 1] - 1 v = nonzeros(A)[ip] unsafe_store!(s.x, rowvals(A)[ip] == j ? Complex(real(v)) : v, ip) end @@ -1196,7 +1196,7 @@ function getLd!(S::SparseMatrixCSC) fill!(d, 0) col = 1 for k = 1:nnz(S) - while k >= getcolptr(S)[col+1] + while k >= colptrs(S)[col+1] col += 1 end if rowvals(S)[k] == col diff --git a/stdlib/SuiteSparse/src/spqr.jl b/stdlib/SuiteSparse/src/spqr.jl index 88a4522520fd8..1089ca4f1d7e0 100644 --- a/stdlib/SuiteSparse/src/spqr.jl +++ b/stdlib/SuiteSparse/src/spqr.jl @@ -24,7 +24,7 @@ const ORDERING_BESTAMD = Int32(9) # try COLAMD and AMD; pick best# # the best of AMD and METIS. METIS is not tried if it isn't installed. using SparseArrays -using SparseArrays: getcolptr +using SparseArrays: colptrs using ..SuiteSparse.CHOLMOD using ..SuiteSparse.CHOLMOD: change_stype!, free! @@ -160,7 +160,7 @@ function LinearAlgebra.qr(A::SparseMatrixCSC{Tv}; tol = _default_tol(A)) where { vec(Array(CHOLMOD.Dense(HTau[]))), SparseMatrixCSC(min(size(A)...), size(R_, 2), - getcolptr(R_), + colptrs(R_), rowvals(R_), nonzeros(R_)), p, hpinv) diff --git a/stdlib/SuiteSparse/src/umfpack.jl b/stdlib/SuiteSparse/src/umfpack.jl index 155cbe2ab53ef..b75b6607056d8 100644 --- a/stdlib/SuiteSparse/src/umfpack.jl +++ b/stdlib/SuiteSparse/src/umfpack.jl @@ -9,7 +9,7 @@ using LinearAlgebra import LinearAlgebra: Factorization, det, lu, ldiv! using SparseArrays -using SparseArrays: getcolptr +using SparseArrays: colptrs import SparseArrays: nnz import Serialization: AbstractSerializer, deserialize @@ -152,9 +152,9 @@ The relation between `F` and `A` is `SparseMatrixCSC{Float64}` or `SparseMatrixCSC{ComplexF64}` as appropriate. """ function lu(S::SparseMatrixCSC{<:UMFVTypes,<:UMFITypes}; check::Bool = true) - zerobased = getcolptr(S)[1] == 0 + zerobased = colptrs(S)[1] == 0 res = UmfpackLU(C_NULL, C_NULL, size(S, 1), size(S, 2), - zerobased ? copy(getcolptr(S)) : decrement(getcolptr(S)), + zerobased ? copy(colptrs(S)) : decrement(colptrs(S)), zerobased ? copy(rowvals(S)) : decrement(rowvals(S)), copy(nonzeros(S)), 0) finalizer(umfpack_free_symbolic, res) diff --git a/stdlib/SuiteSparse/test/cholmod.jl b/stdlib/SuiteSparse/test/cholmod.jl index a19fafd3e9f99..3ad73fc9f8371 100644 --- a/stdlib/SuiteSparse/test/cholmod.jl +++ b/stdlib/SuiteSparse/test/cholmod.jl @@ -7,7 +7,7 @@ using Random using Serialization using LinearAlgebra: issuccess, PosDefException using SparseArrays -using SparseArrays: getcolptr +using SparseArrays: colptrs # CHOLMOD tests Random.seed!(123) @@ -334,7 +334,7 @@ end A1pdSparse = CHOLMOD.Sparse( size(A1pd, 1), size(A1pd, 2), - SuiteSparse.decrement(getcolptr(A1pd)), + SuiteSparse.decrement(colptrs(A1pd)), SuiteSparse.decrement(rowvals(A1pd)), nonzeros(A1pd)) @@ -768,7 +768,7 @@ end @testset "Check inputs to Sparse. Related to #20024" for A_ in ( SparseMatrixCSC(2, 2, [1, 2, 3], CHOLMOD.SuiteSparse_long[1,2], Float64[]), SparseMatrixCSC(2, 2, [1, 2, 3], CHOLMOD.SuiteSparse_long[1,2], Float64[1.0])) - args = (size(A_)..., getcolptr(A_) .- 1, rowvals(A_) .- 1, nonzeros(A_)) + args = (size(A_)..., colptrs(A_) .- 1, rowvals(A_) .- 1, nonzeros(A_)) @test_throws ArgumentError CHOLMOD.Sparse(args...) @test_throws ArgumentError CHOLMOD.Sparse(A_) end