Skip to content

Fix stack overflow in indexing unit range with BlockRange #110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "BlockArrays"
uuid = "8e7c35d0-a365-5155-bbbb-fb81a777f24e"
version = "0.12.3"
version = "0.12.4"

[deps]
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
Expand Down
5 changes: 5 additions & 0 deletions src/blockaxis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@ function getindex(b::AbstractUnitRange{Int}, K::Block{1})
b
end

function getindex(b::AbstractUnitRange{Int}, K::BlockRange)
@boundscheck K == Block.(1:1) || throw(BlockBoundsError(b, K))
b
end

blockaxes(b::AbstractUnitRange{Int}) = (Block.(Base.OneTo(1)),)

function findblock(b::AbstractUnitRange{Int}, k::Integer)
Expand Down
4 changes: 4 additions & 0 deletions src/pseudo_blockarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,10 @@ function copyto!(block_array::PseudoBlockArray{T, N, R}, arr::R) where {T,N,R <:
copyto!(block_array.blocks, arr)
end

function copyto!(block_array::PseudoBlockArray{T, N, R}, arr::R) where {T,N,R <: LayoutArray}
copyto!(block_array.blocks, arr)
end

function Base.copy(block_array::PseudoBlockArray{T, N, R}) where {T,N,R <: AbstractArray}
copy(block_array.blocks)
end
Expand Down
9 changes: 9 additions & 0 deletions test/test_blockarrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,15 @@ end
B[1] = 2
@test B[1] == 2
@test A[1] ≠ 2
@testset "copyto!" begin
A = PseudoBlockArray(randn(6), 1:3)
B = BlockArray(randn(6), 1:3)
@test copyto!(BlockArray{Float64}(undef, 1:3), A) == A
@test copyto!(PseudoBlockArray{Float64}(undef, 1:3), A) == A

@test copyto!(BlockArray{Float64}(undef, 1:3), B) == B
@test copyto!(PseudoBlockArray{Float64}(undef, 1:3), B) == B
end
end

@testset "const block size" begin
Expand Down
2 changes: 2 additions & 0 deletions test/test_blockindices.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ import BlockArrays: BlockIndex, BlockIndexRange, BlockSlice
b = Block.(2:5)
@test Int.(b) === 2:5
@test Base.OneTo.(1:5) isa Vector{Base.OneTo{Int}} #98
@test Base.OneTo(5)[Block.(1:1)] === Base.OneTo(5)
@test_throws BlockBoundsError Base.OneTo(5)[Block.(1:3)]
end
end

Expand Down