diff --git a/Project.toml b/Project.toml index 71f81c4d..bafb1f9d 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "BandedMatrices" uuid = "aae01518-5342-5314-be14-df237901396f" -version = "0.17.20" +version = "0.17.21" [deps] ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a" diff --git a/src/banded/BandedMatrix.jl b/src/banded/BandedMatrix.jl index 00420983..61f0a8e8 100644 --- a/src/banded/BandedMatrix.jl +++ b/src/banded/BandedMatrix.jl @@ -622,20 +622,7 @@ end @boundscheck checkbounds(A, kr, jr) @boundscheck checkdimensions(kr, jr, V) @boundscheck checkbandmatch(A, V, kr, jr) - - data, u, l = A.data, A.u, A.l - jj = 1 - for j in jr - kk = 1 - for k in kr - if -l ≤ j - k ≤ u - # we index V manually in column-major order - inbands_setindex!(data, u, V[kk, jj], k, j) - kk += 1 - end - end - jj += 1 - end + copyto!(view(A, kr, jr), V) V end diff --git a/test/test_banded.jl b/test/test_banded.jl index c4f29cfb..2d5bd3f7 100644 --- a/test/test_banded.jl +++ b/test/test_banded.jl @@ -469,5 +469,15 @@ Base.similar(::MyMatrix, ::Type{T}, m::Int, n::Int) where T = MyMatrix{T}(undef, A = _BandedMatrix(Fill(1,1,5), Base.Slice(1:4), 1, -1) @test summary(A) == "4×5 BandedMatrix{$Int} with bandwidths (1, -1) with data 1×5 Fill{$Int} with indices 1:4×Base.OneTo(5)" end + + @testset "setindex! with ranges (#348)" begin + n = 10; + X1 = brand(n,n,1,1) + B = BandedMatrix(Zeros(2n,2n), (3,3)) + B[1:2:end,1:2:end] = X1 + A = zeros(2n,2n) + A[1:2:end,1:2:end] = X1 + @test A == B + end end