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.6.0"
version = "1.6.1"

[deps]
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
Expand Down
4 changes: 4 additions & 0 deletions src/blockarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,10 @@ end

@inline Base.similar(B::BlockArray, ::Type{T}) where {T} = _BlockArray(similar.(blocks(B), T), axes(B))

# specific 0-dim
@inline Base.similar(B::BlockArray{<:Any,0}, ::Type{T}) where {T} = BlockArray(similar(only(blocks(B)), T), ())
@inline Base.similar(::BlockArray, ::Type{T}, ::Tuple{}) where {T} = BlockArray{T}(undef)

const OffsetAxis = Union{Integer, UnitRange, Base.OneTo, Base.IdentityUnitRange}

# avoid ambiguities
Expand Down
3 changes: 3 additions & 0 deletions src/blockedarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ function Base.similar(block_array::BlockedArray{T,N}, ::Type{T2}) where {T,N,T2}
BlockedArray(similar(block_array.blocks, T2), axes(block_array))
end

# specific zero dim
Base.similar(::BlockedArray, ::Type{T}, ::Tuple{}) where {T} = BlockedArray{T}(undef)

to_axes(r::AbstractUnitRange) = r
to_axes(n::Integer) = Base.oneto(n)

Expand Down
19 changes: 16 additions & 3 deletions test/test_blockarrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ end

@testset "zero dim" begin
zerodim = ones()
r = blockedrange([1])
@test view(zerodim) isa AbstractArray{Float64, 0} # check no type-piracy

ret = BlockArray{Float64}(undef)
Expand All @@ -343,13 +344,19 @@ end
view(ret)[] = 0
@test ret[] == 0

ret = BlockArrays.BlockArray(zeros())
ret = BlockArray(zeros())
@test ret isa BlockArray{Float64, 0}
@test size(ret) == ()
@test all(iszero, ret)
@test ret[Block()] == zeros()

ret = BlockArrays.BlockArray(zeros(1,1))
@test similar(ret) isa BlockArray{Float64, 0}
@test similar(ret, Float32) isa BlockArray{Float32, 0}
@test similar(ret, Float32, ()) isa BlockArray{Float32, 0}
@test similar(ret, Float32, (r,)) isa BlockVector{Float32}
@test similar(BlockArray(zeros(r)), Float32, ()) isa BlockArray{Float32, 0}

ret = BlockArray(zeros(1,1))
@test reshape(ret, ()) isa AbstractBlockArray{Float64, 0} # may be BlockedArray
@test size(reshape(ret, ())) == ()

Expand All @@ -373,7 +380,13 @@ end
@test all(iszero, ret)
@test ret[Block()] == zeros()

ret = BlockArrays.BlockedArray(zeros(1,1))
@test similar(ret) isa BlockedArray{Float64, 0}
@test similar(ret, Float32) isa BlockedArray{Float32, 0}
@test similar(ret, Float32, ()) isa BlockedArray{Float32, 0}
@test similar(ret, Float32, (blockedrange([1]),)) isa BlockedVector{Float32}
@test similar(zeros(r), Float32, ()) isa BlockedArray{Float32, 0}

ret = BlockedArray(zeros(1,1))
@test reshape(ret, ()) isa BlockedArray{Float64, 0}
@test size(reshape(ret, ())) == ()
end
Expand Down
Loading