Skip to content

Commit

Permalink
Fix setindex! with ranges (#138) (#349)
Browse files Browse the repository at this point in the history
* Fix setindex! with ranges (#138)

* Update BandedMatrix.jl
  • Loading branch information
dlfivefifty authored Apr 27, 2023
1 parent 7988daf commit 45a5873
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
15 changes: 1 addition & 14 deletions src/banded/BandedMatrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 10 additions & 0 deletions test/test_banded.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

2 comments on commit 45a5873

@dlfivefifty
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/82418

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.17.21 -m "<description of version>" 45a587399b25f153dfea07093a75abc2dd1f57b5
git push origin v0.17.21

Please sign in to comment.