Skip to content
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 = "1.9.2"
version = "1.9.3"


[deps]
Expand Down
2 changes: 2 additions & 0 deletions src/blockarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
2 changes: 2 additions & 0 deletions src/blockedarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
8 changes: 8 additions & 0 deletions test/test_blockarrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading