diff --git a/Project.toml b/Project.toml index 4f93b27e..67f1981c 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "BlockArrays" uuid = "8e7c35d0-a365-5155-bbbb-fb81a777f24e" -version = "1.9.2" +version = "1.9.3" [deps] diff --git a/src/blockarray.jl b/src/blockarray.jl index b6630019..660a1c5c 100644 --- a/src/blockarray.jl +++ b/src/blockarray.jl @@ -448,6 +448,8 @@ end @inline Base.similar(block_array::AbstractArray, ::Type{T}, axes::Tuple{Union{AbstractUnitRange{<:Integer},Integer},Union{AbstractUnitRange{<:Integer},Integer},AbstractBlockedUnitRange,Vararg{Union{AbstractUnitRange{<:Integer},Integer}}}) where T = BlockArray{T}(undef, map(to_axes,axes)) +@inline Base.similar(block_array::Type{<:AbstractArray{T}}, axes::Tuple{AbstractBlockedUnitRange,Vararg{AbstractBlockedUnitRange}}) where T = + BlockArray{T}(undef, axes) @inline Base.similar(block_array::Type{<:AbstractArray{T}}, axes::Tuple{AbstractBlockedUnitRange,Vararg{Union{AbstractUnitRange{<:Integer},Integer}}}) where T = BlockArray{T}(undef, map(to_axes,axes)) @inline Base.similar(block_array::Type{<:AbstractArray{T}}, axes::Tuple{AbstractBlockedUnitRange,AbstractBlockedUnitRange,Vararg{Union{AbstractUnitRange{<:Integer},Integer}}}) where T = diff --git a/src/blockedarray.jl b/src/blockedarray.jl index ec7c2b26..416eb866 100644 --- a/src/blockedarray.jl +++ b/src/blockedarray.jl @@ -215,6 +215,8 @@ to_axes(n::Integer) = Base.oneto(n) const IntegerOrUnitRange = Union{Integer,AbstractUnitRange{<:Integer}} +@inline Base.similar(block_array::Type{<:StridedArray{T}}, axes::Tuple{AbstractBlockedUnitRange,Vararg{AbstractBlockedUnitRange}}) where T = + BlockedArray{T}(undef, axes) @inline Base.similar(block_array::Type{<:StridedArray{T}}, axes::Tuple{AbstractBlockedUnitRange,Vararg{IntegerOrUnitRange}}) where T = BlockedArray{T}(undef, map(to_axes,axes)) @inline Base.similar(block_array::Type{<:StridedArray{T}}, axes::Tuple{AbstractBlockedUnitRange,AbstractBlockedUnitRange,Vararg{IntegerOrUnitRange}}) where T = diff --git a/test/test_blockarrays.jl b/test/test_blockarrays.jl index f5de71f0..537792e6 100644 --- a/test/test_blockarrays.jl +++ b/test/test_blockarrays.jl @@ -260,6 +260,14 @@ end @test similar(typeof(view(randn(5),1:3)), (blockedrange(1:3),)) isa BlockedVector @test similar(view(randn(5),1:3), Int, (blockedrange(1:3),)) isa BlockedVector{Int} + # Regression test for method ambiguity. + A = Array{Float64} + @test similar(A, blockedrange.((1:3,1:3,1:3))) isa BlockedArray{Float64,3} + @test similar(A, blockedrange.((1:3,1:3,1:3,1:3))) isa BlockedArray{Float64,4} + A = typeof(view(randn(4,4,4),[1,2,4],[1,2,4],[1,2,4])) + @test similar(A, blockedrange.((1:3,1:3,1:3))) isa BlockArray{Float64,3} + @test similar(A, blockedrange.((1:3,1:3,1:3,1:3))) isa BlockArray{Float64,4} + b = BlockVector([1,2,3,4,5,6,7,8,9,10], (BlockedOneTo(5:5:10),)) @test zero(b) isa typeof(b) end