Skip to content

Commit 45a5873

Browse files
authored
Fix setindex! with ranges (#138) (#349)
* Fix setindex! with ranges (#138) * Update BandedMatrix.jl
1 parent 7988daf commit 45a5873

File tree

3 files changed

+12
-15
lines changed

3 files changed

+12
-15
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "BandedMatrices"
22
uuid = "aae01518-5342-5314-be14-df237901396f"
3-
version = "0.17.20"
3+
version = "0.17.21"
44

55
[deps]
66
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"

src/banded/BandedMatrix.jl

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -622,20 +622,7 @@ end
622622
@boundscheck checkbounds(A, kr, jr)
623623
@boundscheck checkdimensions(kr, jr, V)
624624
@boundscheck checkbandmatch(A, V, kr, jr)
625-
626-
data, u, l = A.data, A.u, A.l
627-
jj = 1
628-
for j in jr
629-
kk = 1
630-
for k in kr
631-
if -l j - k u
632-
# we index V manually in column-major order
633-
inbands_setindex!(data, u, V[kk, jj], k, j)
634-
kk += 1
635-
end
636-
end
637-
jj += 1
638-
end
625+
copyto!(view(A, kr, jr), V)
639626
V
640627
end
641628

test/test_banded.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,5 +469,15 @@ Base.similar(::MyMatrix, ::Type{T}, m::Int, n::Int) where T = MyMatrix{T}(undef,
469469
A = _BandedMatrix(Fill(1,1,5), Base.Slice(1:4), 1, -1)
470470
@test summary(A) == "4×5 BandedMatrix{$Int} with bandwidths (1, -1) with data 1×5 Fill{$Int} with indices 1:4×Base.OneTo(5)"
471471
end
472+
473+
@testset "setindex! with ranges (#348)" begin
474+
n = 10;
475+
X1 = brand(n,n,1,1)
476+
B = BandedMatrix(Zeros(2n,2n), (3,3))
477+
B[1:2:end,1:2:end] = X1
478+
A = zeros(2n,2n)
479+
A[1:2:end,1:2:end] = X1
480+
@test A == B
481+
end
472482
end
473483

0 commit comments

Comments
 (0)