From cf4aac57a888897eae5a4725897b48f2cf8500a6 Mon Sep 17 00:00:00 2001 From: Lilith Hafner Date: Tue, 5 Sep 2023 16:33:04 -0500 Subject: [PATCH] fixups --- src/linalg.jl | 8 ++++---- src/sparsematrix.jl | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/linalg.jl b/src/linalg.jl index cb9093f3..7670ce61 100644 --- a/src/linalg.jl +++ b/src/linalg.jl @@ -664,7 +664,7 @@ function LinearAlgebra.generic_trimatdiv!(C::StridedVecOrMat, uploc, isunitc, tf i2 = ia[j + 1] - one(eltype(ia)) # find diagonal element - ii = searchsortedfirst(view(ja, i1:i2), j) - i1 + 1 + ii = searchsortedfirst(view(ja, i1:i2), j) + i1 - 1 jai = ii > i2 ? zero(eltype(ja)) : ja[ii] cj = C[j,k] @@ -723,7 +723,7 @@ function LinearAlgebra.generic_trimatdiv!(C::StridedVecOrMat, uploc, isunitc, tf i2 = ia[j + 1] - one(eltype(ia)) # find diagonal element - ii = searchsortedlast(view(ja, i1:i2), j) - i1 + 1 + ii = searchsortedlast(view(ja, i1:i2), j) + i1 - 1 jai = ii < i1 ? zero(eltype(ja)) : ja[ii] cj = C[j,k] @@ -801,7 +801,7 @@ function LinearAlgebra.generic_trimatdiv!(C::StridedVecOrMat, uploc, isunitc, :: i2 = ia[j + 1] - one(eltype(ia)) # find diagonal element - ii = searchsortedfirst(view(ja, i1:i2), j) - i1 + 1 + ii = searchsortedfirst(view(ja, i1:i2), j) + i1 - 1 jai = ii > i2 ? zero(eltype(ja)) : ja[ii] cj = C[j,k] @@ -830,7 +830,7 @@ function LinearAlgebra.generic_trimatdiv!(C::StridedVecOrMat, uploc, isunitc, :: i2 = ia[j + 1] - one(eltype(ia)) # find diagonal element - ii = searchsortedlast(view(ja, i1:i2), j) - i1 + 1 + ii = searchsortedlast(view(ja, i1:i2), j) + i1 - 1 jai = ii < i1 ? zero(eltype(ja)) : ja[ii] cj = C[j,k] diff --git a/src/sparsematrix.jl b/src/sparsematrix.jl index c03a5809..e2dfacce 100644 --- a/src/sparsematrix.jl +++ b/src/sparsematrix.jl @@ -1954,7 +1954,7 @@ function _sparse_findprevnz(m::AbstractSparseMatrixCSC, ij::CartesianIndex{2}) iszero(col) && return nothing lo, hi = getcolptr(m)[col], getcolptr(m)[col+1] - n = searchsortedlast(view(rowvals(m), lo:hi-1), row) - lo + 1 + n = searchsortedlast(view(rowvals(m), lo:hi-1), row) + lo - 1 if lo <= n <= hi-1 return CartesianIndex(rowvals(m)[n], col) end @@ -3491,7 +3491,7 @@ function setindex!(A::AbstractSparseMatrixCSC, x::AbstractArray, I::AbstractMatr xidx += 1 if r1 <= r2 - copylen = searchsortedfirst(view(rowvalA, r1:r2), row) - 2r1 + 1 + copylen = searchsortedfirst(view(rowvalA, r1:r2), row) - 1 if (copylen > 0) if (nadd > 0) copyto!(rowvalB, bidx, rowvalA, r1, copylen) @@ -3621,7 +3621,7 @@ function setindex!(A::AbstractSparseMatrixCSC, x::AbstractArray, Ix::AbstractVec end if r1 <= r2 - copylen = searchsortedfirst(view(rowvalA, r1:r2), row) - 2r1 + 1 + copylen = searchsortedfirst(view(rowvalA, r1:r2), row) - 1 if (copylen > 0) if (nadd > 0) copyto!(rowvalB, bidx, rowvalA, r1, copylen) @@ -3705,7 +3705,7 @@ function dropstored!(A::AbstractSparseMatrixCSC, i::Integer, j::Integer) end coljfirstk = Int(getcolptr(A)[j]) coljlastk = Int(getcolptr(A)[j+1] - 1) - searchk = searchsortedfirst(view(rowvals(A), coljfirstk:coljlastk), i) - coljfirstk + 1 + searchk = searchsortedfirst(view(rowvals(A), coljfirstk:coljlastk), i) + coljfirstk - 1 if searchk <= coljlastk && rowvals(A)[searchk] == i # Entry A[i,j] is stored. Drop and return. deleteat!(rowvals(A), searchk) @@ -4222,7 +4222,7 @@ function diag(A::AbstractSparseMatrixCSC{Tv,Ti}, d::Integer=0) where {Tv,Ti} r1 = Int(getcolptr(A)[c]) r2 = Int(getcolptr(A)[c+1]-1) r1 > r2 && continue - r1 += searchsortedfirst(view(rowvals(A), r1:r2), r) + 1 + r1 += searchsortedfirst(view(rowvals(A), r1:r2), r) - 1 ((r1 > r2) || (rowvals(A)[r1] != r)) && continue push!(ind, i) push!(val, nonzeros(A)[r1])