Skip to content

Commit

Permalink
Merge pull request #100 from invenia/mz/getindex
Browse files Browse the repository at this point in the history
fix the getindex bug for abstract arrays
  • Loading branch information
mzgubic authored May 18, 2022
2 parents fc727ab + d77c395 commit b2ee90a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "BlockDiagonals"
uuid = "0a1fb500-61f7-11e9-3c65-f5ef3456f9f0"
authors = ["Invenia Technical Computing Corporation"]
version = "0.1.29"
version = "0.1.30"

[deps]
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
Expand Down
3 changes: 2 additions & 1 deletion src/blockdiagonal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ function _block_indices(B::BlockDiagonal, i::Integer, j::Integer)
p += 1
j -= blocksize(B, p)[2]
end
@views @inbounds i -= sum(size.(blocks(B)[1:(p-1)], 1))
# isempty to avoid reducing over an empty collection
@views @inbounds i -= isempty(1:(p-1)) ? 0 : sum(size.(blocks(B)[1:(p-1)], 1))
# if row `i` outside of block `p`, set `p` to place-holder value `-1`
if i <= 0 || i > blocksize(B, p)[1]
p = -1
Expand Down
5 changes: 5 additions & 0 deletions test/blockdiagonal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,9 @@ using Test

@test_throws DimensionMismatch copy!(b2, b1)
end

@testset "getindex bug" begin
b = BlockDiagonal(AbstractMatrix{Float64}[ones(2, 2)])
@test b[1] == 1
end
end

2 comments on commit b2ee90a

@mzgubic
Copy link
Collaborator 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/60469

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.1.30 -m "<description of version>" b2ee90a2df314be5743ac16987548ceddf84229d
git push origin v0.1.30

Please sign in to comment.