diff --git a/src/SparseArrays.jl b/src/SparseArrays.jl index 8d463a8c..27e1a601 100644 --- a/src/SparseArrays.jl +++ b/src/SparseArrays.jl @@ -11,6 +11,9 @@ using Base.Sort: Forward using LinearAlgebra using LinearAlgebra: AdjOrTrans, matprod +# Temporary workaround for simplifying SparseArrays.jl upgrade in JuliaLang/julia +# to workaround circshift! bug, see https://github.com/JuliaLang/julia/pull/46759 +const CIRCSHIFT_WRONG_DIRECTION = circshift!([1, 2, 3], 1) != circshift([1, 2, 3], 1) import Base: +, -, *, \, /, &, |, xor, ==, zero diff --git a/src/sparsematrix.jl b/src/sparsematrix.jl index bff7df5a..fe68edd8 100644 --- a/src/sparsematrix.jl +++ b/src/sparsematrix.jl @@ -4203,16 +4203,16 @@ function Base.swaprows!(A::AbstractSparseMatrixCSC, i, j) rows[rr[iidx]] = j jidx == 0 && continue rotate_range = rr[iidx]:jrange[jidx] - circshift!(@view(vals[rotate_range]), -1) - circshift!(@view(rows[rotate_range]), -1) + circshift!(@view(vals[rotate_range]), CIRCSHIFT_WRONG_DIRECTION ? -1 : 1) + circshift!(@view(rows[rotate_range]), CIRCSHIFT_WRONG_DIRECTION ? -1 : 1) else # Same as i, but in the opposite direction @assert has_j rows[jrange[jidx]] = i iidx > length(rr) && continue rotate_range = rr[iidx]:jrange[jidx] - circshift!(@view(vals[rotate_range]), 1) - circshift!(@view(rows[rotate_range]), 1) + circshift!(@view(vals[rotate_range]), CIRCSHIFT_WRONG_DIRECTION ? 1 : -1) + circshift!(@view(rows[rotate_range]), CIRCSHIFT_WRONG_DIRECTION ? 1 : -1) end end return nothing diff --git a/src/sparsevector.jl b/src/sparsevector.jl index 0f8916ea..83435d95 100644 --- a/src/sparsevector.jl +++ b/src/sparsevector.jl @@ -2223,8 +2223,8 @@ function subvector_shifter!(R::AbstractVector, V::AbstractVector, start::Integer end end # ...but rowval should be sorted within columns - circshift!(@view(R[start:fin]), split-start+1) - circshift!(@view(V[start:fin]), split-start+1) + circshift!(@view(R[start:fin]), (CIRCSHIFT_WRONG_DIRECTION ? (+) : (-))(split-start+1)) + circshift!(@view(V[start:fin]), (CIRCSHIFT_WRONG_DIRECTION ? (+) : (-))(split-start+1)) end function circshift!(O::SparseVector, X::SparseVector, (r,)::Base.DimsInteger{1})