Skip to content

Commit b095f3f

Browse files
authored
Fix stack overflow in indexing unit range with BlockRange (#110)
* Fix stack overflow in indexing unit range with BlockRange * Update pseudo_blockarray.jl * add test * Update blockaxis.jl
1 parent 651ca96 commit b095f3f

File tree

5 files changed

+21
-1
lines changed

5 files changed

+21
-1
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "BlockArrays"
22
uuid = "8e7c35d0-a365-5155-bbbb-fb81a777f24e"
3-
version = "0.12.3"
3+
version = "0.12.4"
44

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

src/blockaxis.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,11 @@ function getindex(b::AbstractUnitRange{Int}, K::Block{1})
192192
b
193193
end
194194

195+
function getindex(b::AbstractUnitRange{Int}, K::BlockRange)
196+
@boundscheck K == Block.(1:1) || throw(BlockBoundsError(b, K))
197+
b
198+
end
199+
195200
blockaxes(b::AbstractUnitRange{Int}) = (Block.(Base.OneTo(1)),)
196201

197202
function findblock(b::AbstractUnitRange{Int}, k::Integer)

src/pseudo_blockarray.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,10 @@ function copyto!(block_array::PseudoBlockArray{T, N, R}, arr::R) where {T,N,R <:
254254
copyto!(block_array.blocks, arr)
255255
end
256256

257+
function copyto!(block_array::PseudoBlockArray{T, N, R}, arr::R) where {T,N,R <: LayoutArray}
258+
copyto!(block_array.blocks, arr)
259+
end
260+
257261
function Base.copy(block_array::PseudoBlockArray{T, N, R}) where {T,N,R <: AbstractArray}
258262
copy(block_array.blocks)
259263
end

test/test_blockarrays.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,15 @@ end
421421
B[1] = 2
422422
@test B[1] == 2
423423
@test A[1]  2
424+
@testset "copyto!" begin
425+
A = PseudoBlockArray(randn(6), 1:3)
426+
B = BlockArray(randn(6), 1:3)
427+
@test copyto!(BlockArray{Float64}(undef, 1:3), A) == A
428+
@test copyto!(PseudoBlockArray{Float64}(undef, 1:3), A) == A
429+
430+
@test copyto!(BlockArray{Float64}(undef, 1:3), B) == B
431+
@test copyto!(PseudoBlockArray{Float64}(undef, 1:3), B) == B
432+
end
424433
end
425434

426435
@testset "const block size" begin

test/test_blockindices.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ import BlockArrays: BlockIndex, BlockIndexRange, BlockSlice
7474
b = Block.(2:5)
7575
@test Int.(b) === 2:5
7676
@test Base.OneTo.(1:5) isa Vector{Base.OneTo{Int}} #98
77+
@test Base.OneTo(5)[Block.(1:1)] === Base.OneTo(5)
78+
@test_throws BlockBoundsError Base.OneTo(5)[Block.(1:3)]
7779
end
7880
end
7981

0 commit comments

Comments
 (0)